public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/103310] New: null comparison with a weak symbol eliminated
@ 2021-11-17 22:01 msebor at gcc dot gnu.org
  2021-11-18  0:40 ` [Bug c/103310] " msebor at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-17 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103310
           Summary: null comparison with a weak symbol eliminated
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following test case was prompted by the discussion in the review of a
-Waddress enhancement:
  https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584749.html

Before folding the test in call_alias() to true, GCC issues a -Waddress.  At
runtime the program then crashes.  In the review Jason suggests GCC should
reject the subsequent declaration of the alias with an error because it has
been used (and because the test for null may have been eliminated).

cat a.c && gcc -DUSE_ALIAS -O2 -Wall -c a.c && gcc -O2 -Wall a.c a.o && ./a.out
#if USE_ALIAS

extern void alias (void);

void call_alias (void)
{
  __builtin_printf ("in %s: alias = %p\n", __func__, alias);

  if (alias)
    alias ();
}

extern void alias (void)  __attribute__((weak));

#else

extern void alias (void)  __attribute__((weak));   // not defined

extern void call_alias (void);

int main (void)
{
  __builtin_printf ("in %s: alias = %p\n", __func__, alias);

  call_alias ();
}

#endif
a.c: In function ‘call_alias’:
a.c:9:7: warning: the address of ‘alias’ will always evaluate as ‘true’
[-Waddress]
    9 |   if (alias)
      |       ^~~~~
in main: alias = (nil)
in call_alias: alias = (nil)
Segmentation fault (core dumped)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-01 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 22:01 [Bug middle-end/103310] New: null comparison with a weak symbol eliminated msebor at gcc dot gnu.org
2021-11-18  0:40 ` [Bug c/103310] " msebor at gcc dot gnu.org
2021-11-18 15:58 ` jason at gcc dot gnu.org
2021-12-01 18:24 ` cvs-commit at gcc dot gnu.org

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).