From eb18b6eab34d71a9041030959473c1ec0409c170 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 13 Oct 2024 16:50:30 -0700 Subject: fix lifetime issues with GVN gone wild --- .../java/com/seaofnodes/simple/Chapter15Test.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'chapter15/src/test/java/com') diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java index 3a379084..6ec7cc1a 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -14,8 +14,7 @@ public class Chapter15Test { @Test public void testJig() { - Parser parser = new Parser( -""" + Parser parser = new Parser(""" return 3.14; """); StopNode stop = parser.parse().iterate(); @@ -23,6 +22,23 @@ return 3.14; assertEquals(3.14, Evaluator.evaluate(stop, 0)); } + @Test + public void testLifetime() { + Parser parser = new Parser(""" +u8[] b = new u8[5]; +if (arg) { + b[0] = b[0] + 1; +} else { + b[1] = b[1] * 2; +} +return b[0] + b[1]; +"""); + StopNode stop = parser.parse().iterate(); + assertEquals("return Phi(Region69,1,0);", stop.toString()); + assertEquals(0L, Evaluator.evaluate(stop, 0)); + assertEquals(1L, Evaluator.evaluate(stop, 1)); + } + @Test public void testCyclic() { Parser parser = new Parser( -- cgit v1.2.3