Blame SOURCES/gcc48-pr80129.patch

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