diff options
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp | 24 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-memset-bad-sizeof.cpp | 24 | 
2 files changed, 12 insertions, 36 deletions
| diff --git a/clang/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp b/clang/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp deleted file mode 100644 index f76f4973930..00000000000 --- a/clang/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// RUN: cp %s %t -// RUN: not %clang_cc1 -fixit -Werror -x c++ -std=c++98 %t -// RUN: %clang_cc1 -fsyntax-only -Werror -x c++ -std=c++98 %t -// RUN: cp %s %t -// RUN: not %clang_cc1 -DUSE_BUILTINS -fixit -Werror -x c++ -std=c++98 %t -// RUN: %clang_cc1 -DUSE_BUILTINS -fsyntax-only -Werror -x c++ -std=c++98 %t - -extern "C" void *memcpy(void *s1, const void *s2, unsigned n); - -#ifdef USE_BUILTINS -# define BUILTIN(f) __builtin_ ## f -#else -# define BUILTIN(f) f -#endif - -#define memcpy BUILTIN(memcpy) - -int testFixits(int *to, int *from) { -  memcpy(to, from, sizeof(to)); // \ -         // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination; did you mean to dereference it?}} -  memcpy(0, &from, sizeof(&from)); // \ -         // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source; did you mean to remove the addressof?}} -  return 0; -} diff --git a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp index e0d28da3d58..e388634e884 100644 --- a/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp +++ b/clang/test/SemaCXX/warn-memset-bad-sizeof.cpp @@ -35,27 +35,27 @@ void f(Mat m, const Foo& const_foo, char *buffer) {    /* Should warn */    memset(&s, 0, sizeof(&s));  // \ -      // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} +      // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}    memset(ps, 0, sizeof(ps));  // \ -      // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} +      // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}    memset(ps2, 0, sizeof(ps2));  // \ -      // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} +      // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'PS' (aka 'S *')}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}    memset(ps2, 0, sizeof(typeof(ps2)));  // \        // expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}}    memset(ps2, 0, sizeof(PS));  // \        // expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}}    memset(heap_buffer, 0, sizeof(heap_buffer));  // \ -      // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}} +      // expected-warning {{'memset' call operates on objects of type 'char' while the size is based on a different type 'char *'}} expected-note{{did you mean to provide an explicit length?}}    memcpy(&s, 0, sizeof(&s));  // \ -      // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination}} +      // expected-warning {{'memcpy' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}    memcpy(0, &s, sizeof(&s));  // \ -      // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source}} +      // expected-warning {{'memcpy' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}    memmove(ps, 0, sizeof(ps));  // \ -      // expected-warning {{argument to 'sizeof' in 'memmove' call is the same expression as the destination}} +      // expected-warning {{'memmove' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}    memcmp(ps, 0, sizeof(ps));  // \ -      // expected-warning {{argument to 'sizeof' in 'memcmp' call is the same expression as the destination}} +      // expected-warning {{'memcmp' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}    /* Shouldn't warn */    memset((void*)&s, 0, sizeof(&s)); @@ -132,14 +132,14 @@ void strcpy_and_friends() {    const char* BAR = "<- this, too";    strncmp(FOO, BAR, sizeof(FOO)); // \ -      // expected-warning {{argument to 'sizeof' in 'strncmp' call is the same expression as the destination}} +      // expected-warning {{'strncmp' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}    strncasecmp(FOO, BAR, sizeof(FOO));  // \ -      // expected-warning {{argument to 'sizeof' in 'strncasecmp' call is the same expression as the destination}} +      // expected-warning {{'strncasecmp' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}    char buff[80];    strncpy(buff, BAR, sizeof(BAR)); // \ -      // expected-warning {{argument to 'sizeof' in 'strncpy' call is the same expression as the source}} +      // expected-warning {{'strncpy' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}    strndup(FOO, sizeof(FOO)); // \ -      // expected-warning {{argument to 'sizeof' in 'strndup' call is the same expression as the source}} +      // expected-warning {{'strndup' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}  } | 

