From: Erik Pilkington Date: Fri, 29 Mar 2019 19:53:41 +0000 (+0000) Subject: [Sema] Avoid sending a dependent expression to the constant evaluator. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=233ff94212633f88b868f4ea1cd1887aa957ce41;p=platform%2Fupstream%2Fllvm.git [Sema] Avoid sending a dependent expression to the constant evaluator. Fixes llvm.org/PR41286 llvm-svn: 357304 --- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 024d78b..5a9b3c3 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 3cd939a..d9c21c0 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 struct S { + void mf() const { + __builtin_memset(const_cast(mv), 0, 0); + } + + char mv[10]; +}; + +template +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