[PATCH] Fix PR38826 and PR38477

Daniel Berlin dberlin@dberlin.org
Wed Jan 14 06:32:00 GMT 2009


So, after talking with some others who work on points-to algorithms,
we've all agreed the proper solution to this problem is to mark all
nodes in a structure as indirect when the structure is address taken
(IE set graph->direct_nodes[n] false for each node). The notion of an
indirect node is that it can be referenced without using it's
syntactic name, which is exactly what is happening here.
This only affects the offline optimization portion.
It will cause slightly less offline optimization, but that is fixable
in other ways.

If you'd like to disable field-sensitivity, i'd rather see us do that
as a separate patch, since the bug you are fixing would still remain
if you go this route.
:)

On Tue, Jan 13, 2009 at 9:53 AM, Richard Guenther <rguenther@suse.de> wrote:
>
> This fixes the underlying PTA problem (PR38826) that causes the
> false positive alias warnings to be emitted in PR38477.  The patch
> disables field-sensitive points-to analysis in non-IPA mode where
> we rely on correct points-to solutions in the face of transitive
> closures with call-clobbering.
>
> This should be safe for 4.4.
>
> Bootstrap and regtest on x86_64-unknown-linux-gnu in progress.  Danny,
> do you think this is ok?  (we already disable field-sensitive analysis
> for -O1 now)
>
> Thanks,
> Richard.
>
> 2009-01-13  Richard Guenther  <rguenther@suse.de>
>
>        PR tree-optimization/38826
>        PR middle-end/38477
>        * tree-ssa-structalias.c (emit_alias_warning): Emit the pointer
>        initialization notes only if we actually emitted a warning.
>        (init_alias_vars): Possibly enable field-sensitive analysis only
>        for IPA points-to analysis.
>
>        * gcc.dg/Wstrict-aliasing-bogus-pta-1.c: New testcase.
>
> Index: gcc/tree-ssa-structalias.c
> ===================================================================
> --- gcc/tree-ssa-structalias.c  (revision 143333)
> +++ gcc/tree-ssa-structalias.c  (working copy)
> @@ -4735,7 +4735,7 @@ emit_alias_warning (tree ptr)
>  {
>   gimple use;
>   imm_use_iterator ui;
> -  unsigned warned = 0;
> +  bool warned = false;
>
>   FOR_EACH_IMM_USE_STMT (use, ui, ptr)
>     {
> @@ -4773,13 +4773,12 @@ emit_alias_warning (tree ptr)
>          && !TREE_NO_WARNING (deref))
>        {
>          TREE_NO_WARNING (deref) = 1;
> -         warning_at (gimple_location (use), OPT_Wstrict_aliasing,
> -                     "dereferencing pointer %qD does break strict-aliasing "
> -                     "rules", SSA_NAME_VAR (ptr));
> -         ++warned;
> +         warned |= warning_at (gimple_location (use), OPT_Wstrict_aliasing,
> +                               "dereferencing pointer %qD does break "
> +                               "strict-aliasing rules", SSA_NAME_VAR (ptr));
>        }
>     }
> -  if (warned > 0)
> +  if (warned)
>     {
>       bitmap visited = BITMAP_ALLOC (NULL);
>       emit_pointer_definition (ptr, visited);
> @@ -5255,7 +5254,8 @@ init_base_vars (void)
>  static void
>  init_alias_vars (void)
>  {
> -  use_field_sensitive = (MAX_FIELDS_FOR_FIELD_SENSITIVE > 1);
> +  use_field_sensitive = (in_ipa_mode
> +                        && (MAX_FIELDS_FOR_FIELD_SENSITIVE > 1));
>
>   bitmap_obstack_initialize (&pta_obstack);
>   bitmap_obstack_initialize (&oldpta_obstack);
> Index: gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c
> ===================================================================
> *** gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c (revision 0)
> --- gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-pta-1.c (revision 0)
> ***************
> *** 0 ****
> --- 1,19 ----
> + /* { dg-do compile } */
> + /* { dg-options "-O2 -Wall" } */
> +
> + struct S { int *p; int *q; };
> +
> + void foo (struct S *);
> +
> + int bar (int b)
> + {
> +   struct S s;
> +   int *p;
> +   float f;
> +   foo (&s);
> +   if (b)
> +     p = s.q;
> +   else
> +     p = (int *)&f;
> +   return *p;
> + }
>



More information about the Gcc-patches mailing list