Do some blocks cleanup and simplification. Fix a crash, and add a test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65746 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 93bc53f..565549c 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -450,9 +450,13 @@
return CGM.GetAddrOfConstantCFString(S);
}
case Expr::BlockExprClass: {
- BlockExpr *B = cast<BlockExpr>(E);
- if (!B->hasBlockDeclRefExprs())
- return cast<llvm::Constant>(CGF->BuildBlockLiteralTmp(B));
+ std::string FunctionName;
+ if (CGF)
+ FunctionName = CGF->CurFn->getName();
+ else
+ FunctionName = "global";
+
+ return CGM.GetAddrOfGlobalBlock(cast<BlockExpr>(E), FunctionName.c_str());
}
}