diff options
Diffstat (limited to 'test/Sema/builtins.c')
-rw-r--r-- | test/Sema/builtins.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 7647100bc270b..0e2925e0748da 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wno-string-plus-int -triple=i686-apple-darwin9 +// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -Wstrlcpy-strlcat-size -Wno-string-plus-int -triple=i686-apple-darwin9 // This test needs to set the target because it uses __builtin_ia32_vec_ext_v4si int test1(float a, int b) { @@ -66,6 +66,11 @@ void test9_3(volatile int* ptr, int val) { __sync_fetch_and_add_4(ptr, val); } +void test9_4(volatile int* ptr, int val) { + // expected-warning@+1 {{the semantics of this intrinsic changed with GCC version 4.4 - the newer semantics are provided here}} + __sync_fetch_and_nand(ptr, val); +} + // rdar://7236819 void test10(void) __attribute__((noreturn)); @@ -184,12 +189,12 @@ void test18() { void *ptr; ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src), sizeof(dst)); - result = __builtin___strlcpy_chk(dst, src, sizeof(src), sizeof(dst)); - result = __builtin___strlcat_chk(dst, src, sizeof(src), sizeof(dst)); + result = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst)); + result = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst)); ptr = __builtin___memccpy_chk(dst, src, '\037', sizeof(src)); // expected-error {{too few arguments to function call}} - ptr = __builtin___strlcpy_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}} - ptr = __builtin___strlcat_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}} + ptr = __builtin___strlcpy_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}} + ptr = __builtin___strlcat_chk(dst, src, sizeof(dst), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}} } void no_ms_builtins() { @@ -202,3 +207,44 @@ void unavailable() { __builtin_operator_new(0); // expected-error {{'__builtin_operator_new' is only available in C++}} __builtin_operator_delete(0); // expected-error {{'__builtin_operator_delete' is only available in C++}} } + +// rdar://18259539 +size_t strlcpy(char * restrict dst, const char * restrict src, size_t size); +size_t strlcat(char * restrict dst, const char * restrict src, size_t size); + +void Test19(void) +{ + static char b[40]; + static char buf[20]; + + strlcpy(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination}} \\ + // expected-note {{change size argument to be the size of the destination}} + __builtin___strlcpy_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcpy_chk' call appears to be size of the source; expected the size of the destination}} \ + // expected-note {{change size argument to be the size of the destination}} \ + // expected-warning {{'__builtin___strlcpy_chk' will always overflow destination buffer}} + + strlcat(buf, b, sizeof(b)); // expected-warning {{size argument in 'strlcat' call appears to be size of the source; expected the size of the destination}} \ + // expected-note {{change size argument to be the size of the destination}} + + __builtin___strlcat_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcat_chk' call appears to be size of the source; expected the size of the destination}} \ + // expected-note {{change size argument to be the size of the destination}} \ + // expected-warning {{'__builtin___strlcat_chk' will always overflow destination buffer}} +} + +// rdar://11076881 +char * Test20(char *p, const char *in, unsigned n) +{ + static char buf[10]; + + __builtin___memcpy_chk (&buf[6], in, 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + + __builtin___memcpy_chk (p, "abcde", n, __builtin_object_size (p, 0)); + + __builtin___memcpy_chk (&buf[5], "abcde", 5, __builtin_object_size (&buf[5], 0)); + + __builtin___memcpy_chk (&buf[5], "abcde", n, __builtin_object_size (&buf[5], 0)); + + __builtin___memcpy_chk (&buf[6], "abcde", 5, __builtin_object_size (&buf[6], 0)); // expected-warning {{'__builtin___memcpy_chk' will always overflow destination buffer}} + + return buf; +} |