aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-03-22 19:45:48 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-03-22 19:45:48 +0100
commit68ed2ba0a7d60275ac044a4cb50b33eb33fbb813 (patch)
tree1e4f17b8856d8dc6d804ba411cf9c40568e61ca9 /gcc
parent0e2468e0ca0ad2e7adc0098f6a4061be7475fdc1 (diff)
downloadgcc-68ed2ba0a7d60275ac044a4cb50b33eb33fbb813.zip
gcc-68ed2ba0a7d60275ac044a4cb50b33eb33fbb813.tar.gz
gcc-68ed2ba0a7d60275ac044a4cb50b33eb33fbb813.tar.bz2
re PR c++/80129 (wrong code with ternary struct assignment to const)
PR c++/80129 * gimplify.c (gimplify_modify_expr_rhs) <case COND_EXPR>: Clear TREE_READONLY on result if writing it more than once. * g++.dg/torture/pr80129.C: New test. From-SVN: r246401
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/gimplify.c8
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/torture/pr80129.C14
4 files changed, 29 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a1e007f..5259dce 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
2017-03-22 Jakub Jelinek <jakub@redhat.com>
+ PR c++/80129
+ * gimplify.c (gimplify_modify_expr_rhs) <case COND_EXPR>: Clear
+ TREE_READONLY on result if writing it more than once.
+
PR sanitizer/80110
* doc/invoke.texi (-fsanitize=thread): Document that with
-fnon-call-exceptions atomics are not able to throw
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 5658d0a..f90ae94 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -5098,6 +5098,14 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p,
if (ret != GS_ERROR)
ret = GS_OK;
+ /* If we are going to write RESULT more than once, clear
+ TREE_READONLY flag, otherwise we might incorrectly promote
+ the variable to static const and initialize it at compile
+ time in one of the branches. */
+ if (VAR_P (result)
+ && TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node
+ && TREE_TYPE (TREE_OPERAND (cond, 2)) != void_type_node)
+ TREE_READONLY (result) = 0;
if (TREE_TYPE (TREE_OPERAND (cond, 1)) != void_type_node)
TREE_OPERAND (cond, 1)
= build2 (code, void_type_node, result,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d8b45dc..add3a14 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2017-03-22 Jakub Jelinek <jakub@redhat.com>
+ PR c++/80129
+ * g++.dg/torture/pr80129.C: New test.
+
PR sanitizer/80110
* g++.dg/tsan/pr80110.C: New test.
diff --git a/gcc/testsuite/g++.dg/torture/pr80129.C b/gcc/testsuite/g++.dg/torture/pr80129.C
new file mode 100644
index 0000000..134293c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr80129.C
@@ -0,0 +1,14 @@
+// PR c++/80129
+// { dg-do run }
+// { dg-options "-std=c++11" }
+
+struct A { bool a; int b; };
+
+int
+main ()
+{
+ bool c = false;
+ const A x = c ? A {true, 1} : A {false, 0};
+ if (x.a)
+ __builtin_abort ();
+}