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

View file

@ -360,12 +360,12 @@ DValue *DtoDynamicCastObject(Loc &loc, DValue *val, Type *_to) {
// call: // call:
// Object _d_dynamic_cast(Object o, ClassInfo c) // Object _d_dynamic_cast(Object o, ClassInfo c)
resolveObjectAndClassInfoClasses();
llvm::Function *func = llvm::Function *func =
getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast"); getRuntimeFunction(loc, gIR->module, "_d_dynamic_cast");
LLFunctionType *funcTy = func->getFunctionType(); LLFunctionType *funcTy = func->getFunctionType();
resolveObjectAndClassInfoClasses();
// Object o // Object o
LLValue *obj = DtoRVal(val); LLValue *obj = DtoRVal(val);
obj = DtoBitCast(obj, funcTy->getParamType(0)); obj = DtoBitCast(obj, funcTy->getParamType(0));
@ -397,12 +397,12 @@ DValue *DtoDynamicCastInterface(Loc &loc, DValue *val, Type *_to) {
// call: // call:
// Object _d_interface_cast(void* p, ClassInfo c) // Object _d_interface_cast(void* p, ClassInfo c)
resolveObjectAndClassInfoClasses();
llvm::Function *func = llvm::Function *func =
getRuntimeFunction(loc, gIR->module, "_d_interface_cast"); getRuntimeFunction(loc, gIR->module, "_d_interface_cast");
LLFunctionType *funcTy = func->getFunctionType(); LLFunctionType *funcTy = func->getFunctionType();
resolveObjectAndClassInfoClasses();
// void* p // void* p
LLValue *ptr = DtoRVal(val); LLValue *ptr = DtoRVal(val);
ptr = DtoBitCast(ptr, funcTy->getParamType(0)); 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 bool isCPPclass = cd->isCPPclass();
const auto enterCatchFn = getRuntimeFunction( const auto enterCatchFn = getRuntimeFunction(
Loc(), irs.module, c->loc, irs.module,
isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch"); isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch");
const auto ptr = DtoLoad(ehPtrSlot); const auto ptr = DtoLoad(ehPtrSlot);
const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr); const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr);
@ -273,7 +273,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch,
irs.funcGen().pgo.emitCounterIncrement(ctch); irs.funcGen().pgo.emitCounterIncrement(ctch);
if (!isCPPclass) { if (!isCPPclass) {
auto enterCatchFn = 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()), irs.CreateCallOrInvoke(enterCatchFn, DtoBitCast(exnObj, getVoidPtrType()),
clssInfo); clssInfo);
} }
@ -320,7 +320,7 @@ void TryCatchScope::emitCatchBodiesMSVC(IRState &irs, llvm::Value *) {
if (!irs.func()->hasLLVMPersonalityFn()) { if (!irs.func()->hasLLVMPersonalityFn()) {
const char *personality = "__CxxFrameHandler3"; const char *personality = "__CxxFrameHandler3";
irs.func()->setLLVMPersonalityFn( irs.func()->setLLVMPersonalityFn(
getRuntimeFunction(Loc(), irs.module, personality)); getRuntimeFunction(stmt->loc, irs.module, personality));
} }
} }