Skip to content

Commit a225cb2

Browse files
authored
Merge pull request #6722 from dotty-staging/fix-6710
Fix #6710: reverse code for dcmpg/dcmpl and fcmpg/fcmpl
2 parents 6c3b474 + 263e02f commit a225cb2

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class ScalaPrimitivesOps {
3333
final val NE = 43 // x != y
3434
final val LT = 44 // x < y
3535
final val LE = 45 // x <= y
36-
final val GE = 46 // x > y
37-
final val GT = 47 // x >= y
36+
final val GT = 46 // x > y
37+
final val GE = 47 // x >= y
3838

3939
// Boolean unary operations
4040
final val ZNOT = 50 // !x

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
12361236
(tk: @unchecked) match {
12371237
case LONG => emit(asm.Opcodes.LCMP)
12381238
case FLOAT =>
1239-
if (op == LT || op == LE) emit(asm.Opcodes.FCMPG)
1240-
else emit(asm.Opcodes.FCMPL)
1239+
if (op == LT || op == LE) emit(asm.Opcodes.FCMPL)
1240+
else emit(asm.Opcodes.FCMPG)
12411241
case DOUBLE =>
1242-
if (op == LT || op == LE) emit(asm.Opcodes.DCMPG)
1243-
else emit(asm.Opcodes.DCMPL)
1242+
if (op == LT || op == LE) emit(asm.Opcodes.DCMPL)
1243+
else emit(asm.Opcodes.DCMPG)
12441244
}
12451245
bc.emitIF(op, success)
12461246
}

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
113113
).checkRuns()
114114
}
115115

116+
@Test def runBootstrappedOnly: Unit = {
117+
implicit val testGroup: TestGroup = TestGroup("runBootstrappedOnly")
118+
aggregateTests(
119+
compileFilesInDir("tests/run-bootstrapped", withCompilerOptions),
120+
).checkRuns()
121+
}
122+
116123
// Pickling Tests ------------------------------------------------------------
117124
//
118125
// Pickling tests are very memory intensive and as such need to be run with a

tests/run-bootstrapped/i6710.scala

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
// constant fold will fail for non-bootstrapped Dotty
4+
assert(!(Float.NaN > 0.0))
5+
assert(!(Float.NaN < 0.0))
6+
assert(!(Double.NaN > 0.0))
7+
assert(!(Double.NaN < 0.0))
8+
9+
val f: Float = Float.NaN
10+
val d: Double = Double.NaN
11+
assert(!(f > 0.0f))
12+
assert(!(f < 0.0f))
13+
assert(!(d > 0.0))
14+
assert(!(d < 0.0))
15+
16+
// loop forever before the fix
17+
var x = Double.NaN
18+
while(x < 10.0) { x = x + 1; println(x) }
19+
while(x > 10.0) { x = x + 1; println(x) }
20+
do { x = x + 1; println(x) } while(x < 10.0)
21+
do { x = x + 1; println(x) } while(x > 10.0)
22+
23+
// tests from https://github.com/scala/scala/pull/5207
24+
{
25+
val n = Double.NaN
26+
def ne(x: Double, y: Double) = x != y
27+
val fs: List[(Double, Double) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y))
28+
val vs = List[Double](n, 1, -1, 0)
29+
for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y))
30+
}
31+
32+
{
33+
val n = Float.NaN
34+
def ne(x: Float, y: Float) = x != y
35+
val fs: List[(Float, Float) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y))
36+
val vs = List[Float](n, 1, -1, 0)
37+
for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y))
38+
}
39+
40+
{
41+
def a[T](x: T, y: T) = x == y
42+
def b[T](x: T, y: T) = x != y
43+
val n = Double.NaN
44+
(a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b))
45+
}
46+
47+
{
48+
def a[T](x: T, y: T) = x == y
49+
def b[T](x: T, y: T) = x != y
50+
val n = Float.NaN
51+
(a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b))
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)