[cfe-commits] r72674 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/new.cpp
Anders Carlsson
andersca at mac.com
Sun May 31 13:56:36 PDT 2009
Author: andersca
Date: Sun May 31 15:56:36 2009
New Revision: 72674
URL: http://llvm.org/viewvc/llvm-project?rev=72674&view=rev
Log:
Better support for scalar POD types in 'new' expressions.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/new.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=72674&r1=72673&r2=72674&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun May 31 15:56:36 2009
@@ -285,20 +285,29 @@
CGM.GetAddrOfFunction(GlobalDecl(NewFD)),
NewArgs, NewFD);
- llvm::Value *V = Builder.CreateBitCast(RV.getScalarVal(),
- ConvertType(E->getType()));
+ llvm::Value *NewPtr = Builder.CreateBitCast(RV.getScalarVal(),
+ ConvertType(E->getType()));
- if (E->hasInitializer()) {
- ErrorUnsupported(E, "new expression with initializer");
- return llvm::UndefValue::get(ConvertType(E->getType()));
+ if (AllocType->isPODType()) {
+ if (E->getNumConstructorArgs() != 0) {
+ assert(E->getNumConstructorArgs() == 1 &&
+ "Can only have one argument to initializer of POD type.");
+
+ const Expr *Init = E->getConstructorArg(0);
+
+ if (!hasAggregateLLVMType(AllocType)) {
+ Builder.CreateStore(EmitScalarExpr(Init), NewPtr);
+ } else {
+ ErrorUnsupported(E, "new expression");
+ return llvm::UndefValue::get(ConvertType(E->getType()));
+ }
+ }
+
+ return NewPtr;
}
- if (!AllocType->isPODType()) {
- ErrorUnsupported(E, "new expression with non-POD type");
- return llvm::UndefValue::get(ConvertType(E->getType()));
- }
-
- return V;
+ ErrorUnsupported(E, "new expression with non-POD type");
+ return llvm::UndefValue::get(ConvertType(E->getType()));
}
static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=72674&r1=72673&r2=72674&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Sun May 31 15:56:36 2009
@@ -10,3 +10,7 @@
void t2(int* a) {
int* b = new (a) int;
}
+
+void t3() {
+ int *a = new int(10);
+}
More information about the cfe-commits
mailing list