From ebbf86b42d1d227c0454194694f818e4358ef490 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Thu, 3 May 2018 15:01:21 +0700 Subject: [PATCH] Boolean type fix --- .../jetbrains/kotlin/backend/konan/CAdapterGenerator.kt | 8 +++++++- .../jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt | 2 +- .../jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt | 9 ++++----- .../kotlin/org/jetbrains/kotlin/compiletest/LldbTests.kt | 3 +-- runtime/src/main/cpp/Types.h | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt index 5c37d8bad63..dd2a1d60d5d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt @@ -757,7 +757,13 @@ internal class CAdapterGenerator( #ifdef __cplusplus extern "C" { #endif""".trimIndent()) - output("typedef unsigned char ${prefix}_KBoolean;") + output(""" + #ifdef __cplusplus + typedef bool ${prefix}_KBoolean; + #else + typedef _Bool ${prefix}_KBoolean; + #endif + """.trimIndent()) output("typedef char ${prefix}_KByte;") output("typedef unsigned short ${prefix}_KChar;") output("typedef short ${prefix}_KShort;") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt index 0049dced668..fcb73b27f10 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/DebugUtils.kt @@ -54,12 +54,12 @@ internal class DebugInfo internal constructor(override val context: Context):Con var types = mutableMapOf() val llvmTypes = mapOf( + context.builtIns.booleanType to LLVMInt8Type()!!, context.builtIns.byteType to LLVMInt8Type()!!, context.builtIns.charType to LLVMInt8Type()!!, context.builtIns.shortType to LLVMInt16Type()!!, context.builtIns.intType to LLVMInt32Type()!!, context.builtIns.longType to LLVMInt64Type()!!, - context.builtIns.booleanType to LLVMInt1Type()!!, context.builtIns.floatType to LLVMFloatType()!!, context.builtIns.doubleType to LLVMDoubleType()!!) val intTypes = listOf(context.builtIns.byteType, context.builtIns.shortType, context.builtIns.intType, context.builtIns.longType) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index ee153a33d96..cfae7cc5b3c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -1332,8 +1332,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map) { @@ -54,7 +53,7 @@ class LldbTests { (int) b = 2 (long) c = -3 (unsigned char) d = 'c' - (void) e = + (bool) e = true """) @Test diff --git a/runtime/src/main/cpp/Types.h b/runtime/src/main/cpp/Types.h index a24582dc2ee..db2522a5bb0 100644 --- a/runtime/src/main/cpp/Types.h +++ b/runtime/src/main/cpp/Types.h @@ -36,7 +36,7 @@ #include "TypeInfo.h" // Note that almost all types are signed. -typedef uint8_t KBoolean; +typedef bool KBoolean; typedef int8_t KByte; typedef uint16_t KChar; typedef int16_t KShort;