aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-03-07 01:52:56 +0000
committerJohn McCall <rjmccall@apple.com>2011-03-07 01:52:56 +0000
commita7f633f522af786e80dc08dbd63e222c9414095b (patch)
tree4ada9ad427b1a0b97bbfd52b6f94745f73d76fad /lib/CodeGen
parent03fd362dbf6fcd077df566fe2ac3165be668323b (diff)
An operator new with an empty exception specifier returns null on a bad
allocation and therefore requires a null-check. We were doing that, but we weren't treating the new-initializer as being conditionally executed, which means it was possible to get ill-formed IR as in PR9298. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127147 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGExprCXX.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index bba7864bff..2b8efa0e39 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -993,6 +993,10 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
llvm::Value *NewPtr = RV.getScalarVal();
unsigned AS = cast<llvm::PointerType>(NewPtr->getType())->getAddressSpace();
+ // The null-check means that the initializer is conditionally
+ // evaluated.
+ ConditionalEvaluation conditional(*this);
+
if (NullCheckResult) {
NullCheckSource = Builder.GetInsertBlock();
NewNotNull = createBasicBlock("new.notnull");
@@ -1001,6 +1005,8 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
llvm::Value *IsNull = Builder.CreateIsNull(NewPtr, "new.isnull");
Builder.CreateCondBr(IsNull, NewEnd, NewNotNull);
EmitBlock(NewNotNull);
+
+ conditional.begin(*this);
}
assert((AllocSize == AllocSizeWithoutCookie) ==
@@ -1042,6 +1048,8 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
DeactivateCleanupBlock(CallOperatorDelete);
if (NullCheckResult) {
+ conditional.end(*this);
+
Builder.CreateBr(NewEnd);
llvm::BasicBlock *NotNullSource = Builder.GetInsertBlock();
EmitBlock(NewEnd);