From 790ed59d9fe5ca396984b8a5135b7a091e4224f7 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Sat, 23 Jan 2016 21:03:10 +0100 Subject: SI-8601 Don't treat newarray as dead code Otherwise we lose the side effect of a `NegativeArraySizeException`. A test for this case already exists (run/t8601b.scala), but it currently enforces `-optimize -Ybackend:GenASM`, so it didn't trigger on the new backend. However, PR #4814 was merged into 2.12.x and moved that test over to the new backend and optimizer. After merging the 2.12.x into the current optimizer branch (push-pop elimination), the test started failing. Also disable the optimizer for `jvm/bytecode-test-example`: it counts the number of null checks in a method, the optimizer (rightly) eliminates one of the two. --- test/files/jvm/bytecode-test-example.flags | 1 + test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 test/files/jvm/bytecode-test-example.flags (limited to 'test') diff --git a/test/files/jvm/bytecode-test-example.flags b/test/files/jvm/bytecode-test-example.flags new file mode 100644 index 0000000000..bc22511cff --- /dev/null +++ b/test/files/jvm/bytecode-test-example.flags @@ -0,0 +1 @@ +-Yopt:l:none diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala index 5ee52ff78f..ec063c6cb3 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala @@ -161,7 +161,7 @@ class MethodLevelOptsTest extends ClearAfterClass { | val b = (a, y) // Tuple2 | val c = (new Object, "krik", new String) // unused java/lang/Object, java/lang/String allocation and string constant is also eliminated | val d = new java.lang.Integer(x) - | val e = new String(new Array[Char](23)) + | val e = new String(new Array[Char](23)) // array allocation not eliminated, as it may throw (negative size, SI-8601) | val f = new scala.runtime.IntRef(11) | x + y | } @@ -169,7 +169,7 @@ class MethodLevelOptsTest extends ClearAfterClass { """.stripMargin val List(c) = compileClasses(methodOptCompiler)(code) assertEquals(getSingleMethod(c, "t").instructions.dropNonOp, - List(VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN))) + List(IntOp(BIPUSH, 23), IntOp(NEWARRAY, 5), Op(POP), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN))) } @Test -- cgit v1.2.3