public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-105654-4-av2DiMxFSM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105654-4@http.gcc.gnu.org/bugzilla/>

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?

  reply	other threads:[~2022-05-19 11:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19  6:41 [Bug c/105654] New: Address of local variable as function call argument is NULL?! gnu.org at quisquis dot de
2022-05-19 11:13 ` rguenth at gcc dot gnu.org [this message]
2022-05-19 11:34 ` [Bug middle-end/105654] transparent_union, function pointer and different types arguments causes null pointer to be passed schwab@linux-m68k.org
2022-05-19 12:25 ` schwab@linux-m68k.org
2022-05-20 12:59 ` tobias at strongswan dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105654-4-av2DiMxFSM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).