Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing location information for error reporting of TypeInfo in b… #3632

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions gen/aa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
#include "ir/irmodule.h"

// returns the keytype typeinfo
static LLConstant *to_keyti(DValue *aa, LLType *targetType) {
static LLConstant *to_keyti(const Loc &loc, DValue *aa, LLType *targetType) {
// keyti param
assert(aa->type->toBasetype()->ty == Taarray);
TypeAArray *aatype = static_cast<TypeAArray *>(aa->type->toBasetype());
LLConstant *ti = DtoTypeInfoOf(aatype->index, /*base=*/false);
LLConstant *ti = DtoTypeInfoOf(loc, aatype->index, /*base=*/false);
return DtoBitCast(ti, targetType);
}

////////////////////////////////////////////////////////////////////////////////

DLValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key,
DLValue *DtoAAIndex(const Loc &loc, Type *type, DValue *aa, DValue *key,
bool lvalue) {
// D2:
// call:
Expand All @@ -61,13 +61,13 @@ DLValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key,
LLValue *ret;
if (lvalue) {
LLValue *rawAATI =
DtoTypeInfoOf(aa->type->unSharedOf()->mutableOf(), /*base=*/false);
DtoTypeInfoOf(loc, aa->type->unSharedOf()->mutableOf(), /*base=*/false);
LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1));
LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type)));
ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey,
"aa.index");
} else {
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1));
LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));
ret = gIR->CreateCallOrInvoke(func, aaval, keyti, pkey, "aa.index");
}

Expand Down Expand Up @@ -101,7 +101,7 @@ DLValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key,

////////////////////////////////////////////////////////////////////////////////

DValue *DtoAAIn(Loc &loc, Type *type, DValue *aa, DValue *key) {
DValue *DtoAAIn(const Loc &loc, Type *type, DValue *aa, DValue *key) {
// D1:
// call:
// extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
Expand All @@ -125,7 +125,7 @@ DValue *DtoAAIn(Loc &loc, Type *type, DValue *aa, DValue *key) {
aaval = DtoBitCast(aaval, funcTy->getParamType(0));

// keyti param
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1));
LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));

// pkey param
LLValue *pkey = makeLValue(loc, key);
Expand All @@ -145,7 +145,7 @@ DValue *DtoAAIn(Loc &loc, Type *type, DValue *aa, DValue *key) {

////////////////////////////////////////////////////////////////////////////////

DValue *DtoAARemove(Loc &loc, DValue *aa, DValue *key) {
DValue *DtoAARemove(const Loc &loc, DValue *aa, DValue *key) {
// D1:
// call:
// extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey)
Expand All @@ -169,7 +169,7 @@ DValue *DtoAARemove(Loc &loc, DValue *aa, DValue *key) {
aaval = DtoBitCast(aaval, funcTy->getParamType(0));

// keyti param
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1));
LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));

