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