r232900 - -Wdynamic-class-memaccess: Also warn about array types.
Nico Weber
nicolasweber at gmx.de
Sat Mar 21 10:56:44 PDT 2015
Author: nico
Date: Sat Mar 21 12:56:44 2015
New Revision: 232900
URL: http://llvm.org/viewvc/llvm-project?rev=232900&view=rev
Log:
-Wdynamic-class-memaccess: Also warn about array types.
It looks like not warning on this was an oversight in the original
implementation of this warning.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp
cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=232900&r1=232899&r2=232900&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Mar 21 12:56:44 2015
@@ -4788,6 +4788,8 @@ void Sema::CheckMemaccessArguments(const
break;
}
}
+ } else if (DestTy->isArrayType()) {
+ PointeeTy = DestTy;
}
if (PointeeTy == QualType())
Modified: cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp?rev=232900&r1=232899&r2=232900&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-bad-memaccess.cpp Sat Mar 21 12:56:44 2015
@@ -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}}
Modified: cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp?rev=232900&r1=232899&r2=232900&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp Sat Mar 21 12:56:44 2015
@@ -95,9 +95,11 @@ void f(Mat m, const Foo& const_foo, char
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));
More information about the cfe-commits
mailing list