[PATCH] ipa: Adjust cgraph verifier to materialization on demand (PR 98222)

Martin Jambor mjambor@suse.cz
Sun Jan 17 21:40:14 GMT 2021


Hi,

after switching to materialization of clones on demand, the verifier
can happen to see edges leading to a clone of a materialized clone.
This means its clone_of is NULL and former_clone_of needs to be
checked in order to verify that the callee is a clone of the original
decl, which it did not do and reported edges to pointing to a wrong
place.

Fixed with the following patch, which has been pre-approved by Honza.
Bootstrapped and tested on x86_64-linux, pushed to master.

Martin

gcc/ChangeLog:

2021-01-15  Martin Jambor  <mjambor@suse.cz>

	PR ipa/98222
	* cgraph.c (clone_of_p): Check also former_clone_of as we climb
	the clone tree.

gcc/testsuite/ChangeLog:

2021-01-15  Martin Jambor  <mjambor@suse.cz>

	PR ipa/98222
	* gcc.dg/ipa/pr98222.c: New test.
---
 gcc/cgraph.c                       |  4 +++-
 gcc/testsuite/gcc.dg/ipa/pr98222.c | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr98222.c

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index d0d785b3438..db038306e19 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3081,7 +3081,9 @@ clone_of_p (cgraph_node *node, cgraph_node *node2)
 
   if (!node->thunk && !node->former_thunk_p ())
     {
-      while (node2 && node->decl != node2->decl)
+      while (node2
+	     && node->decl != node2->decl
+	     && node->decl != node2->former_clone_of)
 	node2 = node2->clone_of;
       return node2 != NULL;
     }
diff --git a/gcc/testsuite/gcc.dg/ipa/pr98222.c b/gcc/testsuite/gcc.dg/ipa/pr98222.c
new file mode 100644
index 00000000000..92e857c2048
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr98222.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O3"  } */
+
+int a, b, *c;
+
+int f (int j, int k) {
+  b = k / j;
+  if (a)
+    f(0, 0);
+  *c = f(b & a, 0);
+  return 0;
+}
+
+int main() {
+  if (a)
+    while (1)
+      f(0, 0);
+  return 0;
+}
-- 
2.29.2



More information about the Gcc-patches mailing list