// pkey param
LLValue *pkey = makeLValue(loc, key);
Expand All @@ -183,7 +183,7 @@ DValue *DtoAARemove(Loc &loc, DValue *aa, DValue *key) {

////////////////////////////////////////////////////////////////////////////////

LLValue *DtoAAEquals(Loc &loc, TOK op, DValue *l, DValue *r) {
LLValue *DtoAAEquals(const Loc &loc, TOK op, DValue *l, DValue *r) {
Type *t = l->type->toBasetype();
assert(t == r->type->toBasetype() &&
"aa equality is only defined for aas of same type");
Expand All @@ -192,7 +192,7 @@ LLValue *DtoAAEquals(Loc &loc, TOK op, DValue *l, DValue *r) {

LLValue *aaval = DtoBitCast(DtoRVal(l), funcTy->getParamType(1));
LLValue *abval = DtoBitCast(DtoRVal(r), funcTy->getParamType(2));
LLValue *aaTypeInfo = DtoTypeInfoOf(t);
LLValue *aaTypeInfo = DtoTypeInfoOf(loc, t);
LLValue *res =
gIR->CreateCallOrInvoke(func, aaTypeInfo, aaval, abval, "aaEqRes");

Expand Down
9 changes: 5 additions & 4 deletions gen/aa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace llvm {
class Value;
}

DLValue *DtoAAIndex(Loc &loc, Type *type, DValue *aa, DValue *key, bool lvalue);
DValue *DtoAAIn(Loc &loc, Type *type, DValue *aa, DValue *key);
DValue *DtoAARemove(Loc &loc, DValue *aa, DValue *key);
llvm::Value *DtoAAEquals(Loc &loc, TOK op, DValue *l, DValue *r);
DLValue *DtoAAIndex(const Loc &loc, Type *type, DValue *aa, DValue *key,
bool lvalue);
DValue *DtoAAIn(const Loc &loc, Type *type, DValue *aa, DValue *key);
DValue *DtoAARemove(const Loc &loc, DValue *aa, DValue *key);
llvm::Value *DtoAAEquals(const Loc &loc, TOK op, DValue *l, DValue *r);
72 changes: 37 additions & 35 deletions gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void DtoSetArrayToNull(LLValue *v) {

////////////////////////////////////////////////////////////////////////////////

static void DtoArrayInit(Loc &loc, LLValue *ptr, LLValue *length,
static void DtoArrayInit(const Loc &loc, LLValue *ptr, LLValue *length,
DValue *elementValue) {
IF_LOG Logger::println("DtoArrayInit");
LOG_SCOPE;
Expand Down Expand Up @@ -193,8 +193,9 @@ static LLValue *computeSize(LLValue *length, size_t elementSize) {
: gIR->ir->CreateMul(length, DtoConstSize_t(elementSize));
};

static void copySlice(Loc &loc, LLValue *dstarr, LLValue *dstlen, LLValue *srcarr,
LLValue *srclen, size_t elementSize, bool knownInBounds) {
static void copySlice(const Loc &loc, LLValue *dstarr, LLValue *dstlen,
LLValue *srcarr, LLValue *srclen, size_t elementSize,
bool knownInBounds) {
const bool checksEnabled =
global.params.useAssert == CHECKENABLEon || gIR->emitArrayBoundsChecks();
if (checksEnabled && !knownInBounds) {
Expand Down Expand Up @@ -224,7 +225,7 @@ static bool arrayNeedsPostblit(Type *t) {

// Does array assignment (or initialization) from another array of the same
// element type or from an appropriate single element.
void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, int op,
bool canSkipPostblit) {
IF_LOG Logger::println("DtoArrayAssign");
LOG_SCOPE;
Expand Down Expand Up @@ -293,17 +294,16 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
}
} else if (isConstructing) {
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayctor");
gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(elemType),
gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(loc, elemType),
DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength));
} else // assigning
{
} else { // assigning
LLValue *tmpSwap = DtoAlloca(elemType, "arrayAssign.tmpSwap");
LLFunction *fn = getRuntimeFunction(
loc, gIR->module,
!canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r");
gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(elemType), DtoSlice(rhsPtr, rhsLength),
fn, DtoTypeInfoOf(loc, elemType), DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength), DtoBitCast(tmpSwap, getVoidPtrType()));
}
} else {
Expand Down Expand Up @@ -337,7 +337,7 @@ void DtoArrayAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
fn, lhsPtr, DtoBitCast(makeLValue(loc, rhs), getVoidPtrType()),
gIR->ir->CreateTruncOrBitCast(lhsLength,
LLType::getInt32Ty(gIR->context())),
DtoTypeInfoOf(stripModifiers(t2)));
DtoTypeInfoOf(loc, stripModifiers(t2)));
}
}
}
Expand Down Expand Up @@ -675,7 +675,7 @@ static DSliceValue *getSlice(Type *arrayType, LLValue *array) {
}

////////////////////////////////////////////////////////////////////////////////
DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
bool defaultInit) {
IF_LOG Logger::println("DtoNewDynArray : %s", arrayType->toChars());
LOG_SCOPE;
Expand All @@ -693,7 +693,7 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
LLValue *arrayTypeInfo = DtoTypeInfoOf(loc, arrayType);

// dim arg
assert(DtoType(dim->type) == DtoSize_t());
Expand All @@ -710,8 +710,8 @@ DSliceValue *DtoNewDynArray(Loc &loc, Type *arrayType, DValue *dim,
}

////////////////////////////////////////////////////////////////////////////////
DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
size_t ndims) {
DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
DValue **dims, size_t ndims) {
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
LOG_SCOPE;

Expand All @@ -727,7 +727,7 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);

// typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType);
LLValue *arrayTypeInfo = DtoTypeInfoOf(loc, arrayType);

// Check if constant
bool allDimsConst = true;
Expand Down Expand Up @@ -778,7 +778,7 @@ DSliceValue *DtoNewMulDimDynArray(Loc &loc, Type *arrayType, DValue **dims,
}

////////////////////////////////////////////////////////////////////////////////
DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,
DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
LLValue *newdim) {
IF_LOG Logger::println("DtoResizeDynArray : %s", arrayType->toChars());
LOG_SCOPE;
Expand All @@ -798,7 +798,7 @@ DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,
: "_d_arraysetlengthiT");

LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType), newdim,
fn, DtoTypeInfoOf(loc, arrayType), newdim,
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)),
".gc_mem");

Expand All @@ -807,7 +807,7 @@ DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,

////////////////////////////////////////////////////////////////////////////////

void DtoCatAssignElement(Loc &loc, DValue *array, Expression *exp) {
void DtoCatAssignElement(const Loc &loc, DValue *array, Expression *exp) {
IF_LOG Logger::println("DtoCatAssignElement");
LOG_SCOPE;

Expand All @@ -822,7 +822,7 @@ void DtoCatAssignElement(Loc &loc, DValue *array, Expression *exp) {
// potentially moved to a new block).
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType),
fn, DtoTypeInfoOf(loc, arrayType),
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)),
DtoConstSize_t(1), ".appendedArray");

Expand All @@ -839,15 +839,15 @@ void DtoCatAssignElement(Loc &loc, DValue *array, Expression *exp) {

////////////////////////////////////////////////////////////////////////////////

DSliceValue *DtoCatAssignArray(Loc &loc, DValue *arr, Expression *exp) {
DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp) {
IF_LOG Logger::println("DtoCatAssignArray");
LOG_SCOPE;
Type *arrayType = arr->type;

LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
// Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y)
LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType),
fn, DtoTypeInfoOf(loc, arrayType),
DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)),
DtoAggrPaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)),
".appendedArray");
Expand All @@ -857,7 +857,7 @@ DSliceValue *DtoCatAssignArray(Loc &loc, DValue *arr, Expression *exp) {

////////////////////////////////////////////////////////////////////////////////

DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,
DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1,
Expression *exp2) {
IF_LOG Logger::println("DtoCatAssignArray");
LOG_SCOPE;
Expand Down Expand Up @@ -901,14 +901,14 @@ DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,
LLType::getInt8Ty(gIR->context()))))));

// TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType));
args.push_back(DtoTypeInfoOf(loc, arrayType));
// byte[][] arrs
args.push_back(val);
} else {
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT");

// TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType));
args.push_back(DtoTypeInfoOf(loc, arrayType));
// byte[] x
LLValue *val = DtoLoad(DtoSlicePtr(exp1));
val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1));
Expand All @@ -925,7 +925,7 @@ DSliceValue *DtoCatArrays(Loc &loc, Type *arrayType, Expression *exp1,

////////////////////////////////////////////////////////////////////////////////

DSliceValue *DtoAppendDChar(Loc &loc, DValue *arr, Expression *exp,
DSliceValue *DtoAppendDChar(const Loc &loc, DValue *arr, Expression *exp,
const char *func) {
LLValue *valueToAppend = DtoRVal(exp);

Expand All @@ -943,15 +943,16 @@ DSliceValue *DtoAppendDChar(Loc &loc, DValue *arr, Expression *exp,

////////////////////////////////////////////////////////////////////////////////

DSliceValue *DtoAppendDCharToString(Loc &loc, DValue *arr, Expression *exp) {
DSliceValue *DtoAppendDCharToString(const Loc &loc, DValue *arr,
Expression *exp) {
IF_LOG Logger::println("DtoAppendDCharToString");
LOG_SCOPE;
return DtoAppendDChar(loc, arr, exp, "_d_arrayappendcd");
}

////////////////////////////////////////////////////////////////////////////////

DSliceValue *DtoAppendDCharToUnicodeString(Loc &loc, DValue *arr,
DSliceValue *DtoAppendDCharToUnicodeString(const Loc &loc, DValue *arr,
Expression *exp) {
IF_LOG Logger::println("DtoAppendDCharToUnicodeString");
LOG_SCOPE;
Expand All @@ -961,8 +962,8 @@ DSliceValue *DtoAppendDCharToUnicodeString(Loc &loc, DValue *arr,
////////////////////////////////////////////////////////////////////////////////
namespace {
// helper for eq and cmp
LLValue *DtoArrayEqCmp_impl(Loc &loc, const char *func, DValue *l,
DValue *r, bool useti) {
LLValue *DtoArrayEqCmp_impl(const Loc &loc, const char *func, DValue *l,
DValue *r, bool useti) {
IF_LOG Logger::println("comparing arrays");
LLFunction *fn = getRuntimeFunction(loc, gIR->module, func);
assert(fn);
Expand All @@ -985,7 +986,7 @@ LLValue *DtoArrayEqCmp_impl(Loc &loc, const char *func, DValue *l,

// pass array typeinfo ?
if (useti) {
LLValue *tival = DtoTypeInfoOf(l->type);
LLValue *tival = DtoTypeInfoOf(loc, l->type);
args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2)));
}

Expand Down Expand Up @@ -1054,7 +1055,7 @@ bool validCompareWithMemcmp(DValue *l, DValue *r) {
}

// Create a call instruction to memcmp.
llvm::CallInst *callMemcmp(Loc &loc, IRState &irs, LLValue *l_ptr,
llvm::CallInst *callMemcmp(const Loc &loc, IRState &irs, LLValue *l_ptr,
LLValue *r_ptr, LLValue *numElements) {
assert(l_ptr && r_ptr && numElements);
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "memcmp");
Expand All @@ -1076,7 +1077,8 @@ llvm::CallInst *callMemcmp(Loc &loc, IRState &irs, LLValue *l_ptr,
/// with memcmp.
///
/// Note: the dynamic array length check is not covered by (LDC's) PGO.
LLValue *DtoArrayEqCmp_memcmp(Loc &loc, DValue *l, DValue *r, IRState &irs) {
LLValue *DtoArrayEqCmp_memcmp(const Loc &loc, DValue *l, DValue *r,
IRState &irs) {
IF_LOG Logger::println("Comparing arrays using memcmp");

auto *l_ptr = DtoArrayPtr(l);
Expand Down Expand Up @@ -1120,7 +1122,7 @@ LLValue *DtoArrayEqCmp_memcmp(Loc &loc, DValue *l, DValue *r, IRState &irs) {
} // end anonymous namespace

////////////////////////////////////////////////////////////////////////////////
LLValue *DtoArrayEquals(Loc &loc, TOK op, DValue *l, DValue *r) {
LLValue *DtoArrayEquals(const Loc &loc, TOK op, DValue *l, DValue *r) {
LLValue *res = nullptr;

if (r->isNull()) {
Expand Down Expand Up @@ -1216,7 +1218,7 @@ LLValue *DtoArrayPtr(DValue *v) {
}

////////////////////////////////////////////////////////////////////////////////
DValue *DtoCastArray(Loc &loc, DValue *u, Type *to) {
DValue *DtoCastArray(const Loc &loc, DValue *u, Type *to) {
IF_LOG Logger::println("DtoCastArray");
LOG_SCOPE;

Expand Down Expand Up @@ -1309,7 +1311,7 @@ DValue *DtoCastArray(Loc &loc, DValue *u, Type *to) {
return new DLValue(to, castedPtr);
}

void DtoIndexBoundsCheck(Loc &loc, DValue *arr, DValue *index) {
void DtoIndexBoundsCheck(const Loc &loc, DValue *arr, DValue *index) {
Type *arrty = arr->type->toBasetype();
assert(
(arrty->ty == Tsarray || arrty->ty == Tarray || arrty->ty == Tpointer) &&
Expand Down Expand Up @@ -1341,7 +1343,7 @@ void DtoIndexBoundsCheck(Loc &loc, DValue *arr, DValue *index) {
gIR->ir->SetInsertPoint(okbb);
}

void DtoBoundsCheckFailCall(IRState *irs, Loc &loc) {
void DtoBoundsCheckFailCall(IRState *irs, const Loc &loc) {
Module *const module = irs->func()->decl->getModule();

if (global.params.checkAction == CHECKACTION_C) {
Expand Down
Loading