[K/N] Fix for KT-48807

Make NS_FORMAT_ARGUMENT(A) a no-op in cinterop because our
Clang doesn't support it for NSAttributedString.
This commit is contained in:
Sergey Bogolepov
2021-09-23 12:32:42 +07:00
committed by Space
parent fd71520d6e
commit ed4fa2c391
3 changed files with 32 additions and 23 deletions
@@ -58,6 +58,34 @@ interface Compilation {
val language: Language
}
fun defaultCompilerArgs(language: Language): List<String> =
listOf(
// We compile with -O2 because Clang may insert inline asm in bitcode at -O0.
// It is undesirable in case of watchos_arm64 since we target armv7k
// for this target instead of arm64_32 because it is not supported in LLVM 8.
//
// Note that PCH and the *.c file should be compiled with the same optimization level.
"-O2",
// Allow throwing exceptions through generated stubs.
"-fexceptions",
) + when (language) {
Language.C -> emptyList()
Language.CPP -> emptyList()
Language.OBJECTIVE_C -> listOf(
// "Objective-C" within interop means "Objective-C with ARC":
"-fobjc-arc",
// Using this flag here has two effects:
// 1. The headers are parsed with ARC enabled, thus the API is visible correctly.
// 2. The generated Objective-C stubs are compiled with ARC enabled, so reference counting
// calls are inserted automatically.
// Workaround for https://youtrack.jetbrains.com/issue/KT-48807.
// TODO(LLVM): Remove after update to a version with
// https://github.com/apple/llvm-project/commit/2de0a18a8949f0235fb3a08dcc55ff3aa7d969e7.
"-DNS_FORMAT_ARGUMENT(A)="
)
}
data class CompilationWithPCH(
override val compilerArgs: List<String>,
override val language: Language
@@ -26,11 +26,12 @@ class WorkaroundTests : IndexerTests() {
NS_FORMAT_ARGUMENT(1) int f(const char* c);
""".trimIndent()
val language = Language.OBJECTIVE_C
val compilation = CompilationImpl(
includes = emptyList(),
additionalPreambleLines = code.split("\n"),
compilerArgs = listOf(),
language = Language.C
compilerArgs = defaultCompilerArgs(language),
language = language
)
withIndex { index ->
val translationUnit = compilation.parse(
@@ -477,34 +477,14 @@ internal fun buildNativeLibrary(
val compilerOpts: List<String> = mutableListOf<String>().apply {
addAll(def.config.compilerOpts)
addAll(tool.getDefaultCompilerOptsForLanguage(language))
// We compile with -O2 because Clang may insert inline asm in bitcode at -O0.
// It is undesirable in case of watchos_arm64 since we target armv7k
// for this target instead of arm64_32 because it is not supported in LLVM 8.
//
// Note that PCH and the *.c file should be compiled with the same optimization level.
add("-O2")
// Allow throwing exceptions through generated stubs.
add("-fexceptions")
addAll(additionalCompilerOpts)
addAll(getCompilerFlagsForVfsOverlay(arguments.headerFilterPrefix.toTypedArray(), def))
addAll(when (language) {
Language.C -> emptyList()
Language.CPP -> emptyList()
Language.OBJECTIVE_C -> {
// "Objective-C" within interop means "Objective-C with ARC":
listOf("-fobjc-arc")
// Using this flag here has two effects:
// 1. The headers are parsed with ARC enabled, thus the API is visible correctly.
// 2. The generated Objective-C stubs are compiled with ARC enabled, so reference counting
// calls are inserted automatically.
}
})
}
val compilation = CompilationImpl(
includes = headerFiles,
additionalPreambleLines = def.defHeaderLines,
compilerArgs = compilerOpts + tool.platformCompilerOpts,
compilerArgs = defaultCompilerArgs(language) + compilerOpts + tool.platformCompilerOpts,
language = language
)