Skip to content

Commit

Permalink
Fix bounds checking for 16-bit targets
Browse files Browse the repository at this point in the history
  • Loading branch information
luismarques committed Jan 21, 2018
1 parent c8625c4 commit 62f693a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gen/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,9 @@ void DtoIndexBoundsCheck(Loc &loc, DValue *arr, DValue *index) {
}

llvm::ICmpInst::Predicate cmpop = llvm::ICmpInst::ICMP_ULT;
llvm::Value *cond = gIR->ir->CreateICmp(cmpop, DtoRVal(index),
llvm::Value *cond = gIR->ir->CreateICmp(cmpop,
gIR->ir->CreateTrunc(DtoRVal(index),
DtoSize_t()),
DtoArrayLen(arr), "bounds.cmp");

llvm::BasicBlock *okbb = gIR->insertBB("bounds.ok");
Expand Down
20 changes: 20 additions & 0 deletions tests/compilable/bounds_16_bit.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// REQUIRES: target_MSP430

// RUN: %ldc -mtriple=msp430 -c -output-ll %s

void test()
{
int[1] array;

ushort i = 0;
auto value = array[i];

short j = 0;
value = array[j];

uint k = 0;
value = array[k];

int l = 0;
value = array[l];
}

0 comments on commit 62f693a

Please sign in to comment.