From bf7d31c1a6719fbf1e36d6dde187245636d8d558 Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Wed, 6 Apr 2005 00:57:39 -0400
Subject: [PATCH] re PR c++/19312 (ICE in stabilize_call when throwing a copy)

        PR c++/19312
        * tree.c (stabilize_init): Don't bother trying to stabilize
        something with no side-effects.

From-SVN: r97691
---
 gcc/cp/ChangeLog                 | 6 ++++++
 gcc/cp/tree.c                    | 5 ++++-
 gcc/testsuite/g++.dg/eh/throw3.C | 8 ++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/eh/throw3.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f37530d94ced..aec76819098e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2005-04-06  Jason Merrill  <jason@redhat.com>
+
+	PR c++/19312
+	* tree.c (stabilize_init): Don't bother trying to stabilize
+	something with no side-effects.
+
 2005-04-05  Mark Mitchell  <mark@codesourcery.com>
 
 	PR c++/20763
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 8b0d9aa872f7..5d80d5961628 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2257,7 +2257,10 @@ stabilize_init (tree init, tree *initp)
       if (TREE_CODE (t) == COND_EXPR)
 	return false;
 
-      stabilize_call (t, initp);
+      /* The TARGET_EXPR might be initializing via bitwise copy from
+	 another variable; leave that alone.  */
+      if (TREE_SIDE_EFFECTS (t))
+	stabilize_call (t, initp);
     }
 
   return true;
diff --git a/gcc/testsuite/g++.dg/eh/throw3.C b/gcc/testsuite/g++.dg/eh/throw3.C
new file mode 100644
index 000000000000..3417eeb3dcf9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/throw3.C
@@ -0,0 +1,8 @@
+// PR c++/19312
+
+struct A {};
+
+void foo(A a)
+{
+    throw (A)a;
+}
-- 
GitLab