On Thu, Dec 8, 2011 at 2:02 PM, Han Shen(沈涵) <[email protected]> wrote:
> + FOR_EACH_REFERENCED_VAR(cfun, var, rvi)
> + if (!is_global_var(var) && TREE_ADDRESSABLE(var))
> + ++gen_stack_protect_signal;
> +
> + /* Examine local variable declaration. */
> + if (!gen_stack_protect_signal)
> + FOR_EACH_LOCAL_DECL (cfun, i, var)
> + if (TREE_CODE(var) == VAR_DECL && !is_global_var(var)) {
> + tree var_type = TREE_TYPE(var);
> + gen_stack_protect_signal += (TREE_CODE(var_type) == ARRAY_TYPE) ||
> + (RECORD_OR_UNION_TYPE_P(var_type) &&
> + record_or_union_type_has_array(var_type));
> + }
How about merging the above two loops and break if you set
gen_stack_protect_signal? Also I think it is better if you only look
at referenced variables rather than just all local decls.
Something like:
FOR_EACH_REFERENCED_VAR(cfun, var, rvi)
if (!is_global_var(var))
{
tree var_type = TREE_TYPE(var);
if (TREE_ADDRESSABLE(var))
{
gen_stack_protect_signal = true;
break;
}
if (TREE_CODE (var) == VAR_DECL
&& (TREE_CODE (var_type) == ARRAY_TYPE
|| (RECORD_OR_UNION_TYPE_P (var_type)
&& record_or_union_type_has_array (var_type))))
{
gen_stack_protect_signal = true;
break;
}
}
Also I think you should use const_tree in some places like:
>static int record_or_union_type_has_array(tree tree_type)
static int
record_or_union_type_has_array (const_tree tree_type)
Thanks,
Andrew Pinski