summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-03-26 23:21:22 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-03-26 23:21:22 +0000
commit818698010cd47b6ed76b58f06eb9ac62045eb0aa (patch)
treecbc373ceb079136ececd951de457b1e97cef760c
parent14f6d1527c706d0749bad224fb6a4d2586d608f4 (diff)
downloadbcm5719-llvm-818698010cd47b6ed76b58f06eb9ac62045eb0aa.tar.gz
bcm5719-llvm-818698010cd47b6ed76b58f06eb9ac62045eb0aa.zip
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)); llvm-svn: 357041
-rw-r--r--clang/lib/Sema/SemaChecking.cpp7
-rw-r--r--clang/test/Sema/warn-fortify-source.c3
2 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b9b14a0ede5..df77ab959db 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/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/clang/test/Sema/warn-fortify-source.c b/clang/test/Sema/warn-fortify-source.c
index 208ff6909f1..3cd939a2d99 100644
--- a/clang/test/Sema/warn-fortify-source.c
+++ b/clang/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() {
OpenPOWER on IntegriCloud