Extend memset/memcpy/memmove checking to include memcmp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136950 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/warn-memset-bad-sizeof.cpp b/test/SemaCXX/warn-memset-bad-sizeof.cpp
index 90ac504..f4876ab 100644
--- a/test/SemaCXX/warn-memset-bad-sizeof.cpp
+++ b/test/SemaCXX/warn-memset-bad-sizeof.cpp
@@ -3,6 +3,7 @@
extern "C" void *memset(void *, int, unsigned);
extern "C" void *memmove(void *s1, const void *s2, unsigned n);
extern "C" void *memcpy(void *s1, const void *s2, unsigned n);
+extern "C" void *memcmp(void *s1, const void *s2, unsigned n);
struct S {int a, b, c, d;};
typedef S* PS;
@@ -51,6 +52,11 @@
memcpy(0, &s, sizeof(&s)); // \
// expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source}}
+ memmove(ps, 0, sizeof(ps)); // \
+ // expected-warning {{argument to 'sizeof' in 'memmove' call is the same expression as the destination}}
+ memcmp(ps, 0, sizeof(ps)); // \
+ // expected-warning {{argument to 'sizeof' in 'memcmp' call is the same expression as the destination}}
+
/* Shouldn't warn */
memset((void*)&s, 0, sizeof(&s));
memset(&s, 0, sizeof(s));
@@ -99,3 +105,10 @@
memcpy(&foo, &arr, sizeof(Foo));
memcpy(&arr, &foo, sizeof(Foo));
}
+
+namespace ns {
+void memset(void* s, char c, int n);
+void f(int* i) {
+ memset(i, 0, sizeof(i));
+}
+}