forked from OSchip/llvm-project
Better support for scalar POD types in 'new' expressions.
llvm-svn: 72674
This commit is contained in:
parent
6f9dabff6d
commit
ec71f61608
|
@ -285,20 +285,29 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
|
||||||
CGM.GetAddrOfFunction(GlobalDecl(NewFD)),
|
CGM.GetAddrOfFunction(GlobalDecl(NewFD)),
|
||||||
NewArgs, NewFD);
|
NewArgs, NewFD);
|
||||||
|
|
||||||
llvm::Value *V = Builder.CreateBitCast(RV.getScalarVal(),
|
llvm::Value *NewPtr = Builder.CreateBitCast(RV.getScalarVal(),
|
||||||
ConvertType(E->getType()));
|
ConvertType(E->getType()));
|
||||||
|
|
||||||
if (E->hasInitializer()) {
|
if (AllocType->isPODType()) {
|
||||||
ErrorUnsupported(E, "new expression with initializer");
|
if (E->getNumConstructorArgs() != 0) {
|
||||||
return llvm::UndefValue::get(ConvertType(E->getType()));
|
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");
|
||||||
ErrorUnsupported(E, "new expression with non-POD type");
|
return llvm::UndefValue::get(ConvertType(E->getType()));
|
||||||
return llvm::UndefValue::get(ConvertType(E->getType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return V;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
|
static bool canGenerateCXXstructor(const CXXRecordDecl *RD,
|
||||||
|
|
|
@ -10,3 +10,7 @@ void* operator new(unsigned long, void*) throw();
|
||||||
void t2(int* a) {
|
void t2(int* a) {
|
||||||
int* b = new (a) int;
|
int* b = new (a) int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void t3() {
|
||||||
|
int *a = new int(10);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue