This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR38826 and PR38477


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;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]