public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional
@ 2022-01-17 22:10 msebor at gcc dot gnu.org
2022-01-17 22:11 ` [Bug middle-end/104076] " msebor at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-17 22:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
Bug ID: 104076
Summary: bogus -Wdangling-pointer on a conditional
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: ---
As reported in
https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588620.html, the new
-Wdangling-pointer issues a false positive for the following test case:
$ cat t.C && g++ -S -Wall t.C
#include <initializer_list>
struct S1
{
S1 (int);
~S1 ();
};
struct S2 { S2 (std::initializer_list<S1>); };
S2 f1();
S2 f2(bool b)
{
return b ? f1() : S2{0};
}
t.C: In function ‘S2 f2(bool)’:
t.C:16:1: warning: dangling pointer to an unnamed temporary may be used
[-Wdangling-pointer=]
16 | }
| ^
t.C:15:25: note: unnamed temporary defined here
15 | return b ? f1() : S2{0};
| ^
t.C:16:1: warning: dangling pointer to an unnamed temporary may be used
[-Wdangling-pointer=]
16 | }
| ^
t.C:15:25: note: unnamed temporary defined here
15 | return b ? f1() : S2{0};
| ^
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
@ 2022-01-17 22:11 ` msebor at gcc dot gnu.org
2022-01-18 23:15 ` msebor at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-17 22:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2022-01-17
Keywords| |diagnostic
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
2022-01-17 22:11 ` [Bug middle-end/104076] " msebor at gcc dot gnu.org
@ 2022-01-18 23:15 ` msebor at gcc dot gnu.org
2022-01-19 1:04 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-18 23:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
This instance of the warning has disappeared with r12-6694.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
2022-01-17 22:11 ` [Bug middle-end/104076] " msebor at gcc dot gnu.org
2022-01-18 23:15 ` msebor at gcc dot gnu.org
@ 2022-01-19 1:04 ` cvs-commit at gcc dot gnu.org
2022-01-19 1:18 ` msebor at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-19 1:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:6325041c2b68af096195e0eef92091b2e293e950
commit r12-6714-g6325041c2b68af096195e0eef92091b2e293e950
Author: Martin Sebor <msebor@redhat.com>
Date: Tue Jan 18 17:56:20 2022 -0700
Add test for bogus warning [PR104076].
Related:
PR middle-end/104076 - bogus -Wdangling-pointer on a conditional
gcc/testsuite/ChangeLog:
PR middle-end/104076
* g++.dg/warn/Wdangling-pointer-3.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2022-01-19 1:04 ` cvs-commit at gcc dot gnu.org
@ 2022-01-19 1:18 ` msebor at gcc dot gnu.org
2022-02-02 13:54 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-19 1:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Looking at the IL before r12-6694 I'm not sure I see what could be done to keep
the warning from triggering but maybe someone has an idea for a solution I'm
not seeing, in case this comes back with a different test case.
struct S2 f2 (bool b)
{
const struct S1 D.2507[1];
...
<bb 2> :
cleanup.1_26 = 0;
cleanup.2_27 = 0;
if (b_28(D) != 0)
goto <bb 3>; [INV]
else
goto <bb 4>; [INV]
<bb 3> :
f1 ();
goto <bb 6>; [INV]
<bb 4> :
_29 = &D.2507; <<< &D.2507
_30 = _29;
_31 = 0;
cleanup.1_32 = 1;
S1::S1 (_30, 0);
<bb 5> :
_35 = _30 + 1;
_36 = _31 + -1;
retval.0_37 = _29;
_38 = 0;
cleanup.2_39 = 1;
D.2529.array = &D.2507;
D.2529.nelts = 1;
S2::S2 (&D.2525, D.2529);
<bb 6> :
# _7 = PHI <_29(5), _44(D)(3)> <<< _7 == _29(5) == &D.2507 or
undefined
# _9 = PHI <_38(5), _45(D)(3)>
# cleanup.1_13 = PHI <cleanup.1_32(5), cleanup.1_26(3)>
# cleanup.2_15 = PHI <cleanup.2_39(5), cleanup.2_27(3)>
if (cleanup.2_15 != 0)
goto <bb 7>; [INV]
else
goto <bb 10>; [INV]
<bb 7> :
_46 = &D.2507 + 1;
<bb 8> :
# _5 = PHI <_46(7), _47(9)>
if (&D.2507 == _5)
goto <bb 10>; [INV]
else
goto <bb 9>; [INV]
<bb 9> :
_47 = _5 + 18446744073709551615;
S1::~S1 (_47);
goto <bb 8>; [INV]
<bb 10> :
D.2507 ={v} {CLOBBER}; <<< D.2507 clobbered
if (cleanup.1_13 != 0)
goto <bb 11>; [INV]
else
goto <bb 15>; [INV]
<bb 11> :
if (_7 != 0B)
goto <bb 12>; [INV]
else
goto <bb 15>; [INV]
<bb 12> :
_1 = -_9;
_2 = (sizetype) _1;
_50 = _7 + _2;
<bb 13> :
# _11 = PHI <_50(12), _51(14)> <<< _11 points to &D.2507
if (_11 == _7) <<< -Wdangling-pointer
goto <bb 15>; [INV]
else
goto <bb 14>; [INV]
<bb 14> :
_51 = _11 + 18446744073709551615; <<< _51
S1::~S1 (_51);
goto <bb 13>; [INV]
<bb 15> :
return D.2525;
...
}
cc1plus.r12-6693: all warnings being treated as errors
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
` (3 preceding siblings ...)
2022-01-19 1:18 ` msebor at gcc dot gnu.org
@ 2022-02-02 13:54 ` rguenth at gcc dot gnu.org
2022-02-02 19:12 ` msebor at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-02 13:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's probably just gone latent indeed. I think to give a good false positive
vs. false negative rate we should exclude equality compares from being
considered
as "uses" of a dangling pointer. Note with optimization enabled the errorneous
path doesn't appear anymore (in the second instance of the warning).
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
` (4 preceding siblings ...)
2022-02-02 13:54 ` rguenth at gcc dot gnu.org
@ 2022-02-02 19:12 ` msebor at gcc dot gnu.org
2022-03-17 19:31 ` msebor at gcc dot gnu.org
2022-04-25 7:57 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-02 19:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Unlike the false positive -Wuse-after-free in pr104232, the instance of
-Wdangling-pointer in this case (a PHI argument) is intentional so that we
diagnose problems like those in the request for it (pr63272), or in this more
involved test case:
void warn_cond_if (int i, int n)
{
int *p;
if (i)
{
int a[] = { 1, 2 }; // { dg-message "'a' declared" "note" }
sink (a);
p = a;
}
else
p = (int*)malloc (n);
sink (p); // { dg-warning "dangling pointer 'p' to 'a' may
be used" }
}
I could add another level to -Wdangling-pointer to separately control uses in
equality expressions, for consistency with -Wuse-after-free.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
` (5 preceding siblings ...)
2022-02-02 19:12 ` msebor at gcc dot gnu.org
@ 2022-03-17 19:31 ` msebor at gcc dot gnu.org
2022-04-25 7:57 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-03-17 19:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Assignee|msebor at gcc dot gnu.org |unassigned at gcc dot gnu.org
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm no longer working on this.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/104076] bogus -Wdangling-pointer on a conditional
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
` (6 preceding siblings ...)
2022-03-17 19:31 ` msebor at gcc dot gnu.org
@ 2022-04-25 7:57 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-25 7:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104076
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Let's close this bug, the testcase no longer warns.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-04-25 7:57 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 22:10 [Bug middle-end/104076] New: bogus -Wdangling-pointer on a conditional msebor at gcc dot gnu.org
2022-01-17 22:11 ` [Bug middle-end/104076] " msebor at gcc dot gnu.org
2022-01-18 23:15 ` msebor at gcc dot gnu.org
2022-01-19 1:04 ` cvs-commit at gcc dot gnu.org
2022-01-19 1:18 ` msebor at gcc dot gnu.org
2022-02-02 13:54 ` rguenth at gcc dot gnu.org
2022-02-02 19:12 ` msebor at gcc dot gnu.org
2022-03-17 19:31 ` msebor at gcc dot gnu.org
2022-04-25 7:57 ` rguenth 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).