Add enough checking to ensure that non-constant block literals don't
appear to be constant. I'll probably redo this and throw it all away later once we have codegen for BlockDeclRefExprs. llvm-svn: 65070
This commit is contained in:
parent
a118a07157
commit
a67033294a
|
@ -2051,9 +2051,11 @@ public:
|
||||||
class BlockExpr : public Expr {
|
class BlockExpr : public Expr {
|
||||||
protected:
|
protected:
|
||||||
BlockDecl *TheBlock;
|
BlockDecl *TheBlock;
|
||||||
|
bool HasBlockDeclRefExprs;
|
||||||
public:
|
public:
|
||||||
BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty),
|
BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
|
||||||
TheBlock(BD) {}
|
: Expr(BlockExprClass, ty),
|
||||||
|
TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
|
||||||
|
|
||||||
const BlockDecl *getBlockDecl() const { return TheBlock; }
|
const BlockDecl *getBlockDecl() const { return TheBlock; }
|
||||||
BlockDecl *getBlockDecl() { return TheBlock; }
|
BlockDecl *getBlockDecl() { return TheBlock; }
|
||||||
|
@ -2070,6 +2072,10 @@ public:
|
||||||
/// getFunctionType - Return the underlying function type for this block.
|
/// getFunctionType - Return the underlying function type for this block.
|
||||||
const FunctionType *getFunctionType() const;
|
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) {
|
static bool classof(const Stmt *T) {
|
||||||
return T->getStmtClass() == BlockExprClass;
|
return T->getStmtClass() == BlockExprClass;
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,11 @@ public:
|
||||||
APValue VisitAddrLabelExpr(AddrLabelExpr *E)
|
APValue VisitAddrLabelExpr(AddrLabelExpr *E)
|
||||||
{ return APValue(E, 0); }
|
{ return APValue(E, 0); }
|
||||||
APValue VisitCallExpr(CallExpr *E);
|
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);
|
APValue VisitConditionalOperator(ConditionalOperator *E);
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
|
@ -1290,11 +1290,14 @@ ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C) {
|
||||||
void BlockExpr::EmitImpl(Serializer& S) const {
|
void BlockExpr::EmitImpl(Serializer& S) const {
|
||||||
S.Emit(getType());
|
S.Emit(getType());
|
||||||
S.EmitOwnedPtr(TheBlock);
|
S.EmitOwnedPtr(TheBlock);
|
||||||
|
S.EmitBool(HasBlockDeclRefExprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockExpr* BlockExpr::CreateImpl(Deserializer& D, ASTContext& C) {
|
BlockExpr* BlockExpr::CreateImpl(Deserializer& D, ASTContext& C) {
|
||||||
QualType T = QualType::ReadVal(D);
|
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 {
|
void BlockDeclRefExpr::EmitImpl(Serializer& S) const {
|
||||||
|
|
|
@ -382,6 +382,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Constant *VisitBlockExpr(const BlockExpr *E) {
|
llvm::Constant *VisitBlockExpr(const BlockExpr *E) {
|
||||||
|
assert (!E->hasBlockDeclRefExprs() && "global block with BlockDeclRefs");
|
||||||
|
|
||||||
const char *Name = "";
|
const char *Name = "";
|
||||||
if (const NamedDecl *ND = dyn_cast<NamedDecl>(CGF->CurFuncDecl))
|
if (const NamedDecl *ND = dyn_cast<NamedDecl>(CGF->CurFuncDecl))
|
||||||
Name = ND->getNameAsString().c_str();
|
Name = ND->getNameAsString().c_str();
|
||||||
|
@ -615,7 +617,9 @@ public:
|
||||||
return CGM.GetAddrOfConstantCFString(S);
|
return CGM.GetAddrOfConstantCFString(S);
|
||||||
}
|
}
|
||||||
case Expr::BlockExprClass: {
|
case Expr::BlockExprClass: {
|
||||||
return CGF->BuildBlockLiteralTmp(cast<BlockExpr>(E));
|
BlockExpr *B = cast<BlockExpr>(E);
|
||||||
|
if (!B->hasBlockDeclRefExprs())
|
||||||
|
return CGF->BuildBlockLiteralTmp(B);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2004,6 +2004,7 @@ struct BlockSemaInfo {
|
||||||
llvm::SmallVector<ParmVarDecl*, 8> Params;
|
llvm::SmallVector<ParmVarDecl*, 8> Params;
|
||||||
bool hasPrototype;
|
bool hasPrototype;
|
||||||
bool isVariadic;
|
bool isVariadic;
|
||||||
|
bool hasBlockDeclRefExprs;
|
||||||
|
|
||||||
BlockDecl *TheDecl;
|
BlockDecl *TheDecl;
|
||||||
|
|
||||||
|
|
|
@ -865,6 +865,9 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
|
||||||
// as they do not get snapshotted.
|
// as they do not get snapshotted.
|
||||||
//
|
//
|
||||||
if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
|
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.
|
// The BlocksAttr indicates the variable is bound by-reference.
|
||||||
if (VD->getAttr<BlocksAttr>())
|
if (VD->getAttr<BlocksAttr>())
|
||||||
return Owned(new (Context) BlockDeclRefExpr(VD,
|
return Owned(new (Context) BlockDeclRefExpr(VD,
|
||||||
|
@ -4331,6 +4334,7 @@ void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *BlockScope) {
|
||||||
|
|
||||||
BSI->ReturnType = 0;
|
BSI->ReturnType = 0;
|
||||||
BSI->TheScope = BlockScope;
|
BSI->TheScope = BlockScope;
|
||||||
|
BSI->hasBlockDeclRefExprs = false;
|
||||||
|
|
||||||
BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
|
BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
|
||||||
PushDeclContext(BlockScope, BSI->TheDecl);
|
PushDeclContext(BlockScope, BSI->TheDecl);
|
||||||
|
@ -4442,7 +4446,7 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body,
|
||||||
BlockTy = Context.getBlockPointerType(BlockTy);
|
BlockTy = Context.getBlockPointerType(BlockTy);
|
||||||
|
|
||||||
BSI->TheDecl->setBody(Body.take());
|
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,
|
Sema::ExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
|
||||||
|
|
Loading…
Reference in New Issue