diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-05-01 21:25:15 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-05-01 21:25:15 +0000 |
commit | 73242672e877fad79873cf3e764dc4e8771870bb (patch) | |
tree | ed944aa62023941006f92af1582be1c26ecce946 | |
parent | 970b2c22a884383459d455b8614222caa320c7d6 (diff) | |
download | gcc-73242672e877fad79873cf3e764dc4e8771870bb.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187027 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/c-decl.c | 4 | ||||
-rw-r--r-- | gcc/gimplify.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr37303.c | 5 |
5 files changed, 31 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d86d30e1e04..5cf6a8ff960 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2012-05-01 Ian Lance Taylor <iant@google.com> + + 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. + 2012-05-01 Bernd Schmidt <bernds@codesourcery.com> * ira.c (allocated_reg_info_size): New static variable. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 72fad86f9d1..158b3ad0f19 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)) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index cef61180c38..9c58a38b927 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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 952f1d3f2c6..8f32793b77d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-05-01 Ian Lance Taylor <iant@google.com> + + PR c/37303 + * gcc.dg/pr37303.c: New test. + 2012-05-01 Richard Henderson <rth@redhat.com> * lib/target-supports.exp diff --git a/gcc/testsuite/gcc.dg/pr37303.c b/gcc/testsuite/gcc.dg/pr37303.c new file mode 100644 index 00000000000..434fc9d24ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr37303.c @@ -0,0 +1,5 @@ +/* { dg-do compile { target *-*-elf* *-*-linux-gnu* } } */ +/* { dg-options "-std=c99" } +/* { dg-final { scan-assembler "rodata" } } */ + +struct S { const int *x; } s = { (const int[]){1, 2, 3} }; |