diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt index d4ef5aeae50..3ffeca05923 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Utils.kt @@ -82,15 +82,28 @@ internal fun parseTranslationUnit( ): CXTranslationUnit { memScoped { - val result = clang_parseTranslationUnit( + val resultVar = alloc() + + val errorCode = clang_parseTranslationUnit2( index, sourceFile.absolutePath, compilerArgs.toNativeStringArray(memScope), compilerArgs.size, null, 0, - options - )!! + options, + resultVar.ptr + ) - return result + if (errorCode != CXErrorCode.CXError_Success) { + val copiedSourceFile = sourceFile.copyTo(createTempFile(suffix = sourceFile.name), overwrite = true) + + error(""" + clang_parseTranslationUnit2 failed with $errorCode; + sourceFile = ${copiedSourceFile.absolutePath} + arguments = ${compilerArgs.joinToString(" ")} + """.trimIndent()) + } + + return resultVar.value!! } }