Fixed long / double / float value merge in OptimizationBasicInterpreter #KT-7401 Fixed
This commit is contained in:
+21
-20
@@ -91,27 +91,28 @@ public class OptimizationBasicInterpreter extends BasicInterpreter {
|
||||
public BasicValue merge(
|
||||
@NotNull BasicValue v, @NotNull BasicValue w
|
||||
) {
|
||||
if (!v.equals(w)) {
|
||||
if (v == BasicValue.UNINITIALIZED_VALUE || w == BasicValue.UNINITIALIZED_VALUE) {
|
||||
return BasicValue.UNINITIALIZED_VALUE;
|
||||
}
|
||||
|
||||
// if merge of two references then `lub` is java/lang/Object
|
||||
// arrays also are BasicValues with reference type's
|
||||
if (v.getType().getSort() == Type.OBJECT && w.getType().getSort() == Type.OBJECT) {
|
||||
return BasicValue.REFERENCE_VALUE;
|
||||
}
|
||||
|
||||
assert v.getType().getSort() != Type.ARRAY && w.getType().getSort() != Type.ARRAY : "There should not be arrays";
|
||||
|
||||
// if merge of something can be stored in int var (int, char, boolean, byte, character)
|
||||
if (v.getType().getOpcode(Opcodes.ISTORE) == Opcodes.ISTORE &&
|
||||
w.getType().getOpcode(Opcodes.ISTORE) == Opcodes.ISTORE) {
|
||||
return BasicValue.INT_VALUE;
|
||||
}
|
||||
|
||||
if (v == BasicValue.UNINITIALIZED_VALUE || w == BasicValue.UNINITIALIZED_VALUE) {
|
||||
return BasicValue.UNINITIALIZED_VALUE;
|
||||
}
|
||||
return v;
|
||||
// Objects must be equal, others can just have the same sort
|
||||
if (v.getType().getSort() == w.getType().getSort() && (v.getType().getSort() != Type.OBJECT || v.equals(w))) {
|
||||
return v;
|
||||
}
|
||||
|
||||
// if merge of two references then `lub` is java/lang/Object
|
||||
// arrays also are BasicValues with reference type's
|
||||
if (v.getType().getSort() == Type.OBJECT && w.getType().getSort() == Type.OBJECT) {
|
||||
return BasicValue.REFERENCE_VALUE;
|
||||
}
|
||||
|
||||
assert v.getType().getSort() != Type.ARRAY && w.getType().getSort() != Type.ARRAY : "There should not be arrays";
|
||||
|
||||
// if merge of something can be stored in int var (int, char, boolean, byte, character)
|
||||
if (v.getType().getOpcode(Opcodes.ISTORE) == Opcodes.ISTORE &&
|
||||
w.getType().getOpcode(Opcodes.ISTORE) == Opcodes.ISTORE) {
|
||||
return BasicValue.INT_VALUE;
|
||||
}
|
||||
|
||||
return BasicValue.UNINITIALIZED_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(): Double {
|
||||
var d = 2.0
|
||||
if (d > 0.0) {
|
||||
d++
|
||||
}
|
||||
d++
|
||||
return d
|
||||
}
|
||||
|
||||
fun box() = if (foo() > 3.5) "OK" else "Fail"
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(): Float {
|
||||
var f = 2.0f
|
||||
if (f > 0.0f) {
|
||||
f++
|
||||
}
|
||||
f++
|
||||
return f
|
||||
}
|
||||
|
||||
fun box() = if (foo() > 3.5f) "OK" else "Fail"
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(): Long {
|
||||
var n = 2L
|
||||
if (n > 0L) {
|
||||
n++
|
||||
}
|
||||
n++
|
||||
return n
|
||||
}
|
||||
|
||||
fun box() = if (foo() == 4L) "OK" else "Fail"
|
||||
+18
@@ -6895,6 +6895,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/regressions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("doubleMerge.kt")
|
||||
public void testDoubleMerge() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/doubleMerge.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("floatMerge.kt")
|
||||
public void testFloatMerge() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/floatMerge.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt3107.kt")
|
||||
public void testKt3107() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt3107.kt");
|
||||
@@ -6937,6 +6949,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt7401.kt")
|
||||
public void testKt7401() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt7401.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unjustifiedReferenceTarget.kt")
|
||||
public void testUnjustifiedReferenceTarget() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/unjustifiedReferenceTarget.kt");
|
||||
|
||||
Reference in New Issue
Block a user