From 10cc2f895dca32b6389e53470911085af82ab9d4 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 21 Jun 2019 00:02:41 +0200 Subject: [PATCH 1/2] Fix #6710: reverse code for dcmpg/dcmpl and fcmpg/fcmpl Note that the test may only run with the bootstrapped compiler, because the ConstFold in non-bootstrapped compiler is using the wrongly generated byte-code. --- .../tools/backend/jvm/BCodeBodyBuilder.scala | 8 +++---- .../BootstrappedOnlyCompilationTests.scala | 7 ++++++ tests/run-bootstrapped/i6710.scala | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/run-bootstrapped/i6710.scala diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala index 293895c1097d..334fa0ae2e78 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala @@ -1236,11 +1236,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder { (tk: @unchecked) match { case LONG => emit(asm.Opcodes.LCMP) case FLOAT => - if (op == LT || op == LE) emit(asm.Opcodes.FCMPG) - else emit(asm.Opcodes.FCMPL) + if (op == LT || op == LE) emit(asm.Opcodes.FCMPL) + else emit(asm.Opcodes.FCMPG) case DOUBLE => - if (op == LT || op == LE) emit(asm.Opcodes.DCMPG) - else emit(asm.Opcodes.DCMPL) + if (op == LT || op == LE) emit(asm.Opcodes.DCMPL) + else emit(asm.Opcodes.DCMPG) } bc.emitIF(op, success) } diff --git a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala index e672decb4779..1b21348fcb44 100644 --- a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala @@ -113,6 +113,13 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting { ).checkRuns() } + @Test def runBootstrappedOnly: Unit = { + implicit val testGroup: TestGroup = TestGroup("runBootstrappedOnly") + aggregateTests( + compileFilesInDir("tests/run-bootstrapped", withCompilerOptions), + ).checkRuns() + } + // Pickling Tests ------------------------------------------------------------ // // Pickling tests are very memory intensive and as such need to be run with a diff --git a/tests/run-bootstrapped/i6710.scala b/tests/run-bootstrapped/i6710.scala new file mode 100644 index 000000000000..008f47bb259d --- /dev/null +++ b/tests/run-bootstrapped/i6710.scala @@ -0,0 +1,23 @@ +object Test { + def main(args: Array[String]): Unit = { + // constant fold will fail for non-bootstrapped Dotty + assert(!(Float.NaN > 0.0)) + assert(!(Float.NaN < 0.0)) + assert(!(Double.NaN > 0.0)) + assert(!(Double.NaN < 0.0)) + + val f: Float = Float.NaN + val d: Double = Double.NaN + assert(!(f > 0.0f)) + assert(!(f < 0.0f)) + assert(!(d > 0.0)) + assert(!(d < 0.0)) + + // loop forever before the fix + var x = Double.NaN + while(x < 10.0) { x = x + 1; println(x) } + while(x > 10.0) { x = x + 1; println(x) } + do { x = x + 1; println(x) } while(x < 10.0) + do { x = x + 1; println(x) } while(x > 10.0) + } +} From 263e02f68aa30d0e7b7930bee7ea9bd1340106ee Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 21 Jun 2019 07:46:13 +0200 Subject: [PATCH 2/2] Port tests from Scala2 #5207 https://github.com/scala/scala/pull/5207 --- .../tools/backend/ScalaPrimitivesOps.scala | 4 +-- tests/run-bootstrapped/i6710.scala | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala b/compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala index edf1d4c0b966..40b567b640b8 100644 --- a/compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala +++ b/compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala @@ -33,8 +33,8 @@ class ScalaPrimitivesOps { final val NE = 43 // x != y final val LT = 44 // x < y final val LE = 45 // x <= y - final val GE = 46 // x > y - final val GT = 47 // x >= y + final val GT = 46 // x > y + final val GE = 47 // x >= y // Boolean unary operations final val ZNOT = 50 // !x diff --git a/tests/run-bootstrapped/i6710.scala b/tests/run-bootstrapped/i6710.scala index 008f47bb259d..ce4167aa3f67 100644 --- a/tests/run-bootstrapped/i6710.scala +++ b/tests/run-bootstrapped/i6710.scala @@ -19,5 +19,36 @@ object Test { while(x > 10.0) { x = x + 1; println(x) } do { x = x + 1; println(x) } while(x < 10.0) do { x = x + 1; println(x) } while(x > 10.0) + + // tests from https://github.com/scala/scala/pull/5207 + { + val n = Double.NaN + def ne(x: Double, y: Double) = x != y + val fs: List[(Double, Double) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y)) + val vs = List[Double](n, 1, -1, 0) + for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y)) + } + + { + val n = Float.NaN + def ne(x: Float, y: Float) = x != y + val fs: List[(Float, Float) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y)) + val vs = List[Float](n, 1, -1, 0) + for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y)) + } + + { + def a[T](x: T, y: T) = x == y + def b[T](x: T, y: T) = x != y + val n = Double.NaN + (a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b)) + } + + { + def a[T](x: T, y: T) = x == y + def b[T](x: T, y: T) = x != y + val n = Float.NaN + (a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b)) + } } }