diff --git a/ddmd/root/rmem.d b/ddmd/root/rmem.d index 450d45e826..fd966b72b1 100644 --- a/ddmd/root/rmem.d +++ b/ddmd/root/rmem.d @@ -192,6 +192,14 @@ else return cast(Object)p; } + version (LDC) + { + extern (C) Object _d_allocclass(const ClassInfo ci) nothrow + { + return cast(Object)allocmemory(ci.init.length); + } + } + extern (C) void* _d_newitemT(TypeInfo ti) nothrow { auto p = allocmemory(ti.tsize); diff --git a/gen/classes.cpp b/gen/classes.cpp index 35f1293d90..4ae4382255 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -84,8 +84,8 @@ DValue *DtoNewClass(Loc &loc, TypeClass *tc, NewExp *newexp) { // allocate LLValue *mem; if (newexp->onstack) { - // FIXME align scope class to its largest member - mem = DtoRawAlloca(DtoType(tc)->getContainedType(0), 0, ".newclass_alloca"); + mem = DtoRawAlloca(DtoType(tc)->getContainedType(0), DtoAlignment(tc), + ".newclass_alloca"); } // custom allocator else if (newexp->allocator) { @@ -97,7 +97,7 @@ DValue *DtoNewClass(Loc &loc, TypeClass *tc, NewExp *newexp) { // default allocator else { llvm::Function *fn = - getRuntimeFunction(loc, gIR->module, "_d_newclass"); + getRuntimeFunction(loc, gIR->module, "_d_allocclass"); LLConstant *ci = DtoBitCast(getIrAggr(tc->sym)->getClassInfoSymbol(), DtoType(Type::typeinfoclass->type)); mem = diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 346f0b5044..5483e5b528 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -255,7 +255,7 @@ public: } }; -// FunctionInfo for _d_newclass +// FunctionInfo for _d_allocclass class AllocClassFI : public FunctionInfo { public: bool analyze(CallSite CS, const Analysis &A) override { @@ -436,7 +436,7 @@ GarbageCollect2Stack::GarbageCollect2Stack() KnownFunctions["_d_allocmemoryT"] = &AllocMemoryT; KnownFunctions["_d_newarrayU"] = &NewArrayU; KnownFunctions["_d_newarrayT"] = &NewArrayT; - KnownFunctions["_d_newclass"] = &AllocClass; + KnownFunctions["_d_allocclass"] = &AllocClass; KnownFunctions["_d_allocmemory"] = &AllocMemory; } diff --git a/gen/passes/SimplifyDRuntimeCalls.cpp b/gen/passes/SimplifyDRuntimeCalls.cpp index ef5b98abd5..f056b1410c 100644 --- a/gen/passes/SimplifyDRuntimeCalls.cpp +++ b/gen/passes/SimplifyDRuntimeCalls.cpp @@ -372,6 +372,7 @@ void SimplifyDRuntimeCalls::InitOptimizations() { Optimizations["_d_newarraymiT"] = &Allocation; Optimizations["_d_newarraymvT"] = &Allocation; Optimizations["_d_newclass"] = &Allocation; + Optimizations["_d_allocclass"] = &Allocation; } /// runOnFunction - Top level algorithm. diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 5e25494578..1d03f57a42 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -85,6 +85,7 @@ static void checkForImplicitGCCall(const Loc &loc, const char *name) { "_d_newarraymiTX", "_d_newarrayU", "_d_newclass", + "_d_allocclass", "_d_newitemT", "_d_newitemiT", }; @@ -397,6 +398,10 @@ static void buildRuntimeModule() { createFwdDecl(LINKc, objectTy, {"_d_newclass"}, {classInfoTy}, {STCconst}, Attr_NoAlias); + // Object _d_allocclass(const ClassInfo ci) + createFwdDecl(LINKc, objectTy, {"_d_allocclass"}, {classInfoTy}, {STCconst}, + Attr_NoAlias); + // void* _d_newitemT (TypeInfo ti) // void* _d_newitemiT(TypeInfo ti) createFwdDecl(LINKc, voidPtrTy, {"_d_newitemT", "_d_newitemiT"}, {typeInfoTy}, diff --git a/runtime/druntime b/runtime/druntime index 5c5dd37e43..0aeb4da53e 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit 5c5dd37e433afdb5b1f2cd33f170014cdd96312a +Subproject commit 0aeb4da53e922f7d17401dd13f69b8e355f327f9