diff mbox

Fix wrong-code at -O0 with MEM_REF in initializer (PR middle-end/53084)

Message ID 20120423230312.GO16117@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek April 23, 2012, 11:03 p.m. UTC
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.


	Jakub

Comments

Richard Henderson April 23, 2012, 11:12 p.m. UTC | #1
On 04/23/12 16:03, Jakub Jelinek wrote:
> 	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.

Ok.


r~
Richard Biener April 24, 2012, 5:56 a.m. UTC | #2
On Tue, Apr 24, 2012 at 1:03 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> 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?

Isn't this latent in 4.6?

Thanks,
Richard.

> 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
Jakub Jelinek April 24, 2012, 5:59 a.m. UTC | #3
On Tue, Apr 24, 2012 at 07:56:11AM +0200, Richard Guenther wrote:
> On Tue, Apr 24, 2012 at 1:03 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > 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?
> 
> Isn't this latent in 4.6?

Possibly.  The bug started being reproduceable on this testcase with
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178312
and stopped being reproducible with
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186687

	Jakub
diff mbox

Patch

--- 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;
+}