Skip to content

Commit dd3cc5f

Browse files
committed
Fix for issue #553.
This version uses the skipboundscheck member variable.
1 parent 2188ef9 commit dd3cc5f

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

gen/arrays.cpp

+2-18
Original file line numberDiff line numberDiff line change
@@ -1135,24 +1135,8 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun
11351135
assert((arrty->ty == Tsarray || arrty->ty == Tarray || arrty->ty == Tpointer) &&
11361136
"Can only array bounds check for static or dynamic arrays");
11371137

1138-
// Do not emit bounds check code if the index is statically known to be
1139-
// within bounds.
1140-
if (arrty->ty == Tsarray && isaConstantInt(index->getRVal())) {
1141-
assert(!arr->isSlice());
1142-
assert(!arr->isNull());
1143-
assert(!lowerBound);
1144-
1145-
TypeSArray *sarray = static_cast<TypeSArray*>(arrty);
1146-
llvm::ConstantInt *constIndex = static_cast<llvm::ConstantInt*>(index->getRVal());
1147-
if (sarray->dim->toUInteger() < constIndex->getZExtValue()) {
1148-
// If this happens then it is possible a frontend bug.
1149-
// Just output a warning and continue generating a runtime check.
1150-
// This could be generic code which is never executed.
1151-
warning(loc, "Static array index out of bounds (should have been detected during semantic analysis)");
1152-
}
1153-
else
1154-
return ;
1155-
}
1138+
// We do not check if the bounds check can be omitted. This is the
1139+
// responsibility of the caller and performed in IndexExp::toElem().
11561140

11571141
// runtime check
11581142

gen/toir.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1715,12 +1715,12 @@ DValue* IndexExp::toElem(IRState* p)
17151715
arrptr = DtoGEP1(l->getRVal(),r->getRVal());
17161716
}
17171717
else if (e1type->ty == Tsarray) {
1718-
if (gIR->emitArrayBoundsChecks())
1718+
if (gIR->emitArrayBoundsChecks() && !skipboundscheck)
17191719
DtoArrayBoundsCheck(loc, l, r);
17201720
arrptr = DtoGEP(l->getRVal(), zero, r->getRVal());
17211721
}
17221722
else if (e1type->ty == Tarray) {
1723-
if (gIR->emitArrayBoundsChecks())
1723+
if (gIR->emitArrayBoundsChecks() && !skipboundscheck)
17241724
DtoArrayBoundsCheck(loc, l, r);
17251725
arrptr = DtoArrayPtr(l);
17261726
arrptr = DtoGEP1(arrptr,r->getRVal());

0 commit comments

Comments
 (0)