r357304 - [Sema] Avoid sending a dependent expression to the constant evaluator.
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 29 12:53:42 PDT 2019
Author: epilk
Date: Fri Mar 29 12:53:41 2019
New Revision: 357304
URL: http://llvm.org/viewvc/llvm-project?rev=357304&view=rev
Log:
[Sema] Avoid sending a dependent expression to the constant evaluator.
Fixes llvm.org/PR41286
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/warn-fortify-source.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=357304&r1=357303&r2=357304&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar 29 12:53:41 2019
@@ -307,6 +307,9 @@ void Sema::checkFortifiedBuiltinMemoryFu
// - Analyze the format string of sprintf to see how much of buffer is used.
// - Evaluate strlen of strcpy arguments, use as object size.
+ if (TheCall->isValueDependent() || TheCall->isTypeDependent())
+ return;
+
unsigned BuiltinID = FD->getBuiltinID(/*ConsiderWrappers=*/true);
if (!BuiltinID)
return;
Modified: cfe/trunk/test/Sema/warn-fortify-source.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-fortify-source.c?rev=357304&r1=357303&r2=357304&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-fortify-source.c (original)
+++ cfe/trunk/test/Sema/warn-fortify-source.c Fri Mar 29 12:53:41 2019
@@ -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 __at
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
More information about the cfe-commits
mailing list