diff options
author | Ian Lance Taylor <iant@google.com> | 2012-05-01 21:25:15 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-05-01 21:25:15 +0000 |
commit | a845a7f5aa73f695fd44fac430bf4ac684515173 (patch) | |
tree | ed944aa62023941006f92af1582be1c26ecce946 /gcc/gimplify.c | |
parent | b7a9facb2c4308b738b0785a291ae31f02d30b76 (diff) | |
download | gcc-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/gimplify.c')
-rw-r--r-- | gcc/gimplify.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c index cef6118..9c58a38 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3756,7 +3756,8 @@ rhs_predicate_for (tree lhs) decl instead. */ static enum gimplify_status -gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p) +gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p, + fallback_t fallback) { tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p); tree decl = DECL_EXPR_DECL (decl_s); @@ -3775,6 +3776,12 @@ gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p) && !needs_to_live_in_memory (decl)) DECL_GIMPLE_REG_P (decl) = 1; + /* If the decl is not addressable, then it is being used in some + expression or on the right hand side of a statement, and it can + be put into a readonly data section. */ + if (!TREE_ADDRESSABLE (decl) && (fallback & fb_lvalue) == 0) + TREE_READONLY (decl) = 1; + /* This decl isn't mentioned in the enclosing block, so add it to the list of temps. FIXME it seems a bit of a kludge to say that anonymous artificial vars aren't pushed, but everything else is. */ @@ -7071,7 +7078,7 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, break; case COMPOUND_LITERAL_EXPR: - ret = gimplify_compound_literal_expr (expr_p, pre_p); + ret = gimplify_compound_literal_expr (expr_p, pre_p, fallback); break; case MODIFY_EXPR: |