public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect
@ 2021-04-14 20:28 msebor at gcc dot gnu.org
2021-04-14 20:32 ` [Bug tree-optimization/100086] [11 Regression] " msebor at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-14 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
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=1948775. In the original code the
warning points to the this pointer in a call to a member function (which first
became subject to the warning in GCC 11) but the same issue can be reproduced
with any other nonnull function such as the call to __builtin_puts(0B) in the
IL. Replacing the __builtin_expect call with a plain test avoids the warning,
as does removing the indirection via AssertionResult.
$ cat rhbz1948775.C && gcc -O2 -S -Wall -fdump-tree-post_ipa_warn=/dev/stdout
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=(int);
};
struct RefPtr
{
~RefPtr()
{
if (__builtin_expect ((p != 0), 1))
__builtin_puts (p);
}
operator bool() const {
return !!p;
}
char *p;
};
RefPtr take ();
void TestBody ()
{
RefPtr emptyTake = take ();
if (!AssertionResult (!emptyTake))
return AssertHelper(GetMessage().p) = 1;
}
;; Function TestBody (_Z8TestBodyv, funcdef_no=8, decl_uid=2417, cgraph_uid=9,
symbol_order=8)
In destructor ‘RefPtr::~RefPtr()’,
inlined from ‘void TestBody()’ 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 ‘void TestBody()’:
rhbz1948775.C:26:22: note: in a call to built-in function ‘int
__builtin_puts(const char*)’
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;
<bb 2> [local count: 1073741824]:
emptyTake = take (); [return slot optimization]
_14 = emptyTake.p;
_15 = _14 != 0B;
_1 = _14 == 0B;
if (_1 != 0)
goto <bb 9>; [79.76%]
else
goto <bb 3>; [20.24%]
<bb 3> [local count: 217325344]:
D.2464 = GetMessage ();
<bb 4> [local count: 217325344]:
_2 = D.2464.p;
AssertHelper::AssertHelper (&D.2492, _2);
<bb 5> [local count: 217325344]:
AssertHelper::operator= (&D.2492, 1);
<bb 6> [local count: 217325344]:
D.2492 ={v} {CLOBBER};
_16 = emptyTake.p;
_17 = _16 != 0B;
_18 = (long int) _17;
_19 = _18;
if (_19 != 0)
goto <bb 7>; [90.00%]
else
goto <bb 8>; [10.00%]
<bb 7> [local count: 195592809]:
__builtin_puts (_16);
<bb 8> [local count: 217325344]:
emptyTake ={v} {CLOBBER};
emptyTake ={v} {CLOBBER};
goto <bb 12>; [100.00%]
<bb 9> [local count: 856416481]:
_20 = (long int) _15;
_21 = _20;
if (_21 != 0)
goto <bb 10>; [90.00%]
else
goto <bb 11>; [10.00%]
<bb 10> [local count: 770774832]:
__builtin_puts (0B); <<< -Wnonnull
<bb 11> [local count: 856416481]:
emptyTake ={v} {CLOBBER};
emptyTake ={v} {CLOBBER};
<bb 12> [local count: 1073741824]:
return;
<bb 13> [count: 0]:
<L8>:
D.2492 ={v} {CLOBBER};
_22 = emptyTake.p;
_23 = _22 != 0B;
_24 = (long int) _23;
_25 = _24;
if (_25 != 0)
goto <bb 14>; [0.00%]
else
goto <bb 15>; [0.00%]
<bb 14> [count: 0]:
__builtin_puts (_22);
<bb 15> [count: 0]:
emptyTake ={v} {CLOBBER};
resx 2
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
@ 2021-04-14 20:32 ` msebor at gcc dot gnu.org
2021-04-15 7:00 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-14 20:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-04-14
URL| |https://bugzilla.redhat.com
| |/show_bug.cgi?id=1948775
Blocks| |95507
Known to fail| |11.0
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Summary|spurious -Wnonnull with |[11 Regression] spurious
|__builtin_expect |-Wnonnull with
| |__builtin_expect
Ever confirmed|0 |1
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
According to my bisection the warning first appeared in GCC 11, with
g:fcae5121154d1c3382b056bcc2c563cedac28e74. Before then the post_ipa_warn dump
looked like so:
;; Function TestBody (_Z8TestBodyv, funcdef_no=8, decl_uid=2406, cgraph_uid=9,
symbol_order=8)
TestBody ()
{
struct RefPtr emptyTake;
struct string D.2453;
struct AssertHelper D.2481;
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;
<bb 2> [local count: 1073741824]:
emptyTake = take (); [return slot optimization]
_14 = emptyTake.p;
_15 = _14 != 0B;
_1 = _14 == 0B;
if (_1 != 0)
goto <bb 9>; [79.76%]
else
goto <bb 3>; [20.24%]
<bb 3> [local count: 217325344]:
D.2453 = GetMessage ();
<bb 4> [local count: 217325344]:
_2 = D.2453.p;
AssertHelper::AssertHelper (&D.2481, _2);
<bb 5> [local count: 217325344]:
AssertHelper::operator= (&D.2481, 1);
<bb 6> [local count: 217325344]:
D.2481 ={v} {CLOBBER};
_16 = emptyTake.p;
_17 = _16 != 0B;
_18 = (long int) _17;
_19 = _18;
if (_19 != 0)
goto <bb 7>; [90.00%]
else
goto <bb 8>; [10.00%]
<bb 7> [local count: 195592809]:
__builtin_puts (_16);
<bb 8> [local count: 217325344]:
emptyTake ={v} {CLOBBER};
emptyTake ={v} {CLOBBER};
goto <bb 12>; [100.00%]
<bb 9> [local count: 856416481]:
_20 = (long int) _15;
_21 = _20;
if (_21 != 0)
goto <bb 10>; [90.00%]
else
goto <bb 11>; [10.00%]
<bb 10> [local count: 770774832]:
__builtin_puts (_14);
<bb 11> [local count: 856416481]:
emptyTake ={v} {CLOBBER};
emptyTake ={v} {CLOBBER};
<bb 12> [local count: 1073741824]:
return;
<bb 13> [count: 0]:
<L8>:
D.2481 ={v} {CLOBBER};
_22 = emptyTake.p;
_23 = _22 != 0B;
_24 = (long int) _23;
_25 = _24;
if (_25 != 0)
goto <bb 14>; [0.00%]
else
goto <bb 15>; [0.00%]
<bb 14> [count: 0]:
__builtin_puts (_22);
<bb 15> [count: 0]:
emptyTake ={v} {CLOBBER};
resx 2
}
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95507
[Bug 95507] [meta-bug] bogus/missing -Wnonnull
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
2021-04-14 20:32 ` [Bug tree-optimization/100086] [11 Regression] " msebor at gcc dot gnu.org
@ 2021-04-15 7:00 ` rguenth at gcc dot gnu.org
2021-04-27 11:40 ` [Bug tree-optimization/100086] [11/12 " jakub at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-15 7:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11/12 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
2021-04-14 20:32 ` [Bug tree-optimization/100086] [11 Regression] " msebor at gcc dot gnu.org
2021-04-15 7:00 ` rguenth at gcc dot gnu.org
@ 2021-04-27 11:40 ` jakub at gcc dot gnu.org
2021-07-28 7:06 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-27 11:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.0 |11.2
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.1 has been released, retargeting bugs to GCC 11.2.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11/12 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2021-04-27 11:40 ` [Bug tree-optimization/100086] [11/12 " jakub at gcc dot gnu.org
@ 2021-07-28 7:06 ` rguenth at gcc dot gnu.org
2022-01-21 12:37 ` [Bug tree-optimization/100086] [11 " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28 7:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.2 |11.3
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.2 is being released, retargeting bugs to GCC 11.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
` (3 preceding siblings ...)
2021-07-28 7:06 ` rguenth at gcc dot gnu.org
@ 2022-01-21 12:37 ` rguenth at gcc dot gnu.org
2022-01-31 14:52 ` marxin at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21 12:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12 Regression] spurious |[11 Regression] spurious
|-Wnonnull with |-Wnonnull with
|__builtin_expect |__builtin_expect
Known to fail| |11.2.1
Priority|P3 |P2
Keywords| |needs-bisection
Known to work| |12.0
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The testcase no longer reproduces the issue with GCC 12 for me, GCC 11 still
does. I wonder what fixed it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
` (4 preceding siblings ...)
2022-01-21 12:37 ` [Bug tree-optimization/100086] [11 " rguenth at gcc dot gnu.org
@ 2022-01-31 14:52 ` marxin at gcc dot gnu.org
2022-04-21 7:49 ` rguenth at gcc dot gnu.org
2023-05-29 10:04 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-01-31 14:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-bisection |
CC| |marxin at gcc dot gnu.org
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> The testcase no longer reproduces the issue with GCC 12 for me, GCC 11 still
> does. I wonder what fixed it.
Fixed with r12-1546-g786188e8b8cab47c.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
` (5 preceding siblings ...)
2022-01-31 14:52 ` marxin at gcc dot gnu.org
@ 2022-04-21 7:49 ` rguenth at gcc dot gnu.org
2023-05-29 10:04 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21 7:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.3 |11.4
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/100086] [11 Regression] spurious -Wnonnull with __builtin_expect
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
` (6 preceding siblings ...)
2022-04-21 7:49 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:04 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100086
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.4 |11.5
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-05-29 10:04 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 20:28 [Bug tree-optimization/100086] New: spurious -Wnonnull with __builtin_expect msebor at gcc dot gnu.org
2021-04-14 20:32 ` [Bug tree-optimization/100086] [11 Regression] " msebor at gcc dot gnu.org
2021-04-15 7:00 ` rguenth at gcc dot gnu.org
2021-04-27 11:40 ` [Bug tree-optimization/100086] [11/12 " jakub at gcc dot gnu.org
2021-07-28 7:06 ` rguenth at gcc dot gnu.org
2022-01-21 12:37 ` [Bug tree-optimization/100086] [11 " rguenth at gcc dot gnu.org
2022-01-31 14:52 ` marxin at gcc dot gnu.org
2022-04-21 7:49 ` rguenth at gcc dot gnu.org
2023-05-29 10:04 ` jakub 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).