]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/123596 - fix partial virtual SSA update in eh_cleanup
authorRichard Biener <rguenther@suse.de>
Thu, 29 Jan 2026 09:41:16 +0000 (10:41 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 29 Jan 2026 11:37:47 +0000 (12:37 +0100)
The following replaces the not quite correct use of
mark_virtual_operand_for_renaming by an appropriate way of dealing
with a possibly partially up-to-date virtual SSA form.  Namely
when we just move stmts and not remove a VDEF we should arrange
for missing virtual PHIs to be created and just queue its arguments
for possible renaming.  For the testcase at hand there's no renaming
necessary in the end when done this way.

PR tree-optimization/123596
* tree-eh.cc (sink_clobbers): Create a virtual PHI when
one is required but not present, queuing arguments
for renaming.

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

gcc/testsuite/g++.dg/torture/pr123596.C [new file with mode: 0644]
gcc/tree-eh.cc

diff --git a/gcc/testsuite/g++.dg/torture/pr123596.C b/gcc/testsuite/g++.dg/torture/pr123596.C
new file mode 100644 (file)
index 0000000..f146e41
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+struct b {
+  ~b() {}
+};
+struct c {
+  c(long, const int &, b = b());
+};
+int _setjmp();
+long d;
+void e(int *);
+int a;
+int main()
+{
+  auto f = [](int *data) { e(data); };
+  f(&a);
+  c(d, _setjmp());
+}
index ea093544b510443b5f4fe511cd77a8ec394c354b..512dca807a71aa53e8e695cb9d8fb1cd21c488e8 100644 (file)
@@ -3861,6 +3861,18 @@ sink_clobbers (basic_block bb,
     }
   if (first_sunk)
     {
+      /* If there isn't a single predecessor but no virtual PHI node
+        create one and arrange for virtual operands to be renamed as
+        we cannot be sure all incoming edges will updated from sinking
+        something.  */
+      if (!vphi && !single_pred_p (succbb))
+       {
+         vphi = create_phi_node (gimple_vop (cfun), succbb);
+         FOR_EACH_EDGE (e, ei, succbb->preds)
+           add_phi_arg (vphi, gimple_vop (cfun), e, UNKNOWN_LOCATION);
+         mark_virtual_operands_for_renaming (cfun);
+         todo |= TODO_update_ssa_only_virtuals;
+       }
       /* Adjust virtual operands if we sunk across a virtual PHI.  */
       if (vphi)
        {
@@ -3880,14 +3892,6 @@ sink_clobbers (basic_block bb,
                   gimple_vuse (last_sunk));
          SET_USE (gimple_vuse_op (last_sunk), phi_def);
        }
-      /* If there isn't a single predecessor but no virtual PHI node
-         arrange for virtual operands to be renamed.  */
-      else if (!single_pred_p (succbb)
-              && TREE_CODE (gimple_vuse (last_sunk)) == SSA_NAME)
-       {
-         mark_virtual_operand_for_renaming (gimple_vuse (last_sunk));
-         todo |= TODO_update_ssa_only_virtuals;
-       }
     }
 
   return todo;