summaryrefslogtreecommitdiff
path: root/chapter12/src/test/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-09-19 22:31:42 -0700
committerCliff Click <cliffc@acm.org>2026-09-19 22:31:42 -0700
commit6e59fc1b71f2098c8baf90a6c54e5a33b7291e94 (patch)
treecb097fb6fdb0f7941ac7e784f56e11750ab14c53 /chapter12/src/test/java
parent45bd2e5fae4cbbee0ddd07094755c2f995178f28 (diff)
downloadSimple-6e59fc1b71f2098c8baf90a6c54e5a33b7291e94.tar.gz
Simple-6e59fc1b71f2098c8baf90a6c54e5a33b7291e94.zip
Unify mixed-return checking and results
Unify dominator caching.
Diffstat (limited to 'chapter12/src/test/java')
-rw-r--r--chapter12/src/test/java/com/seaofnodes/simple/Chapter10Test.java13
-rw-r--r--chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java14
-rw-r--r--chapter12/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java2
3 files changed, 28 insertions, 1 deletions
diff --git a/chapter12/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter12/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index 6f8a6b3b..fae91067 100644
--- a/chapter12/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter12/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -11,6 +11,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter10Test {
+ @Test public void testDeadReferenceReturn() {
+ for( String body : new String[] {
+ "return new S; return 0;",
+ "if(1) return new S; else return 0;"
+ } ) {
+ String src = "struct S { int x; }; " + body;
+ var stop = new Parser(src).parse().iterate();
+ org.junit.Assert.assertTrue(body,
+ stop.ret().expr()._type instanceof com.seaofnodes.simple.type.TypeMemPtr);
+ }
+ }
+
+
// Issue #246: null-check guards start in Chapter 10; arrays arrive in Chapter 15.
private static final String NULLABLE_POINT_SOURCE = """
diff --git a/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index af8fdfe9..00b2591c 100644
--- a/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
@@ -9,6 +9,20 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter12Test {
+ @Test public void testDeadNumericReturns() {
+ for( String[] test : new String[][] {
+ {"if(1) return 7; else return 2.5;", "7"},
+ {"if(0) return 7; else return 2.5;", "2.5"},
+ {"return 7; return 2.5;", "7"},
+ {"return 2.5; return 7;", "2.5"}
+ } ) {
+ String src = test[0];
+ var stop = new Parser(src).parse().iterate();
+ assertEquals(src,test[1],com.seaofnodes.simple.evaluator.Evaluator.evaluate(stop,0).toString());
+ }
+ }
+
+
@Test
public void testJig() {
Parser parser = new Parser(
diff --git a/chapter12/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java b/chapter12/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
index 01d471bf..8ff33436 100644
--- a/chapter12/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
+++ b/chapter12/src/test/java/com/seaofnodes/simple/node/PrintTestSupport.java
@@ -26,7 +26,7 @@ public class PrintTestSupport {
ins.put(n,n._inputs.toArray(new Node[0]));
outs.put(n,n._outputs.toArray(new Node[0]));
hashes.put(n,hash.getInt(n));
- if( n instanceof CFGNode cfg ) depths.put(n,cfg._idepth);
+ if( n instanceof CFGNode cfg ) depths.put(n,(int)cfg._idepth);
}
print.run();
for( Node n : nodes ) {