diff options
Diffstat (limited to 'chapter22/src')
3 files changed, 14 insertions, 4 deletions
diff --git a/chapter22/src/main/java/com/seaofnodes/simple/Parser.java b/chapter22/src/main/java/com/seaofnodes/simple/Parser.java index 72fe6a71..087fd1fd 100644 --- a/chapter22/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter22/src/main/java/com/seaofnodes/simple/Parser.java @@ -236,8 +236,13 @@ public class Parser { last = parseStatement(); // Last expression is the return except for the top-level main - if( ctrl()._type==Type.CONTROL && fun.sig() != _code._main ) - fun.addReturn(ctrl(), _scope.mem().merge(), last); + if( ctrl()._type==Type.CONTROL ) + if( fun.sig() != _code._main ) + fun.addReturn(ctrl(), _scope.mem().merge(), last); + else { + fun.setDef(1,XCTRL); // Kill default main + _code.addAll(fun._outputs); + } // Pop off the inProgress node on the multi-exit Region merge assert r.inProgress(); diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java index d4d02aa9..551880b1 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java @@ -128,7 +128,7 @@ while(v1+arg) { } """); code.parse().opto(); - assertEquals("return Top;", code.print()); + assertEquals("Stop[ ]", code.print()); // No explicit return: omit default main. } @Test @@ -210,7 +210,7 @@ return -0+0+0; public void testFuzz3() { CodeGen code = new CodeGen("int v0=0; while(0==69) while(v0) return 0;"); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("Stop[ ]", code.print()); // The only return is unreachable. } @Test diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java index 1765512a..1f4a3d27 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter20Test.java @@ -205,6 +205,11 @@ s.cs[0] = 67; // C s.cs[1] = 108; // l hashCode(s); """; + // Without an explicit return, default main must be removed completely. + // Seed 0 previously left a loop with a missing branch successor. + for( String cpu : new String[]{"x86_64_v2","riscv","arm"} ) + new CodeGen(src,com.seaofnodes.simple.type.TypeInteger.BOT,0) + .driver(CodeGen.Phase.Encoding,cpu,"SystemV"); testTarget(src,"x86_64_v2", "SystemV",0,null); testTarget(src,"riscv" , "SystemV",0,null); testTarget(src,"arm" , "SystemV",0,null); |
