This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix wrong-code at -O0 with MEM_REF in initializer (PR middle-end/53084)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 24 Apr 2012 01:03:12 +0200
- Subject: [PATCH] Fix wrong-code at -O0 with MEM_REF in initializer (PR middle-end/53084)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
output_addressed_constants isn't able to output constants addressed
with &MEM_REF<&something, X> and similarly compute_reloc_for_constant
doesn't handle it. Fixed thusly, bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk/4.7?
2012-04-23 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.
* gcc.c-torture/execute/pr53084.c: New test.
--- gcc/varasm.c.jj 2012-04-23 18:55:46.000000000 +0200
+++ gcc/varasm.c 2012-04-23 20:26:15.930660033 +0200
@@ -3948,6 +3948,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
@@ -4016,6 +4023,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:
--- gcc/testsuite/gcc.c-torture/execute/pr53084.c 2012-04-16 20:35:50.603036390 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr53084.c 2012-04-23 20:30:57.193896339 +0200
@@ -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;
+}
Jakub