Lookup runtime function before constructing the call args

To retain the LoC information in case TypeInfo declarations are missing.
This commit is contained in:
Martin 2018-04-02 01:00:47 +02:00
parent 4c1154703e
commit 9ff736bf0f
3 changed files with 17 additions and 17 deletions

View file

@ -674,13 +674,6 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
IF_LOG Logger::println("DtoNewDynArray : %s", arrayType->toChars());
LOG_SCOPE;
// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
// dim arg
assert(DtoType(dim->type) == DtoSize_t());
LLValue *arrayLen = DtoRVal(dim);
// get runtime function
Type *eltType = arrayType->toBasetype()->nextOf();
bool zeroInit = eltType->isZeroInit();
@ -690,6 +683,13 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
: "_d_newarrayU";
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
// dim arg
assert(DtoType(dim->type) == DtoSize_t());
LLValue *arrayLen = DtoRVal(dim);
// call allocator
LLValue *newArray =
gIR->CreateCallOrInvoke(fn, arrayTypeInfo, arrayLen, ".gc_mem")
@ -704,9 +704,6 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
LOG_SCOPE;
// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
// get value type
Type *vtype = arrayType->toBasetype();
for (size_t i = 0; i < ndims; ++i) {
@ -718,6 +715,9 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
// Check if constant
bool allDimsConst = true;
for (size_t i = 0; i < ndims; ++i) {

View file

@ -360,12 +360,12 @@ DValue *DtoDynamicCastObject(Loc &loc, DValue *val, Type *_to) {
// call:
// Object _d_dynamic_cast(Object o, ClassInfo c)
resolveObjectAndClassInfoClasses();
llvm::Function *func =
getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
LLFunctionType *funcTy = func->getFunctionType();
resolveObjectAndClassInfoClasses();
// Object o
LLValue *obj = DtoRVal(val);
obj = DtoBitCast(obj, funcTy->getParamType(0));
@ -397,12 +397,12 @@ DValue *DtoDynamicCastInterface(Loc &loc, DValue *val, Type *_to) {
// call:
// Object _d_interface_cast(void* p, ClassInfo c)
resolveObjectAndClassInfoClasses();
llvm::Function *func =
getRuntimeFunction(loc, gIR->module, "_d_interface_cast");
LLFunctionType *funcTy = func->getFunctionType();
resolveObjectAndClassInfoClasses();
// void* p
LLValue *ptr = DtoRVal(val);
ptr = DtoBitCast(ptr, funcTy->getParamType(0));

View file

@ -81,7 +81,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) {
const bool isCPPclass = cd->isCPPclass();
const auto enterCatchFn = getRuntimeFunction(
Loc(), irs.module,
c->loc, irs.module,
isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch");
const auto ptr = DtoLoad(ehPtrSlot);
const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr);
@ -273,7 +273,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
irs.funcGen().pgo.emitCounterIncrement(ctch);
if (!isCPPclass) {
auto enterCatchFn =
getRuntimeFunction(Loc(), irs.module, "_d_eh_enter_catch");
getRuntimeFunction(ctch->loc, irs.module, "_d_eh_enter_catch");
irs.CreateCallOrInvoke(enterCatchFn, DtoBitCast(exnObj, getVoidPtrType()),
clssInfo);
}
@ -320,7 +320,7 @@ void TryCatchScope::emitCatchBodiesMSVC(IRState &irs, llvm::Value *) {
if (!irs.func()->hasLLVMPersonalityFn()) {
const char *personality = "__CxxFrameHandler3";
irs.func()->setLLVMPersonalityFn(
getRuntimeFunction(Loc(), irs.module, personality));
getRuntimeFunction(stmt->loc, irs.module, personality));
}
}