From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2E3CE3851C18; Wed, 14 Apr 2021 20:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E3CE3851C18 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect Date: Wed, 14 Apr 2021 20:28:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Wed, 14 Apr 2021 20:28:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100086 Bug ID: 100086 Summary: spurious -Wnonnull with __builtin_expect Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The following has been reduced from Red Hat bug https://bugzilla.redhat.com/show_bug.cgi?id=3D1948775. In the original cod= e the warning points to the this pointer in a call to a member function (which fi= rst became subject to the warning in GCC 11) but the same issue can be reproduc= ed with any other nonnull function such as the call to __builtin_puts(0B) in t= he IL. Replacing the __builtin_expect call with a plain test avoids the warni= ng, as does removing the indirection via AssertionResult. $ cat rhbz1948775.C && gcc -O2 -S -Wall -fdump-tree-post_ipa_warn=3D/dev/st= dout rhbz1948775.C struct string { char *p; }; string GetMessage(); struct AssertionResult { AssertionResult (bool b) : b_(b) { } operator bool() const { return b_; } bool b_; }; struct AssertHelper { AssertHelper (const char*); void operator=3D(int); }; struct RefPtr { ~RefPtr() { if (__builtin_expect ((p !=3D 0), 1)) __builtin_puts (p); } operator bool() const { return !!p; } char *p; }; RefPtr take (); void TestBody () { RefPtr emptyTake =3D take (); if (!AssertionResult (!emptyTake)) return AssertHelper(GetMessage().p) =3D 1; } ;; Function TestBody (_Z8TestBodyv, funcdef_no=3D8, decl_uid=3D2417, cgraph= _uid=3D9, symbol_order=3D8) In destructor =E2=80=98RefPtr::~RefPtr()=E2=80=99, inlined from =E2=80=98void TestBody()=E2=80=99 at rhbz1948775.C:43:1: rhbz1948775.C:26:22: warning: argument 1 null where non-null expected [-Wnonnull] 26 | __builtin_puts (p); | ~~~~~~~~~~~~~~~^~~ rhbz1948775.C: In function =E2=80=98void TestBody()=E2=80=99: rhbz1948775.C:26:22: note: in a call to built-in function =E2=80=98int __builtin_puts(const char*)=E2=80=99 void TestBody () { struct RefPtr emptyTake; struct string D.2464; struct AssertHelper D.2492; bool _1; char * _2; char * _14; bool _15; char * _16; bool _17; long int _18; long int _19; long int _20; long int _21; char * _22; bool _23; long int _24; long int _25; [local count: 1073741824]: emptyTake =3D take (); [return slot optimization] _14 =3D emptyTake.p; _15 =3D _14 !=3D 0B; _1 =3D _14 =3D=3D 0B; if (_1 !=3D 0) goto ; [79.76%] else goto ; [20.24%] [local count: 217325344]: D.2464 =3D GetMessage (); [local count: 217325344]: _2 =3D D.2464.p; AssertHelper::AssertHelper (&D.2492, _2); [local count: 217325344]: AssertHelper::operator=3D (&D.2492, 1); [local count: 217325344]: D.2492 =3D{v} {CLOBBER}; _16 =3D emptyTake.p; _17 =3D _16 !=3D 0B; _18 =3D (long int) _17; _19 =3D _18; if (_19 !=3D 0) goto ; [90.00%] else goto ; [10.00%] [local count: 195592809]: __builtin_puts (_16); [local count: 217325344]: emptyTake =3D{v} {CLOBBER}; emptyTake =3D{v} {CLOBBER}; goto ; [100.00%] [local count: 856416481]: _20 =3D (long int) _15; _21 =3D _20; if (_21 !=3D 0) goto ; [90.00%] else goto ; [10.00%] [local count: 770774832]: __builtin_puts (0B); <<< -Wnonnull [local count: 856416481]: emptyTake =3D{v} {CLOBBER}; emptyTake =3D{v} {CLOBBER}; [local count: 1073741824]: return; [count: 0]: : D.2492 =3D{v} {CLOBBER}; _22 =3D emptyTake.p; _23 =3D _22 !=3D 0B; _24 =3D (long int) _23; _25 =3D _24; if (_25 !=3D 0) goto ; [0.00%] else goto ; [0.00%] [count: 0]: __builtin_puts (_22); [count: 0]: emptyTake =3D{v} {CLOBBER}; resx 2 }=