diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.java b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.java index 4ce17a87df0..88cd8ff082c 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.java +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.java @@ -59,7 +59,7 @@ public class K2NativeCompilerArguments extends CommonCompilerArguments { @Argument(value = "verify_descriptors", description = "Verify descriptor tree") public boolean verifyDescriptors; - @Argument(value = "verify_bitcode", description = "Verify llvm bitcode") + @Argument(value = "verify_bitcode", description = "Verify llvm bitcode after each method") public boolean verifyBitCode; @Argument(value = "enable", description = "Enable backend phase") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt index 5e13b51524c..797e7573912 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Context.kt @@ -106,7 +106,7 @@ internal class SpecialDescriptorsFactory(val context: Context) { } } -internal final class Context(val config: KonanConfig) : KonanBackendContext() { +internal class Context(val config: KonanConfig) : KonanBackendContext() { var moduleDescriptor: ModuleDescriptor? = null diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt index 8bd9d1df89a..9e05245e540 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt @@ -92,9 +92,9 @@ internal class PhaseManager(val context: Context) { if (shouldVerifyIr()) { verifyIr() } - if (shouldVerifyBitCode()) { - verifyBitCode() - } + + // We always verify bitcode to prevent hard to debug bugs. + verifyBitCode() if (shouldPrintDescriptors()) { printDescriptors() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 4521558bacb..67a4f9b3272 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -64,7 +64,7 @@ internal fun verifyModule(llvmModule: LLVMModuleRef, current: String = "") { // TODO: use LLVMDisposeMessage() on errorRef, once possible in interop. if (LLVMVerifyModule( llvmModule, LLVMVerifierFailureAction.LLVMPrintMessageAction, errorRef.ptr) == 1) { - if (current.length > 0) + if (current.isNotEmpty()) println("Error in ${current}") LLVMDumpModule(llvmModule) throw Error("Invalid module"); @@ -513,7 +513,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid codegen.epilogue() - verifyModule(context.llvmModule!!, + if (context.shouldVerifyBitCode()) + verifyModule(context.llvmModule!!, "${declaration.descriptor.containingDeclaration}::${ir2string(declaration)}") }