From fd71520d6e33b481dfe0f4fe0a345e6aaffe0073 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 23 Sep 2021 11:47:18 +0700 Subject: [PATCH] Add test for KT-48807 --- .../native/interop/indexer/WorkaroundTests.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt diff --git a/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt b/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt new file mode 100644 index 00000000000..00ab8985d0e --- /dev/null +++ b/kotlin-native/Interop/Indexer/src/test/kotlin/org/jetbrains/kotlin/native/interop/indexer/WorkaroundTests.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.native.interop.indexer + +import clang.CXTranslationUnit_DetailedPreprocessingRecord +import clang.clang_disposeTranslationUnit +import kotlin.test.Test + +class WorkaroundTests : IndexerTests() { + @Test + fun `KT-48807`() { + if (System.getProperty("os.name") != "Mac OS X") { + return + } + val code = """ + #if !defined(NS_FORMAT_ARGUMENT) + #if defined(__clang__) + #define NS_FORMAT_ARGUMENT(A) __attribute__ ((format_arg(A))) + #else + #define NS_FORMAT_ARGUMENT(A) + #endif + #endif + + NS_FORMAT_ARGUMENT(1) int f(const char* c); + """.trimIndent() + val compilation = CompilationImpl( + includes = emptyList(), + additionalPreambleLines = code.split("\n"), + compilerArgs = listOf(), + language = Language.C + ) + withIndex { index -> + val translationUnit = compilation.parse( + index, + options = CXTranslationUnit_DetailedPreprocessingRecord, + ) + try { + // Will throw `error: function does not return string` if cinterop + // doesn't have a workaround for the `NS_FORMAT_ARGUMENT(A)` macro. + translationUnit.ensureNoCompileErrors() + } finally { + clang_disposeTranslationUnit(translationUnit) + } + } + } +} \ No newline at end of file