Fix missing location information for error reporting of TypeInfo in betterC

This fixes an issue where any instantiation of TypeInfo in the final
output would lead to a cryptic error with no file or line information.
This change brings ldc in line with dmd's reporting of the same error,
which at least gives file and line information to discover the problem.
This commit is contained in:
DaveP1776 2020-12-12 22:41:21 -05:00
parent cfb36ded90
commit 3f9d05ac16
7 changed files with 24 additions and 24 deletions

View file

@ -61,7 +61,7 @@ DLValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key,
LLValue *ret; LLValue *ret;
if (lvalue) { if (lvalue) {
LLValue *rawAATI = LLValue *rawAATI =
DtoTypeInfoOf(aa->type->unSharedOf()->mutableOf(), /*base=*/false); DtoTypeInfoOf(aa->type->unSharedOf()->mutableOf(), /*base=*/false, loc);
LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1)); LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1));
LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type))); LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type)));
ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey, ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey,
@ -192,7 +192,7 @@ LLValue *DtoAAEquals(Loc &loc, TOK op, DValue *l, DValue *r) {
LLValue *aaval = DtoBitCast(DtoRVal(l), funcTy->getParamType(1)); LLValue *aaval = DtoBitCast(DtoRVal(l), funcTy->getParamType(1));
LLValue *abval = DtoBitCast(DtoRVal(r), funcTy->getParamType(2)); LLValue *abval = DtoBitCast(DtoRVal(r), funcTy->getParamType(2));
LLValue *aaTypeInfo = DtoTypeInfoOf(t); LLValue *aaTypeInfo = DtoTypeInfoOf(t, /*base=*/true, loc);
LLValue *res = LLValue *res =
gIR->CreateCallOrInvoke(func, aaTypeInfo, aaval, abval, "aaEqRes"); gIR->CreateCallOrInvoke(func, aaTypeInfo, aaval, abval, "aaEqRes");

View file

@ -293,7 +293,7 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
} }
} else if (isConstructing) { } else if (isConstructing) {
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayctor"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayctor");
gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(elemType), gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(elemType, /*base=*/true, loc),
DtoSlice(rhsPtr, rhsLength), DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength)); DtoSlice(lhsPtr, lhsLength));
} else // assigning } else // assigning
@ -303,7 +303,7 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
loc, gIR->module, loc, gIR->module,
!canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r"); !canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r");
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(elemType), DtoSlice(rhsPtr, rhsLength), fn, DtoTypeInfoOf(elemType, /*base=*/true, loc), DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength), DtoBitCast(tmpSwap, getVoidPtrType())); DtoSlice(lhsPtr, lhsLength), DtoBitCast(tmpSwap, getVoidPtrType()));
} }
} else { } else {
@ -337,7 +337,7 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
fn, lhsPtr, DtoBitCast(makeLValue(loc, rhs), getVoidPtrType()), fn, lhsPtr, DtoBitCast(makeLValue(loc, rhs), getVoidPtrType()),
gIR->ir->CreateTruncOrBitCast(lhsLength, gIR->ir->CreateTruncOrBitCast(lhsLength,
LLType::getInt32Ty(gIR->context())), LLType::getInt32Ty(gIR->context())),
DtoTypeInfoOf(stripModifiers(t2))); DtoTypeInfoOf(stripModifiers(t2), /*base=*/true, loc));
} }
} }
} }
@ -693,7 +693,7 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname); LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg // typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType); LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType, /*base=*/true, loc);
// dim arg // dim arg
assert(DtoType(dim->type) == DtoSize_t()); assert(DtoType(dim->type) == DtoSize_t());
@ -727,7 +727,7 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname); LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg // typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType); LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType, /*base=*/true, loc);
// Check if constant // Check if constant
bool allDimsConst = true; bool allDimsConst = true;
@ -798,7 +798,7 @@ DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,
: "_d_arraysetlengthiT"); : "_d_arraysetlengthiT");
LLValue *newArray = gIR->CreateCallOrInvoke( LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType), newdim, fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc), newdim,
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)), DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)),
".gc_mem"); ".gc_mem");
@ -822,7 +822,7 @@ void DtoCatAssignElement(Loc &loc, DValue *array, Expression *exp) {
// potentially moved to a new block). // potentially moved to a new block).
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType), fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc),
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)), DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)),
DtoConstSize_t(1), ".appendedArray"); DtoConstSize_t(1), ".appendedArray");
@ -847,7 +847,7 @@ DSliceValue *DtoCatAssignArray(Loc &loc, DValue *arr, Expression *exp) {
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
// Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y) // Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y)
LLValue *newArray = gIR->CreateCallOrInvoke( LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType), fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc),
DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)), DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)),
DtoAggrPaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)), DtoAggrPaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)),
".appendedArray"); ".appendedArray");
@ -901,14 +901,14 @@ DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,
LLType::getInt8Ty(gIR->context())))))); LLType::getInt8Ty(gIR->context()))))));
// TypeInfo ti // TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType)); args.push_back(DtoTypeInfoOf(arrayType, /*base=*/true, loc));
// byte[][] arrs // byte[][] arrs
args.push_back(val); args.push_back(val);
} else { } else {
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT"); fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT");
// TypeInfo ti // TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType)); args.push_back(DtoTypeInfoOf(arrayType, /*base=*/true, loc));
// byte[] x // byte[] x
LLValue *val = DtoLoad(DtoSlicePtr(exp1)); LLValue *val = DtoLoad(DtoSlicePtr(exp1));
val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1)); val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1));
@ -985,7 +985,7 @@ LLValue *DtoArrayEqCmp_impl(Loc &loc, const char *func, DValue *l,
// pass array typeinfo ? // pass array typeinfo ?
if (useti) { if (useti) {
LLValue *tival = DtoTypeInfoOf(l->type); LLValue *tival = DtoTypeInfoOf(l->type, /*base=*/true, loc);
args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2))); args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2)));
} }

