Workaround clang crash in cinterop tool (KT-34467)

This commit is contained in:
Ilya Matveev
2019-10-18 20:17:54 +03:00
committed by Ilya Matveev
parent f50ea1397c
commit 838cccf275
8 changed files with 37 additions and 2 deletions
@@ -958,7 +958,7 @@ fun buildNativeIndexImpl(library: NativeLibrary, verbose: Boolean): IndexerResul
private fun indexDeclarations(nativeIndex: NativeIndexImpl): CompilationWithPCH {
withIndex { index ->
val translationUnit = nativeIndex.library.parse(
val translationUnit = nativeIndex.library.copyWithArgsForPCH().parse(
index,
options = CXTranslationUnit_DetailedPreprocessingRecord or CXTranslationUnit_ForSerialization
)
@@ -257,6 +257,11 @@ fun Compilation.copy(
language = language
)
// Clang-8 crashes when consuming a precompiled header built with -fmodule-map-file argument (see KT-34467).
// We ignore this argument when building a pch to workaround this crash.
fun Compilation.copyWithArgsForPCH(): Compilation =
copy(compilerArgs = compilerArgs.filterNot { it.startsWith("-fmodule-map-file") })
data class CompilationImpl(
override val includes: List<String>,
override val additionalPreambleLines: List<String>,
@@ -271,7 +276,7 @@ data class CompilationImpl(
*/
fun Compilation.precompileHeaders(): CompilationWithPCH = withIndex { index ->
val options = CXTranslationUnit_ForSerialization
val translationUnit = this.parse(index, options)
val translationUnit = copyWithArgsForPCH().parse(index, options)
try {
translationUnit.ensureNoCompileErrors()
withPrecompiledHeader(translationUnit)
+14
View File
@@ -3318,6 +3318,13 @@ if (PlatformInfo.isAppleTarget(project)) {
it.headers "$projectDir/interop/objc/msg_send/messaging.h"
it.linkerOpts "-L$buildDir", "-lobjcmessaging"
}
createInterop("objcKt34467") {
it.defFile 'interop/objc/kt34467/module_library.def'
def moduleMap = file("interop/objc/kt34467/module_library.modulemap").absolutePath
def includePath = file("interop/objc/kt34467").absolutePath
it.compilerOpts "-fmodule-map-file=$moduleMap", "-I$includePath"
}
}
createInterop("withSpaces") {
@@ -3565,6 +3572,13 @@ interopTest("interop_objc_msg_send") {
}
}
interopTest("interop_objc_kt34467") {
disabled = !isAppleTarget(project)
source = "interop/objc/kt34467/foo.kt"
interop = 'objcKt34467'
goldValue = "OK\n42\n"
}
standaloneTest("jsinterop_math") {
doBefore {
def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop"
@@ -0,0 +1 @@
#define ANSWER 42
@@ -0,0 +1,6 @@
import module_library.*
fun main() {
println("OK")
println(ANSWER)
}
@@ -0,0 +1,2 @@
language = Objective-C
modules = module_library
@@ -0,0 +1,6 @@
module module_library {
umbrella header "module_library_umbrella.h"
export *
module * { export * }
}
@@ -0,0 +1 @@
#import <foo.h>