class BlockExpr : public Expr {
protected:
BlockDecl *TheBlock;
+ bool HasBlockDeclRefExprs;
public:
- BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty),
- TheBlock(BD) {}
+ BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
+ : Expr(BlockExprClass, ty),
+ TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
const BlockDecl *getBlockDecl() const { return TheBlock; }
BlockDecl *getBlockDecl() { return TheBlock; }
/// getFunctionType - Return the underlying function type for this block.
const FunctionType *getFunctionType() const;
+ /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
+ /// contained inside.
+ bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
+
static bool classof(const Stmt *T) {
return T->getStmtClass() == BlockExprClass;
}
APValue VisitAddrLabelExpr(AddrLabelExpr *E)
{ return APValue(E, 0); }
APValue VisitCallExpr(CallExpr *E);
- APValue VisitBlockExpr(BlockExpr *E) { return APValue(E, 0); }
+ APValue VisitBlockExpr(BlockExpr *E) {
+ if (!E->hasBlockDeclRefExprs())
+ return APValue(E, 0);
+ return APValue();
+ }
APValue VisitConditionalOperator(ConditionalOperator *E);
};
} // end anonymous namespace
void BlockExpr::EmitImpl(Serializer& S) const {
S.Emit(getType());
S.EmitOwnedPtr(TheBlock);
+ S.EmitBool(HasBlockDeclRefExprs);
}
BlockExpr* BlockExpr::CreateImpl(Deserializer& D, ASTContext& C) {
QualType T = QualType::ReadVal(D);
- return new BlockExpr(cast<BlockDecl>(D.ReadOwnedPtr<Decl>(C)),T);
+ BlockDecl *B = cast<BlockDecl>(D.ReadOwnedPtr<Decl>(C));
+ bool H = D.ReadBool();
+ return new BlockExpr(B,T,H);
}
void BlockDeclRefExpr::EmitImpl(Serializer& S) const {
}
llvm::Constant *VisitBlockExpr(const BlockExpr *E) {
+ assert (!E->hasBlockDeclRefExprs() && "global block with BlockDeclRefs");
+
const char *Name = "";
if (const NamedDecl *ND = dyn_cast<NamedDecl>(CGF->CurFuncDecl))
Name = ND->getNameAsString().c_str();
return CGM.GetAddrOfConstantCFString(S);
}
case Expr::BlockExprClass: {
- return CGF->BuildBlockLiteralTmp(cast<BlockExpr>(E));
+ BlockExpr *B = cast<BlockExpr>(E);
+ if (!B->hasBlockDeclRefExprs())
+ return CGF->BuildBlockLiteralTmp(B);
}
}
llvm::SmallVector<ParmVarDecl*, 8> Params;
bool hasPrototype;
bool isVariadic;
-
+ bool hasBlockDeclRefExprs;
+
BlockDecl *TheDecl;
/// TheScope - This is the scope for the block itself, which contains
// as they do not get snapshotted.
//
if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
+ // Blocks that have these can't be constant.
+ CurBlock->hasBlockDeclRefExprs = true;
+
// The BlocksAttr indicates the variable is bound by-reference.
if (VD->getAttr<BlocksAttr>())
return Owned(new (Context) BlockDeclRefExpr(VD,
BSI->ReturnType = 0;
BSI->TheScope = BlockScope;
+ BSI->hasBlockDeclRefExprs = false;
BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
PushDeclContext(BlockScope, BSI->TheDecl);
BlockTy = Context.getBlockPointerType(BlockTy);
BSI->TheDecl->setBody(Body.take());
- return new (Context) BlockExpr(BSI->TheDecl, BlockTy);
+ return new (Context) BlockExpr(BSI->TheDecl, BlockTy, BSI->hasBlockDeclRefExprs);
}
Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,