diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt index 127ddc86a2f..b4181e3271a 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2NativeCompilerArguments.kt @@ -285,8 +285,12 @@ 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-ir", + valueDescription = "{none|warning|error}", + description = "IR verification mode (no verification by default)" + ) + var verifyIr: String? = null @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 f868437051a..1252c384983 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 @@ -24,6 +24,12 @@ import org.jetbrains.kotlin.konan.util.visibleName import org.jetbrains.kotlin.library.metadata.resolver.TopologicalLibraryOrder import org.jetbrains.kotlin.util.removeSuffixIfPresent +enum class IrVerificationMode { + NONE, + WARNING, + ERROR +} + class KonanConfig(val project: Project, val configuration: CompilerConfiguration) { internal val distribution = run { val overridenProperties = mutableMapOf().apply { @@ -165,8 +171,8 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration val gcMarkSingleThreaded: Boolean get() = configuration.get(BinaryOptions.gcMarkSingleThreaded) == true - val needVerifyIr: Boolean - get() = configuration.get(KonanConfigKeys.VERIFY_IR) == true + val irVerificationMode: IrVerificationMode + get() = configuration.getNotNull(KonanConfigKeys.VERIFY_IR) val needCompilerVerification: Boolean get() = configuration.get(KonanConfigKeys.VERIFY_COMPILER) 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 0f4f091b2ec..c9cd2465d10 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 @@ -127,8 +127,8 @@ class KonanConfigKeys { = CompilerConfigurationKey.create("save LLVM IR") val VERIFY_BITCODE: CompilerConfigurationKey = CompilerConfigurationKey.create("verify bitcode") - val VERIFY_IR: CompilerConfigurationKey - = CompilerConfigurationKey.create("verify IR") + val VERIFY_IR: CompilerConfigurationKey + = CompilerConfigurationKey.create("IR verification mode") 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/SetupConfiguration.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt index 2abbf4d9573..42bd11907fc 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/SetupConfiguration.kt @@ -103,7 +103,16 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument if (arguments.verifyCompiler != null) put(VERIFY_COMPILER, arguments.verifyCompiler == "true") - put(VERIFY_IR, arguments.verifyIr) + put(VERIFY_IR, when (arguments.verifyIr) { + null -> IrVerificationMode.NONE + "none" -> IrVerificationMode.NONE + "warning" -> IrVerificationMode.WARNING + "error" -> IrVerificationMode.ERROR + else -> { + report(ERROR, "Unsupported IR verification mode ${arguments.verifyIr}") + IrVerificationMode.NONE + } + }) put(VERIFY_BITCODE, arguments.verifyBitCode) put(ENABLE_ASSERTIONS, arguments.enableAssertions) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/utilities/IrPassesUtilities.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/utilities/IrPassesUtilities.kt index e42d30729e8..603c8031710 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/utilities/IrPassesUtilities.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/utilities/IrPassesUtilities.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.backend.common.phaser.Action import org.jetbrains.kotlin.backend.common.phaser.ActionState import org.jetbrains.kotlin.backend.common.phaser.BeforeOrAfter import org.jetbrains.kotlin.backend.common.phaser.defaultDumper +import org.jetbrains.kotlin.backend.konan.IrVerificationMode import org.jetbrains.kotlin.backend.konan.driver.PhaseContext import org.jetbrains.kotlin.backend.konan.reportCompilationWarning import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -56,7 +57,7 @@ private fun ActionState.isDumpNeeded() = private fun getIrValidator(): Action = fun(state: ActionState, data: Data, context: Context) { - if (!context.config.needVerifyIr) return + if (context.config.irVerificationMode == IrVerificationMode.NONE) return val backendContext: CommonBackendContext? = findBackendContext(context) if (backendContext == null) { @@ -71,7 +72,7 @@ private fun getIrValidator(): Action baseDir testOutputLocal extraOpts '-ea' // Without this option assertions would remain inactive. extraOpts '-tr' - extraOpts '-Xverify-ir' + extraOpts '-Xverify-ir=error' extraOpts project.globalTestArgs } } 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 d66d99f2455..8f56a6d3055 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 @@ -406,7 +406,7 @@ open class KonanStandaloneTest : KonanLocalTest() { if (enableKonanAssertions) result += "-ea" if (verifyIr) - result += "-Xverify-ir" + result += "-Xverify-ir=error" return result } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index 44d87a5f6c9..6bee14ad7f9 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -53,7 +53,7 @@ internal abstract class BasicCompilation( add( "-enable-assertions", "-Xskip-prerelease-check", - "-Xverify-ir" + "-Xverify-ir=error" ) addFlattened(binaryOptions.entries) { (name, value) -> listOf("-Xbinary=$name=$value") } }