public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/105867] New: incorrect dangling-pointer warning
@ 2022-06-07  0:13 gman at chromium dot org
  2022-06-07  6:05 ` [Bug tree-optimization/105867] [12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gman at chromium dot org @ 2022-06-07  0:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

            Bug ID: 105867
           Summary: incorrect dangling-pointer warning
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gman at chromium dot org
  Target Milestone: ---

Created attachment 53094
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53094&action=edit
dangling-pointer warning repo

This code (attached) could be doing something wrong but I was asked to look
into why this code gets an dangling-pointer warning in gcc 12.1 and after
looking though it it seems like maybe the code is fine and the warning is
incorrect?

compiled with 

-std=c++17 -Wall -Wextra -pedantic-errors -Wdangling-pointer -O2

note that there is a function, TIntermRebuild::printStack, which is called in
several places. It's inclusion doesn't seem like it should affect the warning.
As it is it is compiled out via a macro

    #define printStack(msg)

compiling it back in (delete the line above) makes the warning go away.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/105867] [12/13 Regression] incorrect dangling-pointer warning
  2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
@ 2022-06-07  6:05 ` pinskia at gcc dot gnu.org
  2022-07-25 16:10 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-07  6:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-06-07
            Summary|incorrect dangling-pointer  |[12/13 Regression]
                   |warning                     |incorrect dangling-pointer
                   |                            |warning
             Status|UNCONFIRMED                 |NEW
          Component|middle-end                  |tree-optimization
   Target Milestone|---                         |12.2
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks the warning does not notice the store was "undone" with later on.
We have:
  MEM[(struct ConsList *)this_3(D) + 8B].value = currNode_5(D);
  MEM[(struct ConsList *)this_3(D) + 8B].tail = &guard.oldNodeStack;

....
  <bb 5> [local count: 118111600]:
  MEM[(struct ConsList *)this_3(D) + 8B] = guard.oldNodeStack;
  guard ={v} {CLOBBER};
  guard ={v} {CLOBBER(eol)};
  return;

The store to this removes the stored address of the local variable.

Confirmed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/105867] [12/13 Regression] incorrect dangling-pointer warning
  2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
  2022-06-07  6:05 ` [Bug tree-optimization/105867] [12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-07-25 16:10 ` rguenth at gcc dot gnu.org
  2022-11-13  9:32 ` agriff at tin dot it
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-25 16:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
           Priority|P3                          |P2

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  I don't know how the dataflow of the diagnostic is implemented but
to fix this it would need to go backwards from function exits and maintain a
set of "killed" locations it would not diagnose in earlier code.  Of course
it's difficult in general considering

  global = &local;
  tem = global;
  other_global = tem;
  global = NULL;

and here &local escapes to other_global but we'd have to either rely on
optimization forwarding &local to tem or we'd have to conservatively
assume escaping (what the current code seems to do).  The former gets
you false negatives while the latter false positives.

Note for the testcase the store we diagnose is not dead since it has
possible uses via function calls also getting 'this', so optimization
is of no help in avoiding the false positive here.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/105867] [12/13 Regression] incorrect dangling-pointer warning
  2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
  2022-06-07  6:05 ` [Bug tree-optimization/105867] [12/13 Regression] " pinskia at gcc dot gnu.org
  2022-07-25 16:10 ` rguenth at gcc dot gnu.org
@ 2022-11-13  9:32 ` agriff at tin dot it
  2023-03-20 10:48 ` wielkiegie at gmail dot com
  2023-05-08 12:24 ` [Bug tree-optimization/105867] [12/13/14 " rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: agriff at tin dot it @ 2022-11-13  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

Andrea Griffini <agriff at tin dot it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |agriff at tin dot it

--- Comment #4 from Andrea Griffini <agriff at tin dot it> ---
Created attachment 53891
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53891&action=edit
Simpler version that triggers the bug

This code compiled on 12.2.0 with -O3 -Wall generates a warning about storing
the address of a local variable. Surprisingly (for me) adding either of the two
`printf` statements makes the warning go away.

The code seems correct to me; a doubly linked list of all instances of Node is
kept by inserting nodes in constructor and removing them in destructor.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/105867] [12/13 Regression] incorrect dangling-pointer warning
  2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
                   ` (2 preceding siblings ...)
  2022-11-13  9:32 ` agriff at tin dot it
@ 2023-03-20 10:48 ` wielkiegie at gmail dot com
  2023-05-08 12:24 ` [Bug tree-optimization/105867] [12/13/14 " rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: wielkiegie at gmail dot com @ 2023-03-20 10:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

Gustaw Smolarczyk <wielkiegie at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wielkiegie at gmail dot com

--- Comment #5 from Gustaw Smolarczyk <wielkiegie at gmail dot com> ---
This warning is triggered just by std::set::swap(std::set&) when optimizing.

https://godbolt.org/z/e84xPMdf6


--------
#include <set>

void foo()
{
  std::set<int> x, y;
  x.swap(y);
}
--------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/105867] [12/13/14 Regression] incorrect dangling-pointer warning
  2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
                   ` (3 preceding siblings ...)
  2023-03-20 10:48 ` wielkiegie at gmail dot com
@ 2023-05-08 12:24 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105867

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-08 12:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07  0:13 [Bug middle-end/105867] New: incorrect dangling-pointer warning gman at chromium dot org
2022-06-07  6:05 ` [Bug tree-optimization/105867] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-07-25 16:10 ` rguenth at gcc dot gnu.org
2022-11-13  9:32 ` agriff at tin dot it
2023-03-20 10:48 ` wielkiegie at gmail dot com
2023-05-08 12:24 ` [Bug tree-optimization/105867] [12/13/14 " 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).