From a845a7f5aa73f695fd44fac430bf4ac684515173 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 1 May 2012 21:25:15 +0000 Subject: 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 --- gcc/c-decl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/c-decl.c') 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)) -- cgit v1.1