diff options
author | Jakub Jelinek <jakub@redhat.com> | 2012-04-24 08:07:30 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2012-04-24 08:07:30 +0200 |
commit | dd0a516fa722bb2847ae1b4581ae2091c3977a5b (patch) | |
tree | 58f80e09989829fcabbe550b0bfbcba45424ec41 | |
parent | 06edd772e354ab922fa429bfe788a006f53511d8 (diff) | |
download | gcc-dd0a516fa722bb2847ae1b4581ae2091c3977a5b.tar.gz |
re PR middle-end/53084 (GCC cannot handle array initialization of string constant with point arithmetic properly)
PR middle-end/53084
* varasm.c (compute_reloc_for_constant): Handle ADDR_EXPR
of MEM_REF.
(output_addressed_constants): Likewise.
* gcc.c-torture/execute/pr53084.c: New test.
From-SVN: r186742
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr53084.c | 18 | ||||
-rw-r--r-- | gcc/varasm.c | 10 |
4 files changed, 38 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f3992e1b8b2..8dbaeffd780 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2012-04-24 Jakub Jelinek <jakub@redhat.com> + PR middle-end/53084 + * varasm.c (compute_reloc_for_constant): Handle ADDR_EXPR + of MEM_REF. + (output_addressed_constants): Likewise. + PR middle-end/52999 * varasm.c (get_section): Don't ICE for section conflicts with built-in section kinds. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8ef28433fd3..76420e0ebe2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-04-24 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/53084 + * gcc.c-torture/execute/pr53084.c: New test. + 2012-04-23 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/cpp0x/noexcept15.C: Adjust for Rev 186726 library changes. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr53084.c b/gcc/testsuite/gcc.c-torture/execute/pr53084.c new file mode 100644 index 00000000000..1afc016dfc4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr53084.c @@ -0,0 +1,18 @@ +/* PR middle-end/53084 */ + +extern void abort (void); + +__attribute__((noinline, noclone)) void +bar (const char *p) +{ + if (p[0] != 'o' || p[1] != 'o' || p[2]) + abort (); +} + +int +main () +{ + static const char *const foo[] = {"foo" + 1}; + bar (foo[0]); + return 0; +} diff --git a/gcc/varasm.c b/gcc/varasm.c index b7939c54a84..03ac49b4677 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3934,6 +3934,13 @@ compute_reloc_for_constant (tree exp) tem = TREE_OPERAND (tem, 0)) ; + if (TREE_CODE (tem) == MEM_REF + && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR) + { + reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0)); + break; + } + if (TREE_PUBLIC (tem)) reloc |= 2; else @@ -4002,6 +4009,9 @@ output_addressed_constants (tree exp) if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR) output_constant_def (tem, 0); + + if (TREE_CODE (tem) == MEM_REF) + output_addressed_constants (TREE_OPERAND (tem, 0)); break; case PLUS_EXPR: |