diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-03-29 19:53:41 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-03-29 19:53:41 +0000 |
commit | 0cf9ba250e8ec340f5dc0fda616024e0a59f2f1d (patch) | |
tree | cd472c00c87a1b2c733d4314ef904650d90694b2 /test/Sema | |
parent | f29e4266bd8a20e46da5f8f422742ad02e5108b8 (diff) |
[Sema] Avoid sending a dependent expression to the constant evaluator.
Fixes llvm.org/PR41286
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/warn-fortify-source.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/Sema/warn-fortify-source.c b/test/Sema/warn-fortify-source.c index 3cd939a2d9..d9c21c0842 100644 --- a/test/Sema/warn-fortify-source.c +++ b/test/Sema/warn-fortify-source.c @@ -1,9 +1,16 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE +// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS typedef unsigned long size_t; +#ifdef __cplusplus +extern "C" { +#endif + #if defined(USE_PASS_OBJECT_SIZE) void *memcpy(void *dst, const void *src, size_t c); static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp"); @@ -16,6 +23,10 @@ static void *memcpy(void *const dst __attribute__((pass_object_size(1))), const void *memcpy(void *dst, const void *src, size_t c); #endif +#ifdef __cplusplus +} +#endif + void call_memcpy() { char dst[10]; char src[20]; @@ -84,3 +95,25 @@ void call_vsnprintf() { __builtin_vsnprintf(buf, 10, "merp", list); __builtin_vsnprintf(buf, 11, "merp", list); // expected-warning {{'vsnprintf' size argument is too large; destination buffer has size 10, but size argument is 11}} } + +#ifdef __cplusplus +template <class> struct S { + void mf() const { + __builtin_memset(const_cast<char *>(mv), 0, 0); + } + + char mv[10]; +}; + +template <int A, int B> +void call_memcpy_dep() { + char bufferA[A]; + char bufferB[B]; + memcpy(bufferA, bufferB, 10); // expected-warning{{'memcpy' will always overflow; destination buffer has size 9, but size argument is 10}} +} + +void call_call_memcpy() { + call_memcpy_dep<10, 9>(); + call_memcpy_dep<9, 10>(); // expected-note {{in instantiation of function template specialization 'call_memcpy_dep<9, 10>' requested here}} +} +#endif |