Blame SOURCES/gcc48-pr80129.patch

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