Blame SOURCES/gcc48-pr80129.patch

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