r254639 - [analyzer] Suppress stack address escape on CK_CopyAndAutoreleaseBlockObject.
Devin Coughlin via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 3 11:41:24 PST 2015
Author: dcoughlin
Date: Thu Dec 3 13:41:24 2015
New Revision: 254639
URL: http://llvm.org/viewvc/llvm-project?rev=254639&view=rev
Log:
[analyzer] Suppress stack address escape on CK_CopyAndAutoreleaseBlockObject.
Don't warn about addresses of stack-allocated blocks escaping if the block
region was cast with CK_CopyAndAutoreleaseBlockObject. These casts, which
are introduced in the implicit conversion operator for lambda-to-block
conversions, cause the block to be copied to the heap -- so the warning is
spurious.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
cfe/trunk/test/Analysis/lambdas.mm
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp?rev=254639&r1=254638&r2=254639&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp Thu Dec 3 13:41:24 2015
@@ -156,6 +156,15 @@ void StackAddrEscapeChecker::checkPreStm
if (isa<CXXConstructExpr>(RetE) && RetE->getType()->isRecordType())
return;
+ // The CK_CopyAndAutoreleaseBlockObject cast causes the block to be copied
+ // so the stack address is not escaping here.
+ if (auto *ICE = dyn_cast<ImplicitCastExpr>(RetE)) {
+ if (isa<BlockDataRegion>(R) &&
+ ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject) {
+ return;
+ }
+ }
+
EmitStackError(C, R, RetE);
}
Modified: cfe/trunk/test/Analysis/lambdas.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lambdas.mm?rev=254639&r1=254638&r2=254639&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/lambdas.mm (original)
+++ cfe/trunk/test/Analysis/lambdas.mm Thu Dec 3 13:41:24 2015
@@ -76,10 +76,10 @@ void castToBlockAndInline() {
}
void castLambdaInLocalBlock() {
- // FIXME: This results in a spurious
- // "Address of stack-allocated block declared on line XX returned to caller" warning
- // because we're not handling lambda to block conversions properly in ExprEngine.
- auto lambda = []{ }; // expected-warning {{Address of stack-allocated block declared on line}}
+ // Make sure we don't emit a spurious diagnostic about the address of a block
+ // escaping in the implicit conversion operator method for lambda-to-block
+ // conversions.
+ auto lambda = []{ }; // no-warning
void(^block)() = lambda;
(void)block;
More information about the cfe-commits
mailing list