From: Erik Pilkington Date: Tue, 26 Mar 2019 23:21:22 +0000 (+0000) Subject: Emit -Wfortify-source using DiagRuntimeBehaviour X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92053fee4de8009646eeb55af50c8715be29c6bf;p=clang Emit -Wfortify-source using DiagRuntimeBehaviour This fixes a false positive on the following, where st is configured to have different sizes based on some preprocessor logic: if (sizeof(buf) == sizeof(*st)) memcpy(&buf, st, sizeof(*st)); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357041 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index b9b14a0ede..df77ab959d 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -431,9 +431,10 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, FunctionName = FunctionName.drop_front(std::strlen("__builtin_")); } - Diag(TheCall->getBeginLoc(), DiagID) - << FunctionName << ObjectSize.toString(/*Radix=*/10) - << UsedSize.toString(/*Radix=*/10); + DiagRuntimeBehavior(TheCall->getBeginLoc(), TheCall, + PDiag(DiagID) + << FunctionName << ObjectSize.toString(/*Radix=*/10) + << UsedSize.toString(/*Radix=*/10)); } static bool SemaBuiltinSEHScopeCheck(Sema &SemaRef, CallExpr *TheCall, diff --git a/test/Sema/warn-fortify-source.c b/test/Sema/warn-fortify-source.c index 208ff6909f..3cd939a2d9 100644 --- a/test/Sema/warn-fortify-source.c +++ b/test/Sema/warn-fortify-source.c @@ -20,6 +20,9 @@ void call_memcpy() { char dst[10]; char src[20]; memcpy(dst, src, 20); // expected-warning {{memcpy' will always overflow; destination buffer has size 10, but size argument is 20}} + + if (sizeof(dst) == sizeof(src)) + memcpy(dst, src, 20); // no warning, unreachable } void call_memcpy_type() {