Skip to content

Commit

Permalink
Fix Pointer.atContents for off-heap ranges (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer authored Jan 3, 2025
1 parent 923c022 commit c887bea
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aeneas/src/ir/SsaNormalizer.v3
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ class SsaRaNormalizer extends SsaRebuilder {
var narr = ai_new[0], start = ai_new[rn.startIndex()],
length = ai_new[rn.lengthIndex()], index = ai_new[rn.lengthIndex() + 1];
var arrayType = ArrayType.!(rn.sub[0]), ptrType = op.sig.returnType();
addNullCheck(i_old, narr);
if (context.compiler.boundsCheck(i_old.facts)) {
var c1 = curBlock.opU32LtEq(length, index);
curBlock.opConditionalThrow(V3Exception.BoundsCheck, c1);
Expand All @@ -515,6 +514,7 @@ class SsaRaNormalizer extends SsaRebuilder {
var nstart = rangeStartAdd(start, index);
var op = V3Op.newPtrAtArrayElem(arrayType, norm.config.RangeStartType, ptrType);
i_new = curBlock.addApply(curBlock.source, op, [narr, nstart]);
i_new.facts |= Fact.O_NO_NULL_CHECK;
}
i_new.facts |= Fact.O_NO_BOUNDS_CHECK;
map1(i_old, i_new);
Expand Down
1 change: 1 addition & 0 deletions aeneas/src/mach/CiRuntime.v3
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CiRuntime_TypeCon extends Member_TypeCon {
if (Strings.equal(name, "unpackClosure")) return LookupResult.Inst(V3Op.newUnpackClosure(ptrType, C, P, R), TYPE_PARAMS);
var tp = TypeUtil.ONE_TYPE_PARAM.head;
if (Strings.equal(name, "forgeRange")) return LookupResult.Inst(V3Op.newForgeRange(tp, ptrType), TypeUtil.ONE_TYPE_PARAM);
if (Strings.equal(name, "STACK_SIZE")) return LookupResult.Const(Int.TYPE, Int.box(int.!(CLOptions.STACK_SIZE.get())));
if (Strings.startsWith(name, "FEATURE_")) return LookupResult.Const(Bool.TYPE, Bool.FALSE);
return LookupResult.None;
}
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/main/Version.v3
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

// Updated by VCS scripts. DO NOT EDIT.
component Version {
def version: string = "III-7.1779";
def version: string = "III-7.1780";
var buildData: string;
}
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement02.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=true; 1=false; 2=false; 3=!NullCheckException; 4=false
//@execute 0=true; 1=false; 2=false; 3=!BoundsCheckException; 4=false
var a: Array<byte> = "arf";
var b: Array<bool> = [true];
var c: Array<int> = [0];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement03.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=false; 1=false; 2=false; 3=!NullCheckException; 4=false
//@execute 0=false; 1=false; 2=false; 3=!BoundsCheckException; 4=false
var a: Array<byte> = "arf";
var b: Array<bool> = [true, false];
var c: Array<int> = [0, 1];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement05.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=false; 1=!BoundsCheckException; 2=!BoundsCheckException; 3=!NullCheckException; 4=false
//@execute 0=false; 1=!BoundsCheckException; 2=!BoundsCheckException; 3=!BoundsCheckException; 4=false
var a: Array<byte> = "arf";
var b: Array<bool> = [true, false];
var c: Array<int> = [0, 1];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement10.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=true; 1=false; 2=false; 3=!NullCheckException; 4=false
//@execute 0=true; 1=false; 2=false; 3=!BoundsCheckException; 4=false
var a: Range<byte> = "arf";
var b: Range<bool> = [true];
var c: Range<int> = [0];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement11.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=false; 1=false; 2=false; 3=!NullCheckException; 4=false
//@execute 0=false; 1=false; 2=false; 3=!BoundsCheckException; 4=false
var a: Range<byte> = "arf";
var b: Range<bool> = [true, false];
var c: Range<int> = [0, 1];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement13.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=false; 1=!BoundsCheckException; 2=!BoundsCheckException; 3=!NullCheckException; 4=false
//@execute 0=false; 1=!BoundsCheckException; 2=!BoundsCheckException; 3=!BoundsCheckException; 4=false
var a: Range<byte> = "arf";
var b: Range<bool> = [true, false];
var c: Range<int> = [0, 1];
Expand Down
2 changes: 1 addition & 1 deletion test/pointer/Pointer_atElement21.v3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@execute 0=true; 1=false; 2=false; 3=!NullCheckException; 4=false
//@execute 0=true; 1=false; 2=false; 3=!BoundsCheckException; 4=false
var a: Array<byte> = "arf";
var b: Array<bool> = [true];
var c: Array<int> = [0];
Expand Down
7 changes: 7 additions & 0 deletions test/pointer/Pointer_atElement22.v3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@execute 0=42; 1=42; 99=42; 100=!BoundsCheckException; 199999=!BoundsCheckException
def data = Array<byte>.new(100);
def main(a: int) -> int {
var range = CiRuntime.forgeRange<byte>(Pointer.atContents(data), data.length);
var p = Pointer.atElement(range, a);
return 42;
}
3 changes: 2 additions & 1 deletion test/rt/CiRuntimeApi.v3
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ component CiRuntimeApi {
checkNonNull(CiRuntime.EX_TABLE, "EX_TABLE");
checkNonNull(CiRuntime.EX_STRINGS, "EX_STRINGS");

var t0 = (CiRuntime.STACK_START, CiRuntime.STACK_END);
// stack variables should exist
var t0 = (CiRuntime.STACK_START, CiRuntime.STACK_END, CiRuntime.STACK_SIZE);

var func1 = CiRuntime.forgeClosure<C, int, int>(Pointer.NULL, null);
var x1 = dontCall(func1, 3);
Expand Down

0 comments on commit c887bea

Please sign in to comment.