summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaChecking.cpp3
-rw-r--r--clang/test/Sema/warn-fortify-source.c33
2 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 024d78bc64e..5a9b3c3d13c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -307,6 +307,9 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
// - 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;
diff --git a/clang/test/Sema/warn-fortify-source.c b/clang/test/Sema/warn-fortify-source.c
index 3cd939a2d99..d9c21c08421 100644
--- a/clang/test/Sema/warn-fortify-source.c
+++ b/clang/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
OpenPOWER on IntegriCloud