[Bug middle-end/105654] transparent_union, function pointer and different types arguments causes null pointer to be passed

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 19 11:13:22 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105654

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
-fno-ipa-modref fixes this, the issue is we remove the initialization of the
out argument:

--- t.i.113t.mergephi2  2022-05-19 13:06:52.209819846 +0200
+++ t.i.116t.dse2       2022-05-19 13:06:52.209819846 +0200
@@ -45,7 +45,6 @@

   <bb 4> [local count: 912787929]:
   _2 = MEM[(char * *)argv_10(D) + 8B];
-  D.2620.x = &val;
   _cb_parse (D.2620, _2);
   val.1_3 = val;
   _4 = (int) val.1_3;

note there's a mismatch between the prototype and the actual _cb_parse
declaration:

static _Bool _cb_parse(union { void* x; _Bool * out; }
__attribute((transparent_union)), char* in);
static typeof(_cb_parse)* parse = _cb_parse;

and

static _Bool _cb_parse( _Bool * out, char* in) {
    *out = !strcmp("yes", in);
    return;
}

with the call being indirect:

    parse(&val, argv[1]);

The docs say

'Second, the argument is passed to the function using the calling
conventions of the first member of the transparent union, not the calling
conventions of the union itself.  All members of the union must have the
same machine representation; this is necessary for this argument passing
to work properly.'

so possibly the alias set of the union needs to be that of the first member
but then the _cb_parse implementation uses _Bool * to access the argument
which then breaks.

But I suppose the issue with modref is more subtle due to the pointer
SSA name in the implementation and the aggregate argument in the caller.

Honza?

Joseph - is the above well-defined use of the extension?


More information about the Gcc-bugs mailing list