This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: valid_gimple_expression_p claims validity of invalid gimple
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: "Daniel Berlin" <dberlin at dberlin dot org>
- Cc: GCC <gcc at gcc dot gnu dot org>
- Date: Sat, 14 Jul 2007 10:05:38 +0200
- Subject: Re: valid_gimple_expression_p claims validity of invalid gimple
- References: <4aca3dc20707131915j11db2b9if6ac17d9da9d4b35@mail.gmail.com>
> First is_gimple_min_invariant in try_to_simplify where it chooses
> DECL_INITIAL should be valid_gimple_expression_p instead.
That's a known problem, see tree-ssa-ccp.c:
/* The regular is_gimple_min_invariant does a shallow test of the object.
It assumes that full gimplification has happened, or will happen on the
object. For a value coming from DECL_INITIAL, this is not true, so we
have to be more strict ourselves. */
static bool
ccp_decl_initial_min_invariant (tree t)
{
if (!is_gimple_min_invariant (t))
return false;
if (TREE_CODE (t) == ADDR_EXPR)
{
/* Inline and unroll is_gimple_addressable. */
while (1)
{
t = TREE_OPERAND (t, 0);
if (is_gimple_id (t))
return true;
if (!handled_component_p (t))
return false;
}
}
return true;
}
static tree
get_symbol_constant_value (tree sym)
{
if (TREE_STATIC (sym)
&& TREE_READONLY (sym)
&& !MTAG_P (sym))
{
tree val = DECL_INITIAL (sym);
if (val
&& ccp_decl_initial_min_invariant (val))
return val;
}
return NULL_TREE;
}
You could turn ccp_decl_initial_min_invariant into a global predicate and
invoke it from tree-ssa-sccvn.c on the DECL_INITIAL.
> However, even if i fix this, the testcase still fails because
> valid_gimple_expression says something that is clearly invalid is
> valid.
>
> (gdb) p valid_gimple_expression_p ($2)
> $3 = 1 '\001'
> (gdb) p debug_generic_stmt ($2)
> &((struct RegisterLayout *) (char *) &SimulatedRegisters)->intmask;
>
> This is not valid gimple by a longshot :)
Almost. :-) The function was extracted unchanged from set_rhs but it looks
like it needs to be beefed up a bit if it is to become of general use.
> If you fix this part, i'll happily fix the bug report with the first part.
The problem is again the ADDR_EXPR case, because it drags lvalues into the
game. This would be something like:
Index: tree-ssa-propagate.c
===================================================================
--- tree-ssa-propagate.c (revision 126545)
+++ tree-ssa-propagate.c (working copy)
@@ -606,10 +606,21 @@ valid_gimple_expression_p (tree expr)
switch (code)
{
case ADDR_EXPR:
- if (TREE_CODE (TREE_OPERAND (expr, 0)) == ARRAY_REF
- && !is_gimple_val (TREE_OPERAND (TREE_OPERAND (expr, 0), 1)))
- return false;
- break;
+ {
+ tree t = TREE_OPERAND (expr, 0);
+ while (handled_component_p (t))
+ {
+ /* ??? More checks needed, see the GIMPLE verifier. */
+ if ((TREE_CODE (t) == ARRAY_REF
+ || TREE_CODE (t) == ARRAY_RANGE_REF)
+ && !is_gimple_val (TREE_OPERAND (t, 1)))
+ return false;
+ t = TREE_OPERAND (t, 0);
+ }
+ if (!is_gimple_addressable (t))
+ return false;
+ break;
+ }
case TRUTH_NOT_EXPR:
if (!is_gimple_val (TREE_OPERAND (expr, 0)))
--
Eric Botcazou