diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index be8f0d3c76faa7d03a2e8a6db531a17849578018..c6ba0c33480cab54ef7308684e90e324da42ff2c 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -5120,6 +5120,12 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, { if (notify_temp_creation) return GS_OK; + + /* The var will be initialized and so appear on lhs of + assignment, it can't be TREE_READONLY anymore. */ + if (VAR_P (object)) + TREE_READONLY (object) = 0; + is_empty_ctor = true; break; } @@ -5171,6 +5177,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, break; } + /* The var will be initialized and so appear on lhs of + assignment, it can't be TREE_READONLY anymore. */ + if (VAR_P (object) && !notify_temp_creation) + TREE_READONLY (object) = 0; + /* If there are "lots" of initialized elements, even discounting those that are not address constants (and thus *must* be computed at runtime), then partition the constructor into diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr104529.C b/gcc/testsuite/g++.dg/tree-ssa/pr104529.C new file mode 100644 index 0000000000000000000000000000000000000000..3cb3853c22a1773ed4030ef8a35aef397bd460ca --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr104529.C @@ -0,0 +1,20 @@ +// PR middle-end/104529 +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -fdump-tree-optimized" } +// { dg-final { scan-tree-dump-not "MEM\[^\n\r]*MEM" "optimized" } } + +#include <cstddef> +#include <vector> + +struct S { + unsigned int a; + std::vector<unsigned char> b; + std::vector<unsigned char> c; +}; + +std::size_t +foo () +{ + S test[] = { { 48, { 255, 0, 0, 0, 0, 0 } } }; + return sizeof (test); +}