aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCXX.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-31 21:53:59 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-31 21:53:59 +0000
commitd3fd6bad1249d3f34d71b73e2333fab0db51cce4 (patch)
tree338f949f88e5c30bef2bacb1db0140c6bcf0cead /lib/CodeGen/CGCXX.cpp
parent627a3e573f1d9f0429d62c7ceb742a21cdabfce0 (diff)
Improve irgen of 'new' further.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72677 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r--lib/CodeGen/CGCXX.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index febfbacf7c..2cc9d0390f 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -285,11 +285,23 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
CGM.GetAddrOfFunction(GlobalDecl(NewFD)),
NewArgs, NewFD);
- llvm::Value *NewPtr = Builder.CreateBitCast(RV.getScalarVal(),
- ConvertType(E->getType()));
-
+ // If an allocation function is declared with an empty exception specification
+ // it returns null to indicate failure to allocate storage. [expr.new]p13.
+ // (We don't need to check for null when there's no new initializer and
+ // we're allocating a POD type).
+ bool NullCheckResult = NewFTy->hasEmptyExceptionSpec() &&
+ !(AllocType->isPODType() && !E->hasInitializer());
+
+ if (NullCheckResult) {
+ ErrorUnsupported(E, "new expr that needs to be null checked");
+ return llvm::UndefValue::get(ConvertType(E->getType()));
+ }
+
+ llvm::Value *NewPtr =
+ Builder.CreateBitCast(RV.getScalarVal(), ConvertType(E->getType()));
+
if (AllocType->isPODType()) {
- if (E->getNumConstructorArgs() != 0) {
+ if (E->hasInitializer()) {
assert(E->getNumConstructorArgs() == 1 &&
"Can only have one argument to initializer of POD type.");
@@ -302,12 +314,16 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
else
EmitAggExpr(Init, NewPtr, AllocType.isVolatileQualified());
}
+ } else {
+ // Call the constructor.
+ CXXConstructorDecl *Ctor = E->getConstructor();
- return NewPtr;
+ EmitCXXConstructorCall(Ctor, Ctor_Complete, NewPtr,
+ E->constructor_arg_begin(),
+ E->constructor_arg_end());
}
-
- ErrorUnsupported(E, "new expression with non-POD type");
- return llvm::UndefValue::get(ConvertType(E->getType()));
+
+ return NewPtr;
}
static bool canGenerateCXXstructor(const CXXRecordDecl *RD,