From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 25E2F384B402; Thu, 19 May 2022 11:13:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25E2F384B402 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/105654] transparent_union, function pointer and different types arguments causes null pointer to be passed Date: Thu, 19 May 2022 11:13:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 11:13:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105654 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hubicka at gcc dot gnu.org, | |jsm28 at gcc dot gnu.org --- Comment #1 from Richard Biener --- -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 @@ [local count: 912787929]: _2 =3D MEM[(char * *)argv_10(D) + 8B]; - D.2620.x =3D &val; _cb_parse (D.2620, _2); val.1_3 =3D val; _4 =3D (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 =3D _cb_parse; and static _Bool _cb_parse( _Bool * out, char* in) { *out =3D !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?=