Author: epilk Date: Tue Mar 26 16:21:22 2019 New Revision: 357041 URL: http://llvm.org/viewvc/llvm-project?rev=357041&view=rev Log: 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)); 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=357041&r1=357040&r2=357041&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Mar 26 16:21:22 2019 @@ -431,9 +431,10 @@ void Sema::checkFortifiedBuiltinMemoryFu 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, 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=357041&r1=357040&r2=357041&view=diff ============================================================================== --- cfe/trunk/test/Sema/warn-fortify-source.c (original) +++ cfe/trunk/test/Sema/warn-fortify-source.c Tue Mar 26 16:21:22 2019 @@ -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() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits