From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E3E9D3858C2C; Thu, 18 Nov 2021 00:40:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3E9D3858C2C From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/103310] null comparison with a weak symbol eliminated Date: Thu, 18 Nov 2021 00:40:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: component 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, 18 Nov 2021 00:40:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103310 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Component|middle-end |c --- Comment #1 from Martin Sebor --- The test case below shows that storing the address of the alias in a local pointer avoids the problem. The dumps show that the problem is in the front end which folds the test of the address of the weak symbol to true. $ cat pr103310.c && gcc -Wall -O2 -S -fdump-tree-original=3D/dev/stdout -fdump-tree-optimized=3D/dev/stdout pr103310.c extern void alias (void); void call_alias (void) { __builtin_printf ("in %s: alias =3D %p\n", __func__, alias); if (alias) alias (); } void call_ptr_alias (void) { void (*p)(void) =3D alias; __builtin_printf ("in %s: alias =3D %p\n", __func__, p); if (p) p (); } extern void alias (void) __attribute__((weak)); pr103310.c: In function =E2=80=98call_alias=E2=80=99: pr103310.c:7:7: warning: the address of =E2=80=98alias=E2=80=99 will always= evaluate as =E2=80=98true=E2=80=99 [-Waddress] 7 | if (alias) | ^~~~~ ;; Function call_alias (null) ;; enabled by -tree-original { static const char __func__[11] =3D "call_alias"; static const char __func__[11] =3D "call_alias"; __builtin_printf ((const char *) "in %s: alias =3D %p\n", (const char *) &__func__, alias); if (1) { alias (); } } ;; Function call_ptr_alias (null) ;; enabled by -tree-original { void (*) (void) p =3D alias; static const char __func__[15] =3D "call_ptr_alias"; static const char __func__[15] =3D "call_ptr_alias"; void (*) (void) p =3D alias; __builtin_printf ((const char *) "in %s: alias =3D %p\n", (const char *) &__func__, p); if (p !=3D 0B) { p (); } } ;; Function call_alias (call_alias, funcdef_no=3D0, decl_uid=3D1945, cgraph= _uid=3D1, symbol_order=3D0) void call_alias () { static const char __func__[11] =3D "call_alias"; [local count: 1073741824]: __builtin_printf ("in %s: alias =3D %p\n", &__func__, alias); alias (); [tail call] return; } ;; Function call_ptr_alias (call_ptr_alias, funcdef_no=3D1, decl_uid=3D1949, cgraph_uid=3D2, symbol_order=3D1) Removing basic block 5 void call_ptr_alias () { static const char __func__[15] =3D "call_ptr_alias"; [local count: 1073741824]: __builtin_printf ("in %s: alias =3D %p\n", &__func__, alias); if (alias !=3D 0B) goto ; [53.47%] else goto ; [46.53%] [local count: 574129753]: alias (); [tail call] [local count: 1073741824]: return; }=