From 5400096ec10da839cf2006a8a02e11ffeff521dd Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 29 Dec 2024 16:06:07 -0800 Subject: More precise error reporting Demand CFG cleanup, even if peeps are off; cleans up some tests & a lot of fuzzer bugs related to trying to find infinite loops in dead code. Logical subclass for better error reporting on &,|,^,>>,<<,>>> More precise error reporting on multi returns and trinaries Fuzzer uses new Eval2 --- .../java/com/seaofnodes/simple/Chapter02Test.java | 2 +- .../java/com/seaofnodes/simple/Chapter03Test.java | 2 +- .../java/com/seaofnodes/simple/Chapter09Test.java | 4 +-- .../java/com/seaofnodes/simple/Chapter17Test.java | 11 ++++++ .../src/test/java/com/seaofnodes/simple/Eval2.java | 1 + .../java/com/seaofnodes/simple/fuzzer/Fuzzer.java | 41 ++++++++-------------- .../com/seaofnodes/simple/fuzzer/FuzzerUtils.java | 9 ++--- .../seaofnodes/simple/fuzzer/ScriptGenerator.java | 5 +-- 8 files changed, 36 insertions(+), 39 deletions(-) (limited to 'chapter18/src/test/java/com') diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter02Test.java index 4254f0a6..324ebf41 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter02Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter02Test.java @@ -12,7 +12,7 @@ public class Chapter02Test { public void testParseGrammar() { CodeGen code = new CodeGen("return 1+2*3+-5;"); code.parse(true); // Disable peepholes - assertEquals("return Phi(Region,((1+(2*3))+(-5)));", code.print()); + assertEquals("return ((1+(2*3))+(-5));", code.print()); } @Test diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter03Test.java index 2e45ee2a..a7fc3ae5 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter03Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter03Test.java @@ -30,7 +30,7 @@ public class Chapter03Test { public void testVarScopeNoPeephole() { CodeGen code = new CodeGen("int a=1; int b=2; int !c=0; { int b=3; c=a+b; } return c; "); code.parse(true); - assertEquals("return Phi(Region,(1+3));", code.print()); + assertEquals("return (1+3);", code.print()); } @Test diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter09Test.java index 5b764013..b210f7e9 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter09Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter09Test.java @@ -194,7 +194,7 @@ int v0=0!=0<-0; return -0+0+0; """); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("return Top;", code.print()); } @@ -243,7 +243,7 @@ while(1) { return 0!=0; """); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("return Top;", code.print()); } @Test diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java index 4bcb9daa..5247f122 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java @@ -353,6 +353,17 @@ return f; // missing widening assertEquals("1.2", Eval2.eval(code, 0)); } + + @Test + public void testTrinary6() { + CodeGen code = new CodeGen(""" +struct S{}; +return arg ? 7 : new S; +"""); + try { code.parse().opto().typeCheck(); fail(); } + catch( Exception e ) { assertEquals("No common type amongst int and reference",e.getMessage()); } + } + // --------------------------------------------------------------- @Test public void testFor0() { diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java b/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java index f7f58f32..77cbf115 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Eval2.java @@ -115,6 +115,7 @@ public abstract class Eval2 { case MinusNode sub -> - x(sub.in(1)); case MulNode mul -> x(mul.in(1)) * x(mul.in(2)); case NewNode alloc -> alloc(alloc); + case NotNode not -> x(not.in(1)) == 0 ? 1L : 0L; case OrNode or -> x(or .in(1)) | x(or .in(2)); case ProjNode proj -> proj._type instanceof TypeMem ? "$mem" : val(proj.in(0)); case ReadOnlyNode read -> val(read.in(1)); diff --git a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java index 6f5307bc..66395a74 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java @@ -1,7 +1,8 @@ package com.seaofnodes.simple.fuzzer; +import com.seaofnodes.simple.Utils; +import com.seaofnodes.simple.Eval2; import com.seaofnodes.simple.CodeGen; -import com.seaofnodes.simple.evaluator.Evaluator; import com.seaofnodes.simple.node.Node; import com.seaofnodes.simple.node.StopNode; import java.util.ArrayList; @@ -55,18 +56,8 @@ public class Fuzzer { private static boolean neq(Object a, Object b) { if (Objects.equals(a, b)) return false; - if (a instanceof Evaluator.Obj ea && b instanceof Evaluator.Obj eb) { - if (ea.struct() != eb.struct()) return true; - for(int i=0;i