Skip to content

Commit

Permalink
Fix DIP1008
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kinke committed Apr 25, 2019
1 parent 89d72b6 commit ef2bbfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
19 changes: 13 additions & 6 deletions gen/classes.cpp
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions gen/runtime.cpp
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion runtime/druntime
Submodule druntime updated 1 files
+7 −5 src/ldc/eh_msvc.d

0 comments on commit ef2bbfa

Please sign in to comment.