diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Sema/builtin-object-size.c | 2 | ||||
-rw-r--r-- | clang/test/Sema/builtins.c | 25 |
2 files changed, 24 insertions, 3 deletions
diff --git a/clang/test/Sema/builtin-object-size.c b/clang/test/Sema/builtin-object-size.c index 0abc27ba187..db4832e347a 100644 --- a/clang/test/Sema/builtin-object-size.c +++ b/clang/test/Sema/builtin-object-size.c @@ -23,6 +23,6 @@ int f3() { // rdar://6252231 - cannot call vsnprintf with va_list on x86_64 void f4(const char *fmt, ...) { __builtin_va_list args; - __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); + __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}} } diff --git a/clang/test/Sema/builtins.c b/clang/test/Sema/builtins.c index 8e3a60ab067..f8df2f85cf6 100644 --- a/clang/test/Sema/builtins.c +++ b/clang/test/Sema/builtins.c @@ -215,10 +215,31 @@ void Test19(void) 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-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-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; } |