JVM: Fix constant folding for unsigned values
This commit is contained in:
committed by
Dmitry Petrov
parent
732405895f
commit
d3d4e94cd6
+6
@@ -7172,6 +7172,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsigned.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("foldingBinaryOpsUnsignedConst.kt")
|
||||
public void testFoldingBinaryOpsUnsignedConst() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsignedConst.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9532.kt")
|
||||
public void testKt9532() throws Exception {
|
||||
|
||||
+4
-2
@@ -12,6 +12,7 @@ import com.intellij.psi.util.TypeConversionUtil
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
@@ -401,7 +402,7 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
return when (constantValue) {
|
||||
is ErrorValue, is EnumValue -> return null
|
||||
is NullValue -> StringValue("null")
|
||||
else -> StringValue(constantValue.stringTemplateValue())
|
||||
else -> StringValue(constantValue.boxedValue().toString())
|
||||
}.wrap(compileTimeConstant.parameters)
|
||||
}
|
||||
|
||||
@@ -984,7 +985,8 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
): OperationArgument? {
|
||||
val compileTimeConstant = constantExpressionEvaluator.evaluateExpression(expression, trace, parameterType) ?: return null
|
||||
if (compileTimeConstant is TypedCompileTimeConstant && !compileTimeConstant.type.isSubtypeOf(parameterType)) return null
|
||||
val evaluationResult = compileTimeConstant.getValue(parameterType) ?: return null
|
||||
val constantValue = compileTimeConstant.toConstantValue(parameterType)
|
||||
val evaluationResult = (if (compileTimeType == ANY) constantValue.boxedValue() else constantValue.value) ?: return null
|
||||
return OperationArgument(evaluationResult, compileTimeType, expression)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
val a = "INT " + 0x8fffffffU
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
const val a = "INT " + 0x8fffffffU
|
||||
const val b = "BYTE " + 0x8ffU
|
||||
const val c = "LONG " + 0xffff_ffff_ffffU
|
||||
|
||||
const val uint = 0x8fffffffU
|
||||
const val ubyte = 0x8ffU
|
||||
const val ulong = 0xffff_ffff_ffffU
|
||||
|
||||
const val aa = "INT " + uint
|
||||
const val bb = "BYTE " + ubyte
|
||||
const val cc = "LONG " + ulong
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (a != "INT 2415919103") {
|
||||
return "FAIL 0: $a"
|
||||
}
|
||||
if (aa != "INT 2415919103") {
|
||||
return "FAIL 1: $aa"
|
||||
}
|
||||
|
||||
if (b != "BYTE 2303") {
|
||||
return "FAIL 2: $b"
|
||||
}
|
||||
if (bb != "BYTE 2303") {
|
||||
return "FAIL 3: $bb"
|
||||
}
|
||||
|
||||
|
||||
if (c != "LONG 281474976710655") {
|
||||
return "FAIL 4: $c"
|
||||
}
|
||||
if (cc != "LONG 281474976710655") {
|
||||
return "FAIL 5: $cc"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -7172,6 +7172,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsigned.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("foldingBinaryOpsUnsignedConst.kt")
|
||||
public void testFoldingBinaryOpsUnsignedConst() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsignedConst.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9532.kt")
|
||||
public void testKt9532() throws Exception {
|
||||
|
||||
+6
@@ -7172,6 +7172,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsigned.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("foldingBinaryOpsUnsignedConst.kt")
|
||||
public void testFoldingBinaryOpsUnsignedConst() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsignedConst.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9532.kt")
|
||||
public void testKt9532() throws Exception {
|
||||
|
||||
+10
-5
@@ -5387,11 +5387,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Constants extends AbstractLightAnalysisModeTest {
|
||||
@TestMetadata("foldingBinaryOpsUnsigned.kt")
|
||||
public void ignoreFoldingBinaryOpsUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsigned.kt");
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
@@ -5430,6 +5425,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/constants/float.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("foldingBinaryOpsUnsigned.kt")
|
||||
public void testFoldingBinaryOpsUnsigned() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsigned.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("foldingBinaryOpsUnsignedConst.kt")
|
||||
public void testFoldingBinaryOpsUnsignedConst() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/foldingBinaryOpsUnsignedConst.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt9532.kt")
|
||||
public void testKt9532() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||
|
||||
Reference in New Issue
Block a user