[PATCH] Fix PR33340, SSA corruption due to FRE

Richard Guenther rguenther@suse.de
Sat Sep 8 00:12:00 GMT 2007


FRE replaces a load by a SSA_NAME that occurs in an abnormal PHI.
Fixed by not value-numbering anything as such SSA_NAME.

Danny, does this make sense?

Ok for mainline if it passes bootstrap & regtest?

Thanks,
Richard.

2007-09-08  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/33340
	* tree-ssa-sccvn.c (set_ssa_val_to): Do not set values to
	SSA_NAMEs that occur in abnormal PHI nodes.

	* g++.dg/torture/pr33340.C: New testcase.

Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c	(revision 128251)
+++ tree-ssa-sccvn.c	(working copy)
@@ -1022,6 +1022,11 @@ set_ssa_val_to (tree from, tree to)
 {
   tree currval;
 
+  if (from != to
+      && TREE_CODE (to) == SSA_NAME
+      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (to))
+    to = from;
+
   /* The only thing we allow as value numbers are VN_TOP, ssa_names
      and invariants.  So assert that here.  */
   gcc_assert (to != NULL_TREE
Index: testsuite/g++.dg/torture/pr33340.C
===================================================================
--- testsuite/g++.dg/torture/pr33340.C	(revision 0)
+++ testsuite/g++.dg/torture/pr33340.C	(revision 0)
@@ -0,0 +1,27 @@
+void* operator new(__SIZE_TYPE__, void* __p) { }
+
+struct auto_ptr {
+        int* p;
+        ~auto_ptr() { delete p; }
+};
+
+typedef void* T;
+struct vector {
+        void push_back(const T& __x) {
+                ::new(0) T(__x);
+                insert(__x);
+        }
+        void insert(const T& __x);
+} v;
+
+void g();
+void f() {
+        auto_ptr ap;
+        if (ap.p) {
+                ap.p = new int();
+        }
+        g();
+        int* tmp = ap.p;
+        ap.p = 0;
+        v.push_back(tmp);
+}



More information about the Gcc-patches mailing list