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)