Skip to content

Commit 760d478

Browse files
committed
Lookup runtime function before constructing the call args
To retain the LoC information in case TypeInfo declarations are missing.
1 parent 13058b8 commit 760d478

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

gen/arrays.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,6 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
674674
IF_LOG Logger::println("DtoNewDynArray : %s", arrayType->toChars());
675675
LOG_SCOPE;
676676

677-
// typeinfo arg
678-
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
679-
680-
// dim arg
681-
assert(DtoType(dim->type) == DtoSize_t());
682-
LLValue *arrayLen = DtoRVal(dim);
683-
684677
// get runtime function
685678
Type *eltType = arrayType->toBasetype()->nextOf();
686679
bool zeroInit = eltType->isZeroInit();
@@ -690,6 +683,13 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
690683
: "_d_newarrayU";
691684
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
692685

686+
// typeinfo arg
687+
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
688+
689+
// dim arg
690+
assert(DtoType(dim->type) == DtoSize_t());
691+
LLValue *arrayLen = DtoRVal(dim);
692+
693693
// call allocator
694694
LLValue *newArray =
695695
gIR->CreateCallOrInvoke(fn, arrayTypeInfo, arrayLen, ".gc_mem")
@@ -704,9 +704,6 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
704704
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
705705
LOG_SCOPE;
706706

707-
// typeinfo arg
708-
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
709-
710707
// get value type
711708
Type *vtype = arrayType->toBasetype();
712709
for (size_t i = 0; i < ndims; ++i) {
@@ -718,6 +715,9 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
718715
vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
719716
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
720717

718+
// typeinfo arg
719+
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
720+
721721
// Check if constant
722722
bool allDimsConst = true;
723723
for (size_t i = 0; i < ndims; ++i) {

gen/classes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ DValue *DtoDynamicCastObject(Loc &loc, DValue *val, Type *_to) {
360360
// call:
361361
// Object _d_dynamic_cast(Object o, ClassInfo c)
362362

363-
resolveObjectAndClassInfoClasses();
364-
365363
llvm::Function *func =
366364
getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
367365
LLFunctionType *funcTy = func->getFunctionType();
368366

367+
resolveObjectAndClassInfoClasses();
368+
369369
// Object o
370370
LLValue *obj = DtoRVal(val);
371371
obj = DtoBitCast(obj, funcTy->getParamType(0));
@@ -397,12 +397,12 @@ DValue *DtoDynamicCastInterface(Loc &loc, DValue *val, Type *_to) {
397397
// call:
398398
// Object _d_interface_cast(void* p, ClassInfo c)
399399

400-
resolveObjectAndClassInfoClasses();
401-
402400
llvm::Function *func =
403401
getRuntimeFunction(loc, gIR->module, "_d_interface_cast");
404402
LLFunctionType *funcTy = func->getFunctionType();
405403

404+
resolveObjectAndClassInfoClasses();
405+
406406
// void* p
407407
LLValue *ptr = DtoRVal(val);
408408
ptr = DtoBitCast(ptr, funcTy->getParamType(0));

gen/trycatchfinally.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
8181
const bool isCPPclass = cd->isCPPclass();
8282

8383
const auto enterCatchFn = getRuntimeFunction(
84-
Loc(), irs.module,
84+
c->loc, irs.module,
8585
isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch");
8686
const auto ptr = DtoLoad(ehPtrSlot);
8787
const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr);
@@ -273,7 +273,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
273273
irs.funcGen().pgo.emitCounterIncrement(ctch);
274274
if (!isCPPclass) {
275275
auto enterCatchFn =
276-
getRuntimeFunction(Loc(), irs.module, "_d_eh_enter_catch");
276+
getRuntimeFunction(ctch->loc, irs.module, "_d_eh_enter_catch");
277277
irs.CreateCallOrInvoke(enterCatchFn, DtoBitCast(exnObj, getVoidPtrType()),
278278
clssInfo);
279279
}
@@ -320,7 +320,7 @@ void TryCatchScope::emitCatchBodiesMSVC(IRState &irs, llvm::Value *) {
320320
if (!irs.func()->hasLLVMPersonalityFn()) {
321321
const char *personality = "__CxxFrameHandler3";
322322
irs.func()->setLLVMPersonalityFn(
323-
getRuntimeFunction(Loc(), irs.module, personality));
323+
getRuntimeFunction(stmt->loc, irs.module, personality));
324324
}
325325
}
326326

0 commit comments

Comments
 (0)