diff options
author | John McCall <rjmccall@apple.com> | 2011-03-07 01:52:56 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-03-07 01:52:56 +0000 |
commit | f7dcf320a7e29cd2a7b89696ba0092a63b0e0a2f (patch) | |
tree | a5c048726aaac30ea3931d66ccc3aaf5882e9f8e /clang/lib/CodeGen | |
parent | e467979d0ad24f4210d7bd1bc8fb38391bb4caff (diff) | |
download | bcm5719-llvm-f7dcf320a7e29cd2a7b89696ba0092a63b0e0a2f.tar.gz bcm5719-llvm-f7dcf320a7e29cd2a7b89696ba0092a63b0e0a2f.zip |
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.
llvm-svn: 127147
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index bba7864bff9..2b8efa0e39f 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/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); |