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:
Martin Kinkelin 2019-04-25 21:24:05 +02:00
parent 89d72b646e
commit ef2bbfa09b
3 changed files with 18 additions and 7 deletions

View file

@ -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,17 +99,23 @@ 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
DtoInitClass(tc, mem);
if (doInit)
DtoInitClass(tc, mem);
// init inner-class outer reference
if (newexp->thisexp) {