From a362742a37a2243f8f8166002a2c3a695b0bfe28 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Thu, 14 Jan 2021 19:16:53 +0300 Subject: [PATCH] Enable C++17 (#4623) --- .../kotlin/backend/konan/CAdapterCompile.kt | 2 +- kotlin-native/backend.native/llvm.def | 2 +- .../backend.native/tests/build.gradle | 2 +- .../kotlin/bitcode/CompileToBitcode.kt | 2 +- kotlin-native/libclangext/build.gradle | 2 +- .../llvmCoverageMappingC/build.gradle | 2 +- kotlin-native/llvmDebugInfoC/build.gradle | 2 +- .../src/main/cpp/DebugInfoC.cpp | 2 +- .../runtime/src/main/cpp/CppSupport.hpp | 28 ------------------- .../runtime/src/main/cpp/MemorySharedRefs.hpp | 6 ++-- .../runtime/src/main/cpp/Natives.cpp | 3 +- kotlin-native/runtime/src/main/cpp/Utils.hpp | 2 -- .../runtime/src/main/cpp/UtilsTest.cpp | 28 +++++++++---------- .../runtime/src/mm/cpp/ObjectFactory.hpp | 4 +-- .../runtime/src/mm/cpp/ObjectFactoryTest.cpp | 2 +- 15 files changed, 28 insertions(+), 61 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterCompile.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterCompile.kt index a9090f656af..cd84b4c4392 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterCompile.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterCompile.kt @@ -10,6 +10,6 @@ import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.file.* fun produceCAdapterBitcode(clang: ClangArgs, cppFileName: String, bitcodeFileName: String) { - val clangCommand = clang.clangCXX("-std=c++14", cppFileName, "-emit-llvm", "-c", "-o", bitcodeFileName) + val clangCommand = clang.clangCXX("-std=c++17", cppFileName, "-emit-llvm", "-c", "-o", bitcodeFileName) Command(clangCommand).execute() } diff --git a/kotlin-native/backend.native/llvm.def b/kotlin-native/backend.native/llvm.def index d93bccffb40..33f813845c1 100644 --- a/kotlin-native/backend.native/llvm.def +++ b/kotlin-native/backend.native/llvm.def @@ -16,7 +16,7 @@ linker = clang++ linkerOpts = -fvisibility-inlines-hidden \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \ -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \ - -std=c++14 \ + -std=c++17 \ -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ -ldebugInfo -lcoverageMapping diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 23f738617ab..d59f61e18d6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -3723,7 +3723,7 @@ createInterop("concurrentTerminate") { it.headers "$projectDir/interop/concurrentTerminate/async.h" // TODO: Using `-Xcompile-source` does not imply dependency on that source, so the task will no re-run when the source is updated. it.extraOpts "-Xcompile-source", "$projectDir/interop/concurrentTerminate/async.cpp" - it.extraOpts "-Xsource-compiler-option", "-std=c++11" + it.extraOpts "-Xsource-compiler-option", "-std=c++17" } createInterop("incomplete_types") { diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt index d06a8614cec..039fb2f39f5 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt @@ -68,7 +68,7 @@ open class CompileToBitcode @Inject constructor( // Used flags provided by original build of allocator C code. listOf("-std=gnu11", "-O3", "-Wall", "-Wextra", "-Werror") Language.CPP -> - listOfNotNull("-std=c++14", "-Werror", "-O2", + listOfNotNull("-std=c++17", "-Werror", "-O2", "-Wall", "-Wextra", "-Wno-unused-parameter", // False positives with polymorphic functions. "-fPIC".takeIf { !HostManager().targetByName(target).isMINGW }) diff --git a/kotlin-native/libclangext/build.gradle b/kotlin-native/libclangext/build.gradle index dd5dd3c356d..d05da0a2718 100644 --- a/kotlin-native/libclangext/build.gradle +++ b/kotlin-native/libclangext/build.gradle @@ -42,7 +42,7 @@ model { binaries.withType(StaticLibraryBinarySpec) { binary -> if (!project.parent.convention.plugins.platformInfo.isWindows()) cppCompiler.args "-fPIC" - cppCompiler.args "--std=c++11", "-g", "-I${llvmDir}/include" + cppCompiler.args "--std=c++17", "-g", "-I${llvmDir}/include" if (isEnabled) { cppCompiler.args '-DLIBCLANGEXT_ENABLE=1' } diff --git a/kotlin-native/llvmCoverageMappingC/build.gradle b/kotlin-native/llvmCoverageMappingC/build.gradle index 12128e116c9..d75738c77d6 100644 --- a/kotlin-native/llvmCoverageMappingC/build.gradle +++ b/kotlin-native/llvmCoverageMappingC/build.gradle @@ -37,7 +37,7 @@ model { binaries.withType(StaticLibraryBinarySpec) { binary -> if (!project.parent.convention.plugins.platformInfo.isWindows()) cppCompiler.args "-fPIC" - cppCompiler.args "--std=c++14", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" + cppCompiler.args "--std=c++17", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" if (isMac()) { cppCompiler.args "-DKONAN_MACOS=1" } else if (isWindows()) { diff --git a/kotlin-native/llvmDebugInfoC/build.gradle b/kotlin-native/llvmDebugInfoC/build.gradle index 76f434c6756..c2d24b17cec 100644 --- a/kotlin-native/llvmDebugInfoC/build.gradle +++ b/kotlin-native/llvmDebugInfoC/build.gradle @@ -37,7 +37,7 @@ model { binaries.withType(StaticLibraryBinarySpec) { binary -> if (!project.parent.convention.plugins.platformInfo.isWindows()) cppCompiler.args "-fPIC" - cppCompiler.args "--std=c++14", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" + cppCompiler.args "--std=c++17", "-I${llvmDir}/include", "-I${projectDir}/src/main/include" linker.args "-L${llvmDir}/lib", "-lLLVMCore", "-lLLVMSupport" } binaries.withType(SharedLibraryBinarySpec) { binary -> diff --git a/kotlin-native/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp b/kotlin-native/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp index 8d07c27ea21..1d1043c25b4 100644 --- a/kotlin-native/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp +++ b/kotlin-native/llvmDebugInfoC/src/main/cpp/DebugInfoC.cpp @@ -25,7 +25,7 @@ #include #include "DebugInfoC.h" /** - * c++ --std=c++14 llvmDebugInfoC/src/DebugInfoC.cpp -IllvmDebugInfoC/include/ -Idependencies/all/clang+llvm-3.9.0-darwin-macos/include -Ldependencies/all/clang+llvm-3.9.0-darwin-macos/lib -lLLVMCore -lLLVMSupport -lncurses -shared -o libLLVMDebugInfoC.dylib + * c++ --std=c++17 llvmDebugInfoC/src/DebugInfoC.cpp -IllvmDebugInfoC/include/ -Idependencies/all/clang+llvm-3.9.0-darwin-macos/include -Ldependencies/all/clang+llvm-3.9.0-darwin-macos/lib -lLLVMCore -lLLVMSupport -lncurses -shared -o libLLVMDebugInfoC.dylib */ namespace llvm { diff --git a/kotlin-native/runtime/src/main/cpp/CppSupport.hpp b/kotlin-native/runtime/src/main/cpp/CppSupport.hpp index e44f9fdc14b..68c7bfb8c21 100644 --- a/kotlin-native/runtime/src/main/cpp/CppSupport.hpp +++ b/kotlin-native/runtime/src/main/cpp/CppSupport.hpp @@ -6,39 +6,11 @@ #ifndef RUNTIME_CPP_SUPPORT_H #define RUNTIME_CPP_SUPPORT_H -#include - // A collection of backported utilities from future C++ versions. namespace kotlin { namespace std_support { -////////////////////////// C++14 ////////////////////////// - -template -using make_unsigned_t = typename std::make_unsigned::type; - -////////////////////////// C++17 ////////////////////////// - -template -constexpr bool is_trivially_destructible_v = std::is_trivially_destructible::value; -template -constexpr bool is_nothrow_default_constructible_v = std::is_nothrow_default_constructible::value; -template -constexpr bool is_nothrow_destructible_v = std::is_nothrow_destructible::value; -template -constexpr bool is_copy_constructible_v = std::is_copy_constructible::value; -template -constexpr bool is_copy_assignable_v = std::is_copy_assignable::value; -template -constexpr bool is_move_constructible_v = std::is_move_constructible::value; -template -constexpr bool is_move_assignable_v = std::is_move_assignable::value; -template -constexpr bool is_nothrow_move_constructible_v = std::is_nothrow_move_constructible::value; -template -constexpr bool is_nothrow_move_assignable_v = std::is_nothrow_move_assignable::value; - } // namespace std_support } // namespace kotlin diff --git a/kotlin-native/runtime/src/main/cpp/MemorySharedRefs.hpp b/kotlin-native/runtime/src/main/cpp/MemorySharedRefs.hpp index 7e2e45b7113..ab40b2457f2 100644 --- a/kotlin-native/runtime/src/main/cpp/MemorySharedRefs.hpp +++ b/kotlin-native/runtime/src/main/cpp/MemorySharedRefs.hpp @@ -8,7 +8,6 @@ #include -#include "CppSupport.hpp" #include "Memory.h" // TODO: Generalize for uses outside this file. @@ -38,8 +37,7 @@ class KRefSharedHolder { ForeignRefContext context_; }; -static_assert( - kotlin::std_support::is_trivially_destructible_v, "KRefSharedHolder destructor is not guaranteed to be called."); +static_assert(std::is_trivially_destructible_v, "KRefSharedHolder destructor is not guaranteed to be called."); class BackRefFromAssociatedObject { public: @@ -68,7 +66,7 @@ class BackRefFromAssociatedObject { }; static_assert( - kotlin::std_support::is_trivially_destructible_v, + std::is_trivially_destructible_v, "BackRefFromAssociatedObject destructor is not guaranteed to be called."); #endif // RUNTIME_MEMORYSHAREDREFS_HPP diff --git a/kotlin-native/runtime/src/main/cpp/Natives.cpp b/kotlin-native/runtime/src/main/cpp/Natives.cpp index 565963aac16..191c322c216 100644 --- a/kotlin-native/runtime/src/main/cpp/Natives.cpp +++ b/kotlin-native/runtime/src/main/cpp/Natives.cpp @@ -21,7 +21,6 @@ #include #include -#include "CppSupport.hpp" #include "KAssert.h" #include "Exceptions.h" #include "Memory.h" @@ -51,7 +50,7 @@ OBJ_GETTER0(Kotlin_native_internal_undefined) { } void* Kotlin_interop_malloc(KLong size, KInt align) { - if (size < 0 || static_cast>(size) > std::numeric_limits::max()) { + if (size < 0 || static_cast>(size) > std::numeric_limits::max()) { return nullptr; } RuntimeAssert(align > 0, "Unsupported alignment"); diff --git a/kotlin-native/runtime/src/main/cpp/Utils.hpp b/kotlin-native/runtime/src/main/cpp/Utils.hpp index e6b94f5a2f8..1f10f53082a 100644 --- a/kotlin-native/runtime/src/main/cpp/Utils.hpp +++ b/kotlin-native/runtime/src/main/cpp/Utils.hpp @@ -6,8 +6,6 @@ #ifndef RUNTIME_UTILS_H #define RUNTIME_UTILS_H -#include "CppSupport.hpp" - namespace kotlin { // A helper for implementing classes with disabled copy constructor and copy assignment. diff --git a/kotlin-native/runtime/src/main/cpp/UtilsTest.cpp b/kotlin-native/runtime/src/main/cpp/UtilsTest.cpp index 5ba0aea917c..178da999c9a 100644 --- a/kotlin-native/runtime/src/main/cpp/UtilsTest.cpp +++ b/kotlin-native/runtime/src/main/cpp/UtilsTest.cpp @@ -5,9 +5,9 @@ #include "Utils.hpp" -#include "gtest/gtest.h" +#include -#include "CppSupport.hpp" +#include "gtest/gtest.h" using namespace kotlin; @@ -30,21 +30,21 @@ public: } // namespace TEST(UtilsTest, MoveOnlyImpl) { - static_assert(std_support::is_nothrow_default_constructible_v, "Must be nothrow default constructible"); - static_assert(std_support::is_nothrow_destructible_v, "Must be nothrow destructible"); - static_assert(!std_support::is_copy_constructible_v, "Must not be copy constructible"); - static_assert(!std_support::is_copy_assignable_v, "Must not be copy assignable"); - static_assert(std_support::is_nothrow_move_constructible_v, "Must be nothrow move constructible"); - static_assert(std_support::is_nothrow_move_assignable_v, "Must be nothrow move assignable"); + static_assert(std::is_nothrow_default_constructible_v, "Must be nothrow default constructible"); + static_assert(std::is_nothrow_destructible_v, "Must be nothrow destructible"); + static_assert(!std::is_copy_constructible_v, "Must not be copy constructible"); + static_assert(!std::is_copy_assignable_v, "Must not be copy assignable"); + static_assert(std::is_nothrow_move_constructible_v, "Must be nothrow move constructible"); + static_assert(std::is_nothrow_move_assignable_v, "Must be nothrow move assignable"); static_assert(sizeof(MoveOnlyImpl) == sizeof(A), "Must not increase size"); } TEST(UtilsTest, PinnedImpl) { - static_assert(std_support::is_nothrow_default_constructible_v, "Must be nothrow default constructible"); - static_assert(std_support::is_nothrow_destructible_v, "Must be nothrow destructible"); - static_assert(!std_support::is_copy_constructible_v, "Must not be copy constructible"); - static_assert(!std_support::is_copy_assignable_v, "Must not be copy assignable"); - static_assert(!std_support::is_move_constructible_v, "Must not be move constructible"); - static_assert(!std_support::is_move_assignable_v, "Must not be move assignable"); + static_assert(std::is_nothrow_default_constructible_v, "Must be nothrow default constructible"); + static_assert(std::is_nothrow_destructible_v, "Must be nothrow destructible"); + static_assert(!std::is_copy_constructible_v, "Must not be copy constructible"); + static_assert(!std::is_copy_assignable_v, "Must not be copy assignable"); + static_assert(!std::is_move_constructible_v, "Must not be move constructible"); + static_assert(!std::is_move_assignable_v, "Must not be move assignable"); static_assert(sizeof(PinnedImpl) == sizeof(A), "Must not increase size"); } diff --git a/kotlin-native/runtime/src/mm/cpp/ObjectFactory.hpp b/kotlin-native/runtime/src/mm/cpp/ObjectFactory.hpp index 99fc269c7d5..b28d093f149 100644 --- a/kotlin-native/runtime/src/mm/cpp/ObjectFactory.hpp +++ b/kotlin-native/runtime/src/mm/cpp/ObjectFactory.hpp @@ -9,10 +9,10 @@ #include #include #include +#include #include "Alignment.hpp" #include "Alloc.h" -#include "CppSupport.hpp" #include "Memory.h" #include "Mutex.hpp" #include "Types.h" @@ -106,7 +106,7 @@ public: template Node& Insert(Args&&... args) noexcept { static_assert(alignof(T) <= DataAlignment, "Cannot insert type with alignment bigger than DataAlignment"); - static_assert(std_support::is_trivially_destructible_v, "Type must be trivially destructible"); + static_assert(std::is_trivially_destructible_v, "Type must be trivially destructible"); auto& node = Insert(sizeof(T)); new (node.Data()) T(std::forward(args)...); return node; diff --git a/kotlin-native/runtime/src/mm/cpp/ObjectFactoryTest.cpp b/kotlin-native/runtime/src/mm/cpp/ObjectFactoryTest.cpp index 3eca0b91496..d235e54bb66 100644 --- a/kotlin-native/runtime/src/mm/cpp/ObjectFactoryTest.cpp +++ b/kotlin-native/runtime/src/mm/cpp/ObjectFactoryTest.cpp @@ -7,11 +7,11 @@ #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "CppSupport.hpp" #include "TestSupport.hpp" #include "Types.h"