Skip to content

Commit 10cc2f8

Browse files
committed
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.
1 parent aef831a commit 10cc2f8

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)