diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index 267c4777719..1f6f56709fd 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -183,6 +183,7 @@ class K2Native : CLICompiler() { if (arguments.verifyCompiler != null) put(VERIFY_COMPILER, arguments.verifyCompiler == "true") + put(VERIFY_IR, arguments.verifyIr) put(VERIFY_BITCODE, arguments.verifyBitCode) put(ENABLED_PHASES, diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 09dd3304088..a44e00ce04c 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -225,6 +225,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xverify-bitcode", deprecatedName = "--verify_bitcode", description = "Verify llvm bitcode after each method") var verifyBitCode: Boolean = false + @Argument(value = "-Xverify-ir", description = "Verify IR") + var verifyIr: Boolean = false + @Argument(value = "-Xverify-compiler", description = "Verify compiler") var verifyCompiler: String? = null diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index d1a4b25f86f..9a6a2755326 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -47,6 +47,9 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration val memoryModel: MemoryModel get() = configuration.get(KonanConfigKeys.MEMORY_MODEL)!! val destroyRuntimeMode: DestroyRuntimeMode get() = configuration.get(KonanConfigKeys.DESTROY_RUNTIME_MODE)!! + val needVerifyIr: Boolean + get() = configuration.get(KonanConfigKeys.VERIFY_IR) == true + val needCompilerVerification: Boolean get() = configuration.get(KonanConfigKeys.VERIFY_COMPILER) ?: (configuration.getBoolean(KonanConfigKeys.OPTIMIZATION) || diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index 16b84887046..cb302eea9e7 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -126,6 +126,8 @@ class KonanConfigKeys { = CompilerConfigurationKey.create("directory for temporary files") val VERIFY_BITCODE: CompilerConfigurationKey = CompilerConfigurationKey.create("verify bitcode") + val VERIFY_IR: CompilerConfigurationKey + = CompilerConfigurationKey.create("verify IR") val VERIFY_COMPILER: CompilerConfigurationKey = CompilerConfigurationKey.create("verify compiler") val DEBUG_INFO_VERSION: CompilerConfigurationKey diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index 4879b6cff2c..4c24ed52d02 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.konan.target.CompilerOutputKind internal fun moduleValidationCallback(state: ActionState, module: IrModuleFragment, context: Context) { - if (!context.config.needCompilerVerification) return + if (!context.config.needVerifyIr) return val validatorConfig = IrValidatorConfig( abortOnError = false, diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index f900d0c96e3..8008e5a022e 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4872,6 +4872,7 @@ KotlinNativeTestKt.createTest(project, 'stdlibTest', KonanGTest) { task -> baseDir "$testOutputStdlib/stdlibTest" enableMultiplatform true extraOpts '-tr', + '-Xverify-ir', '-Xopt-in=kotlin.RequiresOptIn,kotlin.ExperimentalStdlibApi', "-friend-modules", project.rootProject.file("${project.properties['konan.home']}/klib/common/stdlib").absolutePath extraOpts project.globalTestArgs @@ -4911,6 +4912,7 @@ task buildKonanTests { t -> srcFiles sources baseDir testOutputLocal extraOpts '-tr' + extraOpts '-Xverify-ir' extraOpts project.globalTestArgs } } diff --git a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 7be49e1a6ce..749ee1436b3 100644 --- a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -34,6 +34,7 @@ class RunExternalTestGroup extends JavaExec { def dist = UtilsKt.getKotlinNativeDist(project) def enableKonanAssertions = true + def verifyIr = true String outputDirectory = null String goldValue = null // Checks test's output against gold value and returns true if the output matches the expectation @@ -100,6 +101,9 @@ class RunExternalTestGroup extends JavaExec { if (enableKonanAssertions) { args "-ea" } + if (verifyIr) { + args "-Xverify-ir" + } if (project.hasProperty("test_verbose")) { println("Files to compile: $filesToCompile") println(args) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt index a79c5db16d2..85fb358c380 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt @@ -333,11 +333,21 @@ open class KonanStandaloneTest : KonanLocalTest() { @Input @Optional var enableKonanAssertions = true + @Input @Optional + var verifyIr = true + /** * Compiler flags used to build a test. */ var flags: List = listOf() - get() = if (enableKonanAssertions) field + "-ea" else field + get() { + val result = field.toMutableList() + if (enableKonanAssertions) + result += "-ea" + if (verifyIr) + result += "-Xverify-ir" + return result + } fun getSources(): Provider> = project.provider { val sources = buildCompileList(project.file(source).toPath(), outputDirectory)