[cfe-commits] r145445 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/array-bounds.cpp

Matt Beaumont-Gay matthewbg at google.com
Tue Nov 29 14:43:53 PST 2011


Author: matthewbg
Date: Tue Nov 29 16:43:53 2011
New Revision: 145445

URL: http://llvm.org/viewvc/llvm-project?rev=145445&view=rev
Log:
Suppress -Warray-bounds for classes (not just structs) where the last field is
a 1-length character array.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/array-bounds.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=145445&r1=145444&r2=145445&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Nov 29 16:43:53 2011
@@ -4202,8 +4202,11 @@
     return false;
 
   const RecordDecl *RD = dyn_cast<RecordDecl>(FD->getDeclContext());
-  if (!RD || !RD->isStruct())
-    return false;
+  if (!RD) return false;
+  if (RD->isUnion()) return false;
+  if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
+    if (!CRD->isStandardLayout()) return false;
+  }
 
   // See if this is the last field decl in the record.
   const Decl *D = FD;

Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=145445&r1=145444&r2=145445&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Tue Nov 29 16:43:53 2011
@@ -190,10 +190,19 @@
     int x;
     char c2[1];
   };
-  
-  char bar(struct foo *F) {
-    return F->c1[3]; // expected-warning {{array index 3 is past the end of the array (which contains 1 element)}}
-    return F->c2[3]; // no warning, foo could have tail padding allocated.
+
+  class baz {
+   public:
+    char c1[1]; // expected-note {{declared here}}
+    int x;
+    char c2[1];
+  };
+
+  char bar(struct foo *F, baz *B) {
+    return F->c1[3] + // expected-warning {{array index 3 is past the end of the array (which contains 1 element)}}
+           F->c2[3] + // no warning, foo could have tail padding allocated.
+           B->c1[3] + // expected-warning {{array index 3 is past the end of the array (which contains 1 element)}}
+           B->c2[3]; // no warning, baz could have tail padding allocated.
   }
 }
 





More information about the cfe-commits mailing list