Blame SOURCES/gcc48-pr80129.patch

56d343
2017-05-30  Jakub Jelinek  <jakub@redhat.com>
56d343
 
56d343
 	Backported from mainline
56d343
	2017-03-22  Jakub Jelinek  <jakub@redhat.com>
56d343
56d343
	PR c++/80129
56d343
	* gimplify.c (gimplify_modify_expr_rhs) <case COND_EXPR>: Clear
56d343
	TREE_READONLY on result if writing it more than once.
56d343
56d343
	* g++.dg/torture/pr80129.C: New test.
56d343
56d343
--- gcc/gimplify.c
56d343
+++ gcc/gimplify.c
56d343
@@ -4293,6 +4293,14 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p,
56d343
 	      if (ret != GS_ERROR)
56d343
 		ret = GS_OK;
56d343
 
56d343
+	      /* If we are going to write RESULT more than once, clear
56d343
+		 TREE_READONLY flag, otherwise we might incorrectly promote
56d343
+		 the variable to static const and initialize it at compile
56d343
+		 time in one of the branches.  */
56d343
+	      if (TREE_CODE (result) == VAR_DECL
56d343
+		  && TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node
56d343
+		  && TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node)
56d343
+		TREE_READONLY (result) = 0;
56d343
 	      if (TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node)
56d343
 		TREE_OPERAND (cond, 1)
56d343
 		  = build2 (code, void_type_node, result,
56d343
--- /dev/null
56d343
+++ gcc/testsuite/g++.dg/torture/pr80129.C
56d343
@@ -0,0 +1,14 @@
56d343
+// PR c++/80129
56d343
+// { dg-do run }
56d343
+// { dg-options "-std=c++11" }
56d343
+
56d343
+struct A { bool a; int b; };
56d343
+
56d343
+int
56d343
+main ()
56d343
+{
56d343
+  bool c = false;
56d343
+  const A x = c ? A {true, 1} : A {false, 0};
56d343
+  if (x.a)
56d343
+    __builtin_abort ();
56d343
+}