Blame SOURCES/gcc48-pr80129.patch

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