mirror of
https://github.com/corda/corda.git
synced 2025-01-31 16:35:43 +00:00
don't abort when compiling an array lookup with a constant negative index
Instead, just compile it as a direct call to the thunk which throws an ArrayIndexOutOfBoundsException.
This commit is contained in:
parent
ebc54c234f
commit
e75b57a127
@ -4865,12 +4865,13 @@ class BoundsCheckEvent: public Event {
|
|||||||
Assembler* a = c->assembler;
|
Assembler* a = c->assembler;
|
||||||
|
|
||||||
ConstantSite* constant = findConstantSite(c, index);
|
ConstantSite* constant = findConstantSite(c, index);
|
||||||
CodePromise* nextPromise = codePromise
|
|
||||||
(c, static_cast<Promise*>(0));
|
|
||||||
CodePromise* outOfBoundsPromise = 0;
|
CodePromise* outOfBoundsPromise = 0;
|
||||||
|
|
||||||
if (constant) {
|
if (constant) {
|
||||||
expect(c, constant->value->value() >= 0);
|
if (constant->value->value() < 0) {
|
||||||
|
Assembler::Constant handlerConstant(resolved(c, handler));
|
||||||
|
a->apply(Call, BytesPerWord, ConstantOperand, &handlerConstant);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
outOfBoundsPromise = codePromise(c, static_cast<Promise*>(0));
|
outOfBoundsPromise = codePromise(c, static_cast<Promise*>(0));
|
||||||
|
|
||||||
@ -4880,24 +4881,29 @@ class BoundsCheckEvent: public Event {
|
|||||||
BytesPerWord, &oob, &oob);
|
BytesPerWord, &oob, &oob);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(c, object->source->type(c) == RegisterOperand);
|
if (constant == 0 or constant->value->value() >= 0) {
|
||||||
MemorySite length(static_cast<RegisterSite*>(object->source)->number,
|
assert(c, object->source->type(c) == RegisterOperand);
|
||||||
lengthOffset, NoRegister, 1);
|
MemorySite length(static_cast<RegisterSite*>(object->source)->number,
|
||||||
length.acquired = true;
|
lengthOffset, NoRegister, 1);
|
||||||
|
length.acquired = true;
|
||||||
|
|
||||||
ConstantSite next(nextPromise);
|
CodePromise* nextPromise = codePromise
|
||||||
apply(c, JumpIfGreater, 4, index->source, index->source, 4, &length,
|
(c, static_cast<Promise*>(0));
|
||||||
&length, BytesPerWord, &next, &next);
|
|
||||||
|
|
||||||
if (constant == 0) {
|
ConstantSite next(nextPromise);
|
||||||
outOfBoundsPromise->offset = a->offset();
|
apply(c, JumpIfGreater, 4, index->source, index->source, 4, &length,
|
||||||
|
&length, BytesPerWord, &next, &next);
|
||||||
|
|
||||||
|
if (constant == 0) {
|
||||||
|
outOfBoundsPromise->offset = a->offset();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assembler::Constant handlerConstant(resolved(c, handler));
|
||||||
|
a->apply(Call, BytesPerWord, ConstantOperand, &handlerConstant);
|
||||||
|
|
||||||
|
nextPromise->offset = a->offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assembler::Constant handlerConstant(resolved(c, handler));
|
|
||||||
a->apply(Call, BytesPerWord, ConstantOperand, &handlerConstant);
|
|
||||||
|
|
||||||
nextPromise->offset = a->offset();
|
|
||||||
|
|
||||||
popRead(c, this, object);
|
popRead(c, this, object);
|
||||||
popRead(c, this, index);
|
popRead(c, this, index);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,17 @@ public class Arrays {
|
|||||||
expect(exception != null);
|
expect(exception != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ int[] array = new int[0];
|
||||||
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
int x = array[-1];
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
exception = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(exception != null);
|
||||||
|
}
|
||||||
|
|
||||||
{ int[] array = new int[3];
|
{ int[] array = new int[3];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
array[i++] = 1;
|
array[i++] = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user