aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2012-05-01 21:25:15 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-05-01 21:25:15 +0000
commita845a7f5aa73f695fd44fac430bf4ac684515173 (patch)
treeed944aa62023941006f92af1582be1c26ecce946 /gcc/c-decl.c
parentb7a9facb2c4308b738b0785a291ae31f02d30b76 (diff)
downloadgcc-a845a7f5aa73f695fd44fac430bf4ac684515173.zip
gcc-a845a7f5aa73f695fd44fac430bf4ac684515173.tar.gz
gcc-a845a7f5aa73f695fd44fac430bf4ac684515173.tar.bz2
re PR c/37303 (const compound initializers in structs are written to .data instead of .rodata)
gcc/: PR c/37303 * c-decl.c (build_compound_literal): Make the decl readonly if it an array of a readonly type. * gimplify.c (gimplify_compound_literal_expr): Add fallback parameter. Change all callers. If the decl is not addressable and is not an l-value, make it readonly. gcc/testsuite: PR c/37303 * gcc.dg/pr37303.c: New test. From-SVN: r187027
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 72fad86..158b3ad 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -4622,7 +4622,9 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const)
TREE_USED (decl) = 1;
DECL_READ_P (decl) = 1;
TREE_TYPE (decl) = type;
- TREE_READONLY (decl) = TYPE_READONLY (type);
+ TREE_READONLY (decl) = (TYPE_READONLY (type)
+ || (TREE_CODE (type) == ARRAY_TYPE
+ && TYPE_READONLY (TREE_TYPE (type))));
store_init_value (loc, decl, init, NULL_TREE);
if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))