diff options
| author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-03-18 19:23:45 +0000 |
|---|---|---|
| committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-03-18 19:23:45 +0000 |
| commit | b6e16ea006a262c77ed44afc72b94a9b7c9cf440 (patch) | |
| tree | a632d8849ea69fef6f7564e76ae57b4647512897 /clang/test/Sema/builtin-object-size.c | |
| parent | 8627178d4680af6a49459659a71f690dfefc2783 (diff) | |
| download | bcm5719-llvm-b6e16ea006a262c77ed44afc72b94a9b7c9cf440.tar.gz bcm5719-llvm-b6e16ea006a262c77ed44afc72b94a9b7c9cf440.zip | |
[Sema] Add some compile time _FORTIFY_SOURCE diagnostics
These diagnose overflowing calls to subset of fortifiable functions. Some
functions, like sprintf or strcpy aren't supported right not, but we should
probably support these in the future. We previously supported this kind of
functionality with -Wbuiltin-memcpy-chk-size, but that diagnostic doesn't work
with _FORTIFY implementations that use wrapper functions. Also unlike that
diagnostic, we emit these warnings regardless of whether _FORTIFY_SOURCE is
actually enabled, which is nice for programs that don't enable the runtime
checks.
Why not just use diagnose_if, like Bionic does? We can get better diagnostics in
the compiler (i.e. mention the sizes), and we have the potential to diagnose
sprintf and strcpy which is impossible with diagnose_if (at least, in languages
that don't support C++14 constexpr). This approach also saves standard libraries
from having to add diagnose_if.
rdar://48006655
Differential revision: https://reviews.llvm.org/D58797
llvm-svn: 356397
Diffstat (limited to 'clang/test/Sema/builtin-object-size.c')
| -rw-r--r-- | clang/test/Sema/builtin-object-size.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/test/Sema/builtin-object-size.c b/clang/test/Sema/builtin-object-size.c index ff8707493ab..fa66d2e9c0c 100644 --- a/clang/test/Sema/builtin-object-size.c +++ b/clang/test/Sema/builtin-object-size.c @@ -30,7 +30,7 @@ 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); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow; destination buffer has size 11, but size argument is 42}} + __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'vsnprintf' will always overflow; destination buffer has size 11, but size argument is 42}} } // rdar://18334276 @@ -57,7 +57,7 @@ void f6(void) char b[5]; char buf[10]; __builtin___memccpy_chk (buf, b, '\0', sizeof(b), OBJECT_SIZE_BUILTIN (buf, 0)); - __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), OBJECT_SIZE_BUILTIN (b, 0)); // expected-warning {{'__builtin___memccpy_chk' will always overflow; destination buffer has size 5, but size argument is 10}} + __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), OBJECT_SIZE_BUILTIN (b, 0)); // expected-warning {{'memccpy' will always overflow; destination buffer has size 5, but size argument is 10}} } int pr28314(void) { |