View file

@ -82,7 +82,7 @@ LLValue *DtoNew(Loc &loc, Type *newtype) {
// get runtime function // get runtime function
llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_allocmemoryT"); llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_allocmemoryT");
// get type info // get type info
LLConstant *ti = DtoTypeInfoOf(newtype); LLConstant *ti = DtoTypeInfoOf(newtype, /*base=*/true, loc);
assert(isaPointer(ti)); assert(isaPointer(ti));
// call runtime allocator // call runtime allocator
LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem"); LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem");
@ -94,7 +94,7 @@ LLValue *DtoNewStruct(Loc &loc, TypeStruct *newtype) {
llvm::Function *fn = getRuntimeFunction( llvm::Function *fn = getRuntimeFunction(
loc, gIR->module, loc, gIR->module,
newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT"); newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT");
LLConstant *ti = DtoTypeInfoOf(newtype); LLConstant *ti = DtoTypeInfoOf(newtype, /*base=*/true, loc);
LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct"); LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct");
return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct"); return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct");
} }
@ -111,7 +111,7 @@ void DtoDeleteStruct(Loc &loc, DValue *ptr) {
LLValue *lval = (ptr->isLVal() ? DtoLVal(ptr) : makeLValue(loc, ptr)); LLValue *lval = (ptr->isLVal() ? DtoLVal(ptr) : makeLValue(loc, ptr));
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoBitCast(lval, fn->getFunctionType()->getParamType(0)), fn, DtoBitCast(lval, fn->getFunctionType()->getParamType(0)),
DtoBitCast(DtoTypeInfoOf(ptr->type->nextOf()), DtoBitCast(DtoTypeInfoOf(ptr->type->nextOf(), /*base=*/true, loc),
fn->getFunctionType()->getParamType(1))); fn->getFunctionType()->getParamType(1)));
} }
@ -138,7 +138,7 @@ void DtoDeleteArray(Loc &loc, DValue *arr) {
bool hasDtor = (elementType->toBasetype()->ty == Tstruct && bool hasDtor = (elementType->toBasetype()->ty == Tstruct &&
elementType->needsDestruction()); elementType->needsDestruction());
LLValue *typeInfo = (!hasDtor ? getNullPtr(fty->getParamType(1)) LLValue *typeInfo = (!hasDtor ? getNullPtr(fty->getParamType(1))
: DtoTypeInfoOf(elementType)); : DtoTypeInfoOf(elementType, /*base=*/true, loc));
LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr)); LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr));
gIR->CreateCallOrInvoke(fn, DtoBitCast(lval, fty->getParamType(0)), gIR->CreateCallOrInvoke(fn, DtoBitCast(lval, fty->getParamType(0)),
@ -1192,12 +1192,12 @@ LLConstant *DtoConstExpInit(Loc &loc, Type *targetType, Expression *exp) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
LLConstant *DtoTypeInfoOf(Type *type, bool base) { LLConstant *DtoTypeInfoOf(Type *type, bool base, const Loc& loc) {
IF_LOG Logger::println("DtoTypeInfoOf(type = '%s', base='%d')", IF_LOG Logger::println("DtoTypeInfoOf(type = '%s', base='%d')",
type->toChars(), base); type->toChars(), base);
LOG_SCOPE LOG_SCOPE
auto tidecl = getOrCreateTypeInfoDeclaration(Loc(), type); auto tidecl = getOrCreateTypeInfoDeclaration(loc, type);
auto tiglobal = DtoResolveTypeInfo(tidecl); auto tiglobal = DtoResolveTypeInfo(tidecl);
if (base) { if (base) {
return llvm::ConstantExpr::getBitCast(tiglobal, DtoType(getTypeInfoType())); return llvm::ConstantExpr::getBitCast(tiglobal, DtoType(getTypeInfoType()));

View file

@ -126,7 +126,7 @@ LLConstant *DtoConstInitializer(Loc &loc, Type *type,
LLConstant *DtoConstExpInit(Loc &loc, Type *targetType, Expression *exp); LLConstant *DtoConstExpInit(Loc &loc, Type *targetType, Expression *exp);
// getting typeinfo of type, base=true casts to object.TypeInfo // getting typeinfo of type, base=true casts to object.TypeInfo
LLConstant *DtoTypeInfoOf(Type *ty, bool base = true); LLConstant *DtoTypeInfoOf(Type *ty, bool base = true, const Loc& loc = Loc());
// target stuff // target stuff
void findDefaultTarget(); void findDefaultTarget();

View file

@ -250,7 +250,7 @@ static LLValue *getTypeinfoArrayArgumentForDVarArg(Expressions *argexps,
std::vector<LLConstant *> vtypeinfos; std::vector<LLConstant *> vtypeinfos;
vtypeinfos.reserve(numVariadicArgs); vtypeinfos.reserve(numVariadicArgs);
for (size_t i = begin; i < numArgExps; i++) { for (size_t i = begin; i < numArgExps; i++) {
vtypeinfos.push_back(DtoTypeInfoOf((*argexps)[i]->type)); vtypeinfos.push_back(DtoTypeInfoOf((*argexps)[i]->type, /*base=*/true, (*argexps)[i]->loc));
} }
// apply initializer // apply initializer

View file

@ -82,7 +82,7 @@ public:
} }
if (TypeInfoDeclaration *ti = e->var->isTypeInfoDeclaration()) { if (TypeInfoDeclaration *ti = e->var->isTypeInfoDeclaration()) {
result = DtoTypeInfoOf(ti->tinfo, false); result = DtoTypeInfoOf(ti->tinfo, false, e->loc);
result = DtoBitCast(result, DtoType(e->type)); result = DtoBitCast(result, DtoType(e->type));
return; return;
} }
@ -685,7 +685,7 @@ public:
return; return;
} }
result = DtoTypeInfoOf(t, /*base=*/false); result = DtoTypeInfoOf(t, /*base=*/false, e->loc);
result = DtoBitCast(result, DtoType(e->type)); result = DtoBitCast(result, DtoType(e->type));
} }

View file

@ -2403,7 +2403,7 @@ public:
getRuntimeFunction(e->loc, gIR->module, "_d_assocarrayliteralTX"); getRuntimeFunction(e->loc, gIR->module, "_d_assocarrayliteralTX");
LLFunctionType *funcTy = func->getFunctionType(); LLFunctionType *funcTy = func->getFunctionType();
LLValue *aaTypeInfo = LLValue *aaTypeInfo =
DtoBitCast(DtoTypeInfoOf(stripModifiers(aatype), /*base=*/false), DtoBitCast(DtoTypeInfoOf(stripModifiers(aatype), /*base=*/false, e->loc),
DtoType(getAssociativeArrayTypeInfoType())); DtoType(getAssociativeArrayTypeInfoType()));
LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)}; LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)};