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 PR70143


The following fixes PR70143.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2016-03-09  Richard Biener  <rguenther@suse.de>

	c-family/
	PR c/70143
	* c-common.c (strict_aliasing_warning): Add back
	alias_sets_conflict_p check.

	* gcc.dg/Wstrict-aliasing-bogus-upcast.c: New testcase.
	* gcc.dg/Wstrict-aliasing-struct-with-char-member.c: Likewise.
	* gcc.dg/Wstrict-aliasing-struct-member.c: Remove again.

Index: gcc/c-family/c-common.c
===================================================================
*** gcc/c-family/c-common.c	(revision 234025)
--- gcc/c-family/c-common.c	(working copy)
*************** strict_aliasing_warning (tree otype, tre
*** 1568,1574 ****
            alias_set_type set2 = get_alias_set (TREE_TYPE (type));
  
            if (set1 != set2 && set2 != 0
! 	      && (set1 == 0 || !alias_set_subset_of (set2, set1)))
  	    {
  	      warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
  		       "pointer will break strict-aliasing rules");
--- 1568,1576 ----
            alias_set_type set2 = get_alias_set (TREE_TYPE (type));
  
            if (set1 != set2 && set2 != 0
! 	      && (set1 == 0
! 		  || (!alias_set_subset_of (set2, set1)
! 		      && !alias_sets_conflict_p (set1, set2))))
  	    {
  	      warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
  		       "pointer will break strict-aliasing rules");
Index: gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-upcast.c
===================================================================
*** gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-upcast.c	(revision 0)
--- gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-upcast.c	(working copy)
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -Wall" } */
+ 
+ struct a {
+     int i;
+ };
+ struct b {
+     struct a a;
+     int j;
+ };
+ int main(void)
+ {
+   static struct b b;
+   struct a *ap=(struct a *)&b;
+   return ((struct b *)&ap->i)->j; /* { dg-bogus "will break strict-aliasing" } */
+ }
+ 
Index: gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-with-char-member.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-with-char-member.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-with-char-member.c	(working copy)
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct a {
+    int i;
+    char c;
+};
+struct b {
+    float f;
+    float g;
+};
+int main(void)
+{
+  static struct b b;
+  return ((struct a *)&b)->i; /* { dg-warning "will break strict-aliasing" } */
+}


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