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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254639
91177308-0d34-0410-b5e6-
96231b3b80d8
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);
}
}
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;