diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2011-06-16 02:00:04 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2011-06-16 02:00:04 +0000 |
| commit | a05e09ba486a4fa54d2fdfb48bea4d7b290f00d7 (patch) | |
| tree | 3eae765f39911b3a1f2fd337e51eec72a674eea0 /clang/test/SemaCXX/warn-memset-bad-sizeof.cpp | |
| parent | 575d0163bb1e0005698ad92dc97b7c290eca1bf1 (diff) | |
| download | bcm5719-llvm-a05e09ba486a4fa54d2fdfb48bea4d7b290f00d7.tar.gz bcm5719-llvm-a05e09ba486a4fa54d2fdfb48bea4d7b290f00d7.zip | |
Skip both character pointers and void pointers when diagnosing bad
argument types for mem{set,cpy,move}. Character pointers, much like void
pointers, often point to generic "memory", so trying to check whether
they match the type of the argument to 'sizeof' (or other checks) is
unproductive and often results in false positives.
Nico, please review; does this miss any of the bugs you were trying to
find with this warning? The array test case you had should be caught by
the array-specific sizeof warning I think.
llvm-svn: 133136
Diffstat (limited to 'clang/test/SemaCXX/warn-memset-bad-sizeof.cpp')
| -rw-r--r-- | clang/test/SemaCXX/warn-memset-bad-sizeof.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp index 9221590bd9e..167f05f3daf 100644 --- a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp +++ b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp @@ -23,10 +23,11 @@ inline Dest bit_cast(const Source& source) { } // http://www.lysator.liu.se/c/c-faq/c-2.html#2-6 -void f(char fake_array[8], Mat m, const Foo& const_foo) { +void f(Mat m, const Foo& const_foo) { S s; S* ps = &s; PS ps2 = &s; + char c = 42; char arr[5]; char* parr[5]; Foo foo; @@ -42,8 +43,6 @@ void f(char fake_array[8], Mat m, const Foo& const_foo) { // expected-warning {{the argument to sizeof is pointer type 'typeof (ps2)' (aka 'S *'), expected 'S' to match first argument to 'memset'}} memset(ps2, 0, sizeof(PS)); // \ // expected-warning {{the argument to sizeof is pointer type 'PS' (aka 'S *'), expected 'S' to match first argument to 'memset'}} - memset(fake_array, 0, sizeof(fake_array)); // \ - // expected-warning {{the argument to sizeof is pointer type 'char *', expected 'char' to match first argument to 'memset'}} memcpy(&s, 0, sizeof(&s)); // \ // expected-warning {{the argument to sizeof is pointer type 'S *', expected 'S' to match first argument to 'memcpy'}} @@ -69,6 +68,8 @@ void f(char fake_array[8], Mat m, const Foo& const_foo) { memcpy(&foo, &const_foo, sizeof(Foo)); memcpy((void*)&s, 0, sizeof(&s)); memcpy(0, (void*)&s, sizeof(&s)); + memcpy(&parr[3], &c, sizeof(&c)); + memcpy((char*)&parr[3], &c, sizeof(&c)); CFooRef cfoo = foo; memcpy(&foo, &cfoo, sizeof(Foo)); |

