Resolves:
PR middle-end/104761 - bogus -Wdangling-pointer with cleanup and infinite loop
gcc/ChangeLog:
PR middle-end/104761
* gimple-ssa-warn-access.cc (pass_waccess::execute): Call
mark_dfs_back_edges.
gcc/testsuite/ChangeLog:
PR middle-end/104761
* g++.dg/warn/Wdangling-pointer-4.C: New test.
* gcc.dg/Wdangling-pointer-4.c: New test.
#include "tree-object-size.h"
#include "tree-ssa-strlen.h"
#include "calls.h"
-#include "cfgloop.h"
+#include "cfganal.h"
#include "intl.h"
#include "gimple-range.h"
#include "stringpool.h"
calculate_dominance_info (CDI_DOMINATORS);
calculate_dominance_info (CDI_POST_DOMINATORS);
+ /* Set or clear EDGE_DFS_BACK bits on back edges. */
+ mark_dfs_back_edges (fun);
+
/* Create a new ranger instance and associate it with FUN. */
m_ptr_qry.rvals = enable_ranger (fun);
m_func = fun;
--- /dev/null
+/* PR middle-end/104761 - bogus -Wdangling-pointer with cleanup and infinite loop
+ { dg-do compile }
+ { dg-options "-O -Wall -fno-exceptions" } */
+
+struct S { int i; };
+
+struct X { ~X (); };
+
+void g (int);
+
+void test (int i)
+{
+ S s = { 0 };
+
+ X x;
+
+ if (i)
+ {
+ g (s.i); // { dg-bogus "-Wdangling-pointer" }
+ for ( ; ; );
+ }
+}
--- /dev/null
+/* PR middle-end/104761 - bogus -Wdangling-pointer with cleanup and infinite loop
+ { dg-do compile }
+ { dg-options "-O -Wall" } */
+
+typedef struct { int i; } S;
+
+void f (S **);
+
+int g (int);
+
+void nowarn (int x)
+{
+ S s = { 0 };
+
+ __attribute__((__cleanup__ (f))) S *p = 0;
+
+ if (x)
+ {
+ g (s.i); // { dg-bogus "-Wdangling-pointer" }
+ for ( ; ; );
+ }
+}