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: r186745
This commit is contained in:
Jakub Jelinek 2012-04-24 08:10:53 +02:00 committed by Jakub Jelinek
parent 2c2c513a9a
commit a2e8e5e32d
3 changed files with 33 additions and 0 deletions

View File

@ -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.

View File

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

View File

@ -3953,6 +3953,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
@ -4021,6 +4028,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: