mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 10:57:35 +03:00
Fix DIP1008
Invoke _d_newThrowable for exception allocation & initialization, and increase the reference count in LDC-specific _d_throw_exception for MSVC targets. Fixes runnable/test19317.d.
This commit is contained in:
parent
89d72b646e
commit
ef2bbfa09b
3 changed files with 18 additions and 7 deletions
|
@ -82,6 +82,7 @@ DValue *DtoNewClass(Loc &loc, TypeClass *tc, NewExp *newexp) {
|
|||
|
||||
// allocate
|
||||
LLValue *mem;
|
||||
bool doInit = true;
|
||||
if (newexp->onstack) {
|
||||
unsigned alignment = tc->sym->alignsize;
|
||||
if (alignment == STRUCTALIGN_DEFAULT)
|
||||
|
@ -98,16 +99,22 @@ DValue *DtoNewClass(Loc &loc, TypeClass *tc, NewExp *newexp) {
|
|||
}
|
||||
// default allocator
|
||||
else {
|
||||
llvm::Function *fn =
|
||||
getRuntimeFunction(loc, gIR->module, "_d_allocclass");
|
||||
const bool useEHAlloc = global.params.ehnogc && newexp->thrownew;
|
||||
llvm::Function *fn = getRuntimeFunction(
|
||||
loc, gIR->module, useEHAlloc ? "_d_newThrowable" : "_d_allocclass");
|
||||
LLConstant *ci = DtoBitCast(getIrAggr(tc->sym)->getClassInfoSymbol(),
|
||||
DtoType(getClassInfoType()));
|
||||
mem =
|
||||
gIR->CreateCallOrInvoke(fn, ci, ".newclass_gc_alloc").getInstruction();
|
||||
mem = DtoBitCast(mem, DtoType(tc), ".newclass_gc");
|
||||
mem = gIR->CreateCallOrInvoke(fn, ci,
|
||||
useEHAlloc ? ".newthrowable_alloc"
|
||||
: ".newclass_gc_alloc")
|
||||
.getInstruction();
|
||||
mem = DtoBitCast(mem, DtoType(tc),
|
||||
useEHAlloc ? ".newthrowable" : ".newclass_gc");
|
||||
doInit = !useEHAlloc;
|
||||
}
|
||||
|
||||
// init
|
||||
if (doInit)
|
||||
DtoInitClass(tc, mem);
|
||||
|
||||
// init inner-class outer reference
|
||||
|
|
|
@ -615,6 +615,10 @@ static void buildRuntimeModule() {
|
|||
createFwdDecl(LINKc, objectTy, {"_d_newclass", "_d_allocclass"},
|
||||
{classInfoTy}, {STCconst}, Attr_NoAlias);
|
||||
|
||||
// Throwable _d_newThrowable(const ClassInfo ci)
|
||||
createFwdDecl(LINKc, throwableTy, {"_d_newThrowable"}, {classInfoTy},
|
||||
{STCconst}, Attr_NoAlias);
|
||||
|
||||
// void* _d_newitemT (TypeInfo ti)
|
||||
// void* _d_newitemiT(TypeInfo ti)
|
||||
createFwdDecl(LINKc, voidPtrTy, {"_d_newitemT", "_d_newitemiT"}, {typeInfoTy},
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 02b40d8ceb41e23409b17a78ad2600aa5546af22
|
||||
Subproject commit ea48d4405d0a615b7d0e9ee5afcdd4409cf102d2
|
Loading…
Add table
Add a link
Reference in a new issue