public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103310] New: null comparison with a weak symbol eliminated Date: Wed, 17 Nov 2021 22:01:33 +0000 [thread overview] Message-ID: <bug-103310-4@http.gcc.gnu.org/bugzilla/> (raw) 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)
next reply other threads:[~2021-11-17 22:01 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-17 22:01 msebor at gcc dot gnu.org [this message] 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
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-103310-4@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: linkBe 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).