Commit 93e452ed by Richard Guenther Committed by Richard Biener

re PR middle-end/47370 (error: invalid first operand of MEM_REF)

2011-01-20  Richard Guenther  <rguenther@suse.de>

	PR middle-end/47370
	* tree-inline.c (remap_gimple_op_r): Recurse manually for
	the pointer operand of MEM_REFs.

	* gcc.dg/torture/pr47370.c: New testcase.

From-SVN: r169055
parent 28fc44f3
2011-01-20 Richard Guenther <rguenther@suse.de>
PR middle-end/47370
* tree-inline.c (remap_gimple_op_r): Recurse manually for
the pointer operand of MEM_REFs.
2011-01-20 Jakub Jelinek <jakub@redhat.com> 2011-01-20 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/46130 PR tree-optimization/46130
......
2011-01-20 Richard Guenther <rguenther@suse.de>
PR middle-end/47370
* gcc.dg/torture/pr47370.c: New testcase.
2011-01-20 Jakub Jelinek <jakub@redhat.com> 2011-01-20 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/46130 PR tree-optimization/46130
......
/* { dg-do compile } */
struct S { int s; };
void
foo (void)
{
for (;;)
;
}
struct S
bar (void)
{
struct S s = { 99 };
return s;
}
void
baz (int i)
{
struct S s[1];
s[0] = bar ();
bar ();
foo ();
}
...@@ -811,57 +811,47 @@ remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data) ...@@ -811,57 +811,47 @@ remap_gimple_op_r (tree *tp, int *walk_subtrees, void *data)
knows not to copy VAR_DECLs, etc., so this is safe. */ knows not to copy VAR_DECLs, etc., so this is safe. */
if (TREE_CODE (*tp) == MEM_REF) if (TREE_CODE (*tp) == MEM_REF)
{ {
/* We need to re-canonicalize MEM_REFs from inline substitutions tree ptr = TREE_OPERAND (*tp, 0);
that can happen when a pointer argument is an ADDR_EXPR. */ tree old = *tp;
tree decl = TREE_OPERAND (*tp, 0); tree tem;
tree *n;
/* See remap_ssa_name. */
if (TREE_CODE (decl) == SSA_NAME
&& TREE_CODE (SSA_NAME_VAR (decl)) == RESULT_DECL
&& id->transform_return_to_modify)
decl = SSA_NAME_VAR (decl);
n = (tree *) pointer_map_contains (id->decl_map, decl); /* We need to re-canonicalize MEM_REFs from inline substitutions
if (n) that can happen when a pointer argument is an ADDR_EXPR.
Recurse here manually to allow that. */
walk_tree (&ptr, remap_gimple_op_r, data, NULL);
if ((tem = maybe_fold_offset_to_reference (EXPR_LOCATION (*tp),
ptr,
TREE_OPERAND (*tp, 1),
TREE_TYPE (*tp)))
&& TREE_THIS_VOLATILE (tem) == TREE_THIS_VOLATILE (old))
{ {
tree old = *tp; tree *tem_basep = &tem;
tree ptr = unshare_expr (*n); while (handled_component_p (*tem_basep))
tree tem; tem_basep = &TREE_OPERAND (*tem_basep, 0);
if ((tem = maybe_fold_offset_to_reference (EXPR_LOCATION (*tp), if (TREE_CODE (*tem_basep) == MEM_REF)
ptr, *tem_basep
TREE_OPERAND (*tp, 1), = build2 (MEM_REF, TREE_TYPE (*tem_basep),
TREE_TYPE (*tp))) TREE_OPERAND (*tem_basep, 0),
&& TREE_THIS_VOLATILE (tem) == TREE_THIS_VOLATILE (old)) fold_convert (TREE_TYPE (TREE_OPERAND (*tp, 1)),
{ TREE_OPERAND (*tem_basep, 1)));
tree *tem_basep = &tem;
while (handled_component_p (*tem_basep))
tem_basep = &TREE_OPERAND (*tem_basep, 0);
if (TREE_CODE (*tem_basep) == MEM_REF)
*tem_basep
= build2 (MEM_REF, TREE_TYPE (*tem_basep),
TREE_OPERAND (*tem_basep, 0),
fold_convert (TREE_TYPE (TREE_OPERAND (*tp, 1)),
TREE_OPERAND (*tem_basep, 1)));
else
*tem_basep
= build2 (MEM_REF, TREE_TYPE (*tem_basep),
build_fold_addr_expr (*tem_basep),
build_int_cst
(TREE_TYPE (TREE_OPERAND (*tp, 1)), 0));
*tp = tem;
}
else else
{ *tem_basep
*tp = fold_build2 (MEM_REF, TREE_TYPE (*tp), = build2 (MEM_REF, TREE_TYPE (*tem_basep),
ptr, TREE_OPERAND (*tp, 1)); build_fold_addr_expr (*tem_basep),
TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old); build_int_cst
TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old); (TREE_TYPE (TREE_OPERAND (*tp, 1)), 0));
} *tp = tem;
TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old);
*walk_subtrees = 0;
return NULL;
} }
else
{
*tp = fold_build2 (MEM_REF, TREE_TYPE (*tp),
ptr, TREE_OPERAND (*tp, 1));
TREE_THIS_VOLATILE (*tp) = TREE_THIS_VOLATILE (old);
TREE_THIS_NOTRAP (*tp) = TREE_THIS_NOTRAP (old);
}
TREE_NO_WARNING (*tp) = TREE_NO_WARNING (old);
*walk_subtrees = 0;
return NULL;
} }
/* Here is the "usual case". Copy this tree node, and then /* Here is the "usual case". Copy this tree node, and then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment