// Blocks are difficult because the return type may not be stored in the
// BlockDecl itself. The AST should probably be enhanced, but for now we
// just do what we can.
- QualType Ty = BD->getSignatureAsWritten()->getType();
- if (const FunctionType *FT = Ty->getAs<FunctionType>())
+ // FIXME: All blocks should have signatures-as-written, even if the return
+ // type is inferred. (That's signified is with a dependent result type.)
+ if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten()) {
+ const FunctionType *FT = TSI->getType()->castAs<FunctionType>();
if (!FT->getResultType()->isDependentType())
return FT->getResultType();
+ }
return QualType();
}
sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
getFunctionTextRegion(cast<NamedDecl>(STCD)));
else if (const BlockDecl *BD = dyn_cast<BlockDecl>(STCD)) {
+ // FIXME: The fallback type here is totally bogus -- though it should
+ // never be queried, it will prevent uniquing with the real
+ // BlockTextRegion. Ideally we'd fix the AST so that we always had a
+ // signature.
+ QualType T;
+ if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten())
+ T = TSI->getType();
+ else
+ T = getContext().getFunctionNoProtoType(getContext().VoidTy);
+
const BlockTextRegion *BTR =
- getBlockTextRegion(BD,
- C.getCanonicalType(BD->getSignatureAsWritten()->getType()),
- STC->getAnalysisDeclContext());
+ getBlockTextRegion(BD, C.getCanonicalType(T),
+ STC->getAnalysisDeclContext());
sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
BTR);
}
#endif
}
+namespace rdar13954714 {
+ template <bool VALUE>
+ bool blockInTemplate() {
+ return (^() {
+ return VALUE;
+ })();
+ }
+
+ // force instantiation
+ template bool blockInTemplate<true>();
+
+ template <bool VALUE>
+ void blockWithStatic() {
+ (void)^() {
+ static int x;
+ return ++x;
+ };
+ }
+
+ // force instantiation
+ template void blockWithStatic<true>();
+}