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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65070 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 3eb68b5..2a4b465 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2004,7 +2004,8 @@
llvm::SmallVector<ParmVarDecl*, 8> Params;
bool hasPrototype;
bool isVariadic;
-
+ bool hasBlockDeclRefExprs;
+
BlockDecl *TheDecl;
/// TheScope - This is the scope for the block itself, which contains
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 5d1d935..c95b5ee 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -865,6 +865,9 @@
// 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,
@@ -4331,6 +4334,7 @@
BSI->ReturnType = 0;
BSI->TheScope = BlockScope;
+ BSI->hasBlockDeclRefExprs = false;
BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
PushDeclContext(BlockScope, BSI->TheDecl);
@@ -4442,7 +4446,7 @@
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,