diff mbox series

tree-optimization/115694 - ICE with complex store rewrite

Message ID 20240701055643.106B7139C2@imap1.dmz-prg2.suse.org
State New
Headers show
Series tree-optimization/115694 - ICE with complex store rewrite | expand

Commit Message

Richard Biener July 1, 2024, 5:56 a.m. UTC
The following adds a missed check when forwprop attempts to rewrite
a complex store.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/115694
	* tree-ssa-forwprop.cc (pass_forwprop::execute): Check the
	store is complex before rewriting it.

	* g++.dg/torture/pr115694.C: New testcase.
---
 gcc/testsuite/g++.dg/torture/pr115694.C | 13 +++++++++++++
 gcc/tree-ssa-forwprop.cc                |  2 ++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr115694.C
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/torture/pr115694.C b/gcc/testsuite/g++.dg/torture/pr115694.C
new file mode 100644
index 00000000000..bbce47decf8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr115694.C
@@ -0,0 +1,13 @@ 
+// { dg-do compile }
+
+_Complex a;
+typedef struct {
+  double a[2];
+} b;
+void c(b);
+void d()
+{
+  _Complex b1 = a;
+  b t = __builtin_bit_cast (b, b1);
+  c(t);
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index d238fd342e4..44a6b5d39aa 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3766,6 +3766,8 @@  pass_forwprop::execute (function *fun)
 		  && gimple_store_p (use_stmt)
 		  && !gimple_has_volatile_ops (use_stmt)
 		  && is_gimple_assign (use_stmt)
+		  && (TREE_CODE (TREE_TYPE (gimple_assign_lhs (use_stmt)))
+		      == COMPLEX_TYPE)
 		  && (TREE_CODE (gimple_assign_lhs (use_stmt))
 		      != TARGET_MEM_REF))
 		{