-Wdynamic-class-memaccess: Also warn about array types.
authorNico Weber <nicolasweber@gmx.de>
Sat, 21 Mar 2015 17:56:44 +0000 (17:56 +0000)
committerNico Weber <nicolasweber@gmx.de>
Sat, 21 Mar 2015 17:56:44 +0000 (17:56 +0000)
It looks like not warning on this was an oversight in the original
implementation of this warning.

llvm-svn: 232900

clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/warn-bad-memaccess.cpp
clang/test/SemaCXX/warn-memset-bad-sizeof.cpp

index d684928..abcccba 100644 (file)
@@ -4788,6 +4788,8 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
           break;
         }
       }
+    } else if (DestTy->isArrayType()) {
+      PointeeTy = DestTy;
     }
 
     if (PointeeTy == QualType())
index e86610a..67cde10 100644 (file)
@@ -21,7 +21,7 @@ public:
   void foo() {}
 } c1;
 
-struct X1 { virtual void f(); } x1;
+struct X1 { virtual void f(); } x1, x1arr[2];
 struct X2 : virtual S1 {} x2;
 
 struct ContainsDynamic { X1 dynamic; } contains_dynamic;
@@ -33,6 +33,10 @@ void test_warn() {
   memset(&x1, 0, sizeof x1); // \
       // expected-warning {{destination for this 'memset' call is a pointer to dynamic class}} \
       // expected-note {{explicitly cast the pointer to silence this warning}}
+  memset(x1arr, 0, sizeof x1arr); // \
+      // expected-warning {{destination for this 'memset' call is a pointer to dynamic class}} \
+      // expected-note {{explicitly cast the pointer to silence this warning}}
+  memset((void*)x1arr, 0, sizeof x1arr);
   memset(&x2, 0, sizeof x2); // \
       // expected-warning {{destination for this 'memset' call is a pointer to dynamic class}} \
       // expected-note {{explicitly cast the pointer to silence this warning}}
index e388634..cca15fc 100644 (file)
@@ -95,9 +95,11 @@ void f(Mat m, const Foo& const_foo, char *buffer) {
 
   int iarr[14];
   memset(&iarr[0], 0, sizeof iarr);
+  memset(iarr, 0, sizeof iarr);
 
   int* iparr[14];
   memset(&iparr[0], 0, sizeof iparr);
+  memset(iparr, 0, sizeof iparr);
 
   memset(m, 0, sizeof(Mat));