[PATCH][alias-improvements] Add proper PTA constraints for passed-by reference result decls

Andrew Thomas Pinski pinskia@gmail.com
Sun Jan 4 17:50:00 GMT 2009



On Jan 4, 2009, at 3:55 AM, Richard Guenther <rguenther@suse.de> wrote:

>
> This fixes the extra libstdc++ fail introduced by the previous patch.
> We fail to add constraints for a result decl that is passed by
> invisible reference.  Then for
>
> A foo ()
> {
>  A &ptr = <result>;
>
> we conclude ptr points to nothing (or rather we eliminate it as a
> non-pointer variable).  The fix is to add proper constraints for
> <result>.  The following patch adds a constraint from nonlocal,
> like we do for the static chain - but in theory both the result
> decl and the outer frame object should be unaliased, no?  Well,
> better play safe for now.

Yes for the return value but no for the ststic chain, because the user  
could still pass a pointer value of one of the variables in the chain  
to the nested function.
Thanks,
Andrew Pinski

>
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
> the branch.
>
> Richard.
>
> 2009-01-04  Richard Guenther  <rguenther@suse.de>
>
>    * tree-ssa-structalias.c (intra_create_variable_infos): Add
>    constraints for a result decl that is passed by hidden reference.
>    * tree-ssa-alias.c (may_point_to_same_object): Make two identical
>    pointer always conflict.
>
> Index: gcc/tree-ssa-alias.c
> ===================================================================
> *** gcc/tree-ssa-alias.c    (revision 143037)
> --- gcc/tree-ssa-alias.c    (working copy)
> *************** may_point_to_same_object (tree ptr1, tre
> *** 153,158 ****
> --- 153,164 ----
>    gcc_assert (TREE_CODE (ptr1) == SSA_NAME
>            && TREE_CODE (ptr2) == SSA_NAME);
>
> +   /* We may end up with two empty points-to solutions for two same  
> pointers.
> +      In this case we still want to say both pointers alias, so  
> shortcut
> +      that here.  */
> +   if (ptr1 == ptr2)
> +     return true;
> +
>    /* If we do not have useful points-to information for either  
> pointer
>       we cannot disambiguate anything else.  */
>    pi1 = SSA_NAME_PTR_INFO (ptr1);
> Index: gcc/tree-ssa-structalias.c
> ===================================================================
> *** gcc/tree-ssa-structalias.c    (revision 143037)
> --- gcc/tree-ssa-structalias.c    (working copy)
> *************** intra_create_variable_infos (void)
> *** 4596,4601 ****
> --- 4596,4615 ----
>      }
>      }
>
> +   /* ???  Both a passed by reference result object and the object  
> pointed
> +      to by the static chain should be non-aliased by any other  
> pointers.
> +      So we may want to assign them a heap variable.  */
> +
> +   /* Add a constraint for a result decl that is passed by  
> reference.  */
> +   if (DECL_RESULT (cfun->decl)
> +       && DECL_BY_REFERENCE (DECL_RESULT (cfun->decl)))
> +     {
> +       varinfo_t p, result_vi = get_vi_for_tree (DECL_RESULT (cfun- 
> >decl));
> +
> +       for (p = result_vi; p; p = p->next)
> +    make_constraint_from (p, nonlocal_id);
> +     }
> +
>    /* Add a constraint for the incoming static chain parameter.  */
>    if (cfun->static_chain_decl != NULL_TREE)
>      {



More information about the Gcc-patches mailing list