public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] call mark_dfs_back_edges() before testing EDGE_DFS_BACK [PR104761]
@ 2022-03-02 23:15 Martin Sebor
  2022-03-03  8:01 ` Jakub Jelinek
  2022-03-10 14:17 ` [PATCH] call mark_dfs_back_edges() before testing EDGE_DFS_BACK [PR104761] Jason Merrill
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Sebor @ 2022-03-02 23:15 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]

The -Wdangling-pointer code tests the EDGE_DFS_BACK but the pass never
calls the mark_dfs_back_edges() function that initializes the bit (I
didn't know about it).  As a result the bit is not set when expected,
which can cause false positives under the right conditions.

The attached patch adds a call to the warning pass to initialize
the bit.  Tested on x86_64-linux.

Martin

[-- Attachment #2: gcc-104761.diff --]
[-- Type: text/x-patch, Size: 2483 bytes --]

Call mark_dfs_back_edges before testing EDGE_DFS_BACK [PR104761].

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.

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index b7cdad517b3..b519712d76e 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -47,7 +47,7 @@
 #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"
@@ -4710,6 +4710,9 @@ pass_waccess::execute (function *fun)
   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;
diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-pointer-4.C b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-4.C
new file mode 100644
index 00000000000..3608cc79e9a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-4.C
@@ -0,0 +1,23 @@
+/* PR middle-end/104761 - False positive -Wdangling-pointer warning
+   in NetworkManager
+   { 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 ( ; ; );
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/Wdangling-pointer-4.c b/gcc/testsuite/gcc.dg/Wdangling-pointer-4.c
new file mode 100644
index 00000000000..b2716c7b634
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wdangling-pointer-4.c
@@ -0,0 +1,23 @@
+/* PR middle-end/104761 - False positive -Wdangling-pointer warning
+   in NetworkManager
+   { 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 ( ; ; );
+    }
+}

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

end of thread, other threads:[~2022-03-10 14:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 23:15 [PATCH] call mark_dfs_back_edges() before testing EDGE_DFS_BACK [PR104761] Martin Sebor
2022-03-03  8:01 ` Jakub Jelinek
2022-03-03  9:26   ` Richard Biener
2022-03-03 17:56   ` Jeff Law
2022-03-04  0:08   ` Martin Sebor
2022-03-04 13:58     ` Jakub Jelinek
2022-03-05  8:08       ` [PATCH] waccess: Remove visited bitmap and stop on EDGE_ABNORMAL Jakub Jelinek
2022-03-05 10:28         ` Richard Biener
2022-03-10 14:17 ` [PATCH] call mark_dfs_back_edges() before testing EDGE_DFS_BACK [PR104761] Jason Merrill

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).