Skip to content

Commit

Permalink
Weaken range-check test
Browse files Browse the repository at this point in the history
since no range checks... test cannot fail (pass)
  • Loading branch information
cliffclick committed Feb 16, 2025
1 parent 92094eb commit 4a9d57d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions chapter20/src/test/java/com/seaofnodes/simple/Chapter15Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,20 @@ public void testBad2() {

@Test
public void testBad3() {
CodeGen code = new CodeGen(
"""
CodeGen code = new CodeGen("""
int[] is = new int[arg];
return is[1];
""");
code.parse().opto();
assertEquals("return 0;", code.print());
assertEquals("0", Eval2.eval(code, 4));
try { Eval2.eval(code,0); }
catch( ArrayIndexOutOfBoundsException e ) { assertEquals("Array index 1 out of bounds for array length 0",e.getMessage()); }
try { Eval2.eval(code,-1); }
try { Eval2.eval(code,-1); fail(); }
catch( NegativeArraySizeException e ) { assertEquals("-1",e.getMessage()); }
// This test will not pass (i.e., failed range-check) until we have range checks.
// Without the range check, the load `is[1]` optimizes against the `new int[]`
// and assumes it loads a zero then folds away, and the Eval2 never sees an OOB load.
//try { Eval2.eval(code,0); fail(); }
//catch( ArrayIndexOutOfBoundsException e ) { assertEquals("Array index 1 out of bounds for array length 0",e.getMessage()); }
}

@Test
Expand Down

0 comments on commit 4a9d57d

Please sign in to comment.