[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.

llvm-svn: 254639
This commit is contained in:
Devin Coughlin 2015-12-03 19:41:24 +00:00
parent 9ebe30b265
commit dfde655461
2 changed files with 13 additions and 4 deletions

View File

@ -156,6 +156,15 @@ void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
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);
}

View File

@ -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;