From: robert Date: Tue, 11 Sep 2018 18:18:58 +0000 (+0000) Subject: import of libc++ 6.0.0 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=820e1f31efc1d6ed04795ba2e79f3044e1907492;p=openbsd import of libc++ 6.0.0 --- diff --git a/lib/libcxx/CMakeLists.txt b/lib/libcxx/CMakeLists.txt index d618e8358ca..9e8e9d5e3d9 100644 --- a/lib/libcxx/CMakeLists.txt +++ b/lib/libcxx/CMakeLists.txt @@ -19,23 +19,25 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ) -# Find the LLVM sources and simulate LLVM CMake options. -include(HandleOutOfTreeLLVM) - -if (LIBCXX_BUILT_STANDALONE) +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) project(libcxx CXX C) set(PACKAGE_NAME libcxx) - set(PACKAGE_VERSION trunk-svn) + set(PACKAGE_VERSION 6.0.0) set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") -endif () -if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND) - message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: " - "llvm-config not found and LLVM_PATH not defined.\n" - "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config " - "or -DLLVM_PATH=path/to/llvm-source-root.") + # Find the LLVM sources and simulate LLVM CMake options. + include(HandleOutOfTreeLLVM) +endif() + +if (LIBCXX_STANDALONE_BUILD) + include(FindPythonInterp) + if( NOT PYTHONINTERP_FOUND ) + message(WARNING "Failed to find python interpreter. " + "The libc++ test suite will be disabled.") + set(LLVM_INCLUDE_TESTS OFF) + endif() endif() # Require out of source build. @@ -45,46 +47,103 @@ MACRO_ENSURE_OUT_OF_SOURCE_BUILD( build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." ) +if (MSVC) + set(LIBCXX_TARGETING_MSVC ON) +else() + set(LIBCXX_TARGETING_MSVC OFF) +endif() + #=============================================================================== # Setup CMake Options #=============================================================================== +include(CMakeDependentOption) +include(HandleCompilerRT) # Basic options --------------------------------------------------------------- -option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) +option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF) option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) +option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON) -option(LIBCXX_ENABLE_FILESYSTEM - "Build filesystem as part of libc++experimental.a" ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY}) +set(ENABLE_FILESYSTEM_DEFAULT ${LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY}) +if (WIN32) + set(ENABLE_FILESYSTEM_DEFAULT OFF) +endif() +option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of libc++experimental.a" + ${ENABLE_FILESYSTEM_DEFAULT}) option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) + +# Benchmark options ----------------------------------------------------------- +option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON) +set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING + "Build the benchmarks against the specified native STL. + The value must be one of libc++/libstdc++") +set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING + "Use alternate GCC toolchain when building the native benchmarks") + +if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" + OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) + message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " + "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") + endif() +endif() + option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING "Define suffix of library directory name (32/64)") option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) -option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY "Install libc++experimental.a" OFF) +cmake_dependent_option(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY + "Install libc++experimental.a" ON + "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY;LIBCXX_INSTALL_LIBRARY" OFF) set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) +option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") +option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") +set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") +option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) + +if (NOT LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_STATIC) + message(FATAL_ERROR "libc++ must be built as either a shared or static library.") +endif() # ABI Library options --------------------------------------------------------- -set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING - "Specify C++ ABI library to use." FORCE) -set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) +set(LIBCXX_CXX_ABI "default" CACHE STRING + "Specify C++ ABI library to use.") +set(CXXABIS none default libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) # Setup the default options if LIBCXX_CXX_ABI is not specified. -if (NOT LIBCXX_CXX_ABI) - if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND - IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") +if (LIBCXX_CXX_ABI STREQUAL "default") + find_path( + LIBCXX_LIBCXXABI_INCLUDES_INTERNAL + cxxabi.h + PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include + ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include + ${LLVM_MAIN_SRC_DIR}/../libcxxabi/include + NO_DEFAULT_PATH + ) + if (LIBCXX_TARGETING_MSVC) + # FIXME: Figure out how to configure the ABI library on Windows. + set(LIBCXX_CXX_ABI_LIBNAME "vcruntime") + elseif ((NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) AND + IS_DIRECTORY "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") - set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") + set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDES_INTERNAL}") set(LIBCXX_CXX_ABI_INTREE 1) - else () - set(LIBCXX_CXX_ABI_LIBNAME "none") - endif () -else () + elseif (APPLE) + set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") + set(LIBCXX_CXX_ABI_SYSTEM 1) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt") + set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1") + else() + set(LIBCXX_CXX_ABI_LIBNAME "default") + endif() +else() set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") -endif () +endif() # Use a static copy of the ABI library when linking libc++. This option # cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. @@ -92,12 +151,13 @@ option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) # Generate and install a linker script inplace of libc++.so. The linker script # will link libc++ to the correct ABI library. This option is on by default -# On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' +# on UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' # is on. This option is also disabled when the ABI library is not specified # or is specified to be "none". set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" + AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" AND PYTHONINTERP_FOUND AND LIBCXX_ENABLE_SHARED) set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) @@ -107,9 +167,25 @@ option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT "Use and install a linker script for the given ABI library" ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) +set(ENABLE_NEW_DELETE_DEFAULT ON) +if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) +# FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link +# programs due to undefined references to new/delete in libc++abi so to work +# around this libc++abi currently defaults LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS +# to ON. Once the GCC bug has been worked around this option should be changed +# back to OFF. + set(ENABLE_NEW_DELETE_DEFAULT ON) +endif() + +option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS + "Build libc++ with definitions for operator new/delete. This option can + be used to disable the definitions when libc++abi is expected to provide + them" ${ENABLE_NEW_DELETE_DEFAULT}) + # Build libc++abi with libunwind. We need this option to determine whether to # link with libunwind or libgcc_s while running the test cases. option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) +option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF) # Target options -------------------------------------------------------------- option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) @@ -129,6 +205,12 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) +option(LIBCXX_HAS_EXTERNAL_THREAD_API + "Build libc++ with an externalized threading API. + This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) +option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY + "Build libc++ with an externalized threading library. + This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF) # Misc options ---------------------------------------------------------------- # FIXME: Turn -pedantic back ON. It is currently off because it warns @@ -181,9 +263,33 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) " when LIBCXX_ENABLE_THREADS is also set to OFF.") endif() -if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS) - message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" - " when LIBCXX_ENABLE_THREADS is also set to ON.") +if(NOT LIBCXX_ENABLE_THREADS) + if(LIBCXX_HAS_PTHREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" + " when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + if(LIBCXX_HAS_EXTERNAL_THREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" + " when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) + message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set " + "to ON when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + +endif() + +if (LIBCXX_HAS_EXTERNAL_THREAD_API) + if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) + message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and " + "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at " + "the same time") + endif() + if (LIBCXX_HAS_PTHREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" + "and LIBCXX_HAS_PTHREAD_API cannot be both" + "set to ON at the same time.") + endif() endif() # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE @@ -209,6 +315,9 @@ if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) else() message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") endif() + if (LIBCXX_ENABLE_STATIC AND NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") + endif() endif() if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) @@ -234,6 +343,10 @@ if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") endif() +if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT) + message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.") +endif () + #=============================================================================== # Configure System #=============================================================================== @@ -241,19 +354,37 @@ endif() set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER}) set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") +if (LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +endif() +file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") + +set(LIBCXX_INSTALL_PREFIX "" CACHE STRING + "Define libc++ destination prefix.") + +if (NOT LIBCXX_INSTALL_PREFIX MATCHES "^$|.*/") + message(FATAL_ERROR "LIBCXX_INSTALL_PREFIX has to end with \"/\".") +endif() set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) # Declare libc++ configuration variables. # They are intended for use as follows: # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. # LIBCXX_COMPILE_FLAGS: Compile only flags. # LIBCXX_LINK_FLAGS: Linker only flags. +# LIBCXX_LIBRARIES: libraries libc++ is linked to. +# LIBCXX_INTERFACE_LIBRARIES: Libraries that must be linked when using libc++ +# These libraries are exposed in the linker script. set(LIBCXX_COMPILE_FLAGS "") set(LIBCXX_LINK_FLAGS "") set(LIBCXX_LIBRARIES "") +set(LIBCXX_INTERFACE_LIBRARIES "") # Include macros for adding and removing libc++ flags. include(HandleLibcxxFlags) @@ -263,13 +394,20 @@ include(HandleLibcxxFlags) # 'config-ix' use them during feature checks. It also adds them to both # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' add_target_flags_if(LIBCXX_BUILD_32_BITS "-m32") -add_target_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") +add_target_flags_if(LIBCXX_TARGET_TRIPLE "--target=${LIBCXX_TARGET_TRIPLE}") add_target_flags_if(LIBCXX_SYSROOT "--sysroot=${LIBCXX_SYSROOT}") -add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") +add_target_flags_if(LIBCXX_GCC_TOOLCHAIN "--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") +if (LIBCXX_TARGET_TRIPLE) + set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") +endif() # Configure compiler. include(config-ix) +if (LIBCXX_USE_COMPILER_RT) + list(APPEND LIBCXX_LINK_FLAGS "-rtlib=compiler-rt") +endif() + # Configure coverage options. if (LIBCXX_GENERATE_COVERAGE) include(CodeCoverage) @@ -277,6 +415,11 @@ if (LIBCXX_GENERATE_COVERAGE) endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) +if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") + set(LIBCXX_DEBUG_BUILD ON) +else() + set(LIBCXX_DEBUG_BUILD OFF) +endif() #=============================================================================== # Setup Compiler Flags @@ -284,19 +427,36 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) include(HandleLibCXXABI) # Setup the ABI library flags -# Remove flags that may have snuck in. -remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG - -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) +if (NOT LIBCXX_STANDALONE_BUILD) + # Remove flags that may have snuck in. + remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG + -lc++abi) +endif() +remove_flags(-stdlib=libc++ -stdlib=libstdc++) + +# FIXME: Remove all debug flags and flags that change which Windows +# default libraries are linked. Currently we only support linking the +# non-debug DLLs +remove_flags("/D_DEBUG" "/MTd" "/MDd" "/MT" "/Md") # FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. # Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors -# so they don't get transformed into -Wno and -errors respectivly. +# so they don't get transformed into -Wno and -errors respectively. remove_flags(-Wno-pedantic -pedantic-errors -pedantic) # Required flags ============================================================== -add_compile_flags_if_supported(-std=c++11) -if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) - message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") +set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect") +if (LIBCXX_HAS_MUSL_LIBC) + # musl's pthread implementations uses volatile types in their structs which is + # not a constexpr in C++11 but is in C++14, so we use C++14 with musl. + set(LIBCXX_STANDARD_VER c++14 CACHE INTERNAL "internal option to change build dialect") +endif() +add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER}) +mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME) +if(NOT ${SUPPORTS_DIALECT_NAME}) + if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") + message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}") + endif() endif() # On all systems the system c++ standard library headers need to be excluded. @@ -305,14 +465,40 @@ endif() # headers add_compile_flags_if_supported(-nostdinc++) +# Hide all inline function definitions which have not explicitly been marked +# visible. This prevents new definitions for inline functions from appearing in +# the dylib when get ODR used by another function. +add_compile_flags_if_supported(-fvisibility-inlines-hidden) + +if (LIBCXX_CONFIGURE_IDE) + # This simply allows IDE to process + add_compile_flags_if_supported(-fcoroutines-ts) +endif() + +# Let the library headers know they are currently being used to build the +# library. +add_definitions(-D_LIBCPP_BUILDING_LIBRARY) + +if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) +endif() # Warning flags =============================================================== add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) add_compile_flags_if_supported( - -Wall -W -Wwrite-strings - -Wno-unused-parameter -Wno-long-long -Wno-user-defined-literals - -Wno-covered-switch-default + -Wall -Wextra -W -Wwrite-strings + -Wno-unused-parameter -Wno-long-long -Werror=return-type) +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + add_compile_flags_if_supported( + -Wno-user-defined-literals + -Wno-covered-switch-default) +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + add_compile_flags_if_supported( + -Wno-literal-suffix + -Wno-c++14-compat + -Wno-noexcept-type) +endif() if (LIBCXX_ENABLE_WERROR) add_compile_flags_if_supported(-Werror) add_compile_flags_if_supported(-WX) @@ -346,22 +532,42 @@ if (NOT LIBCXX_ENABLE_RTTI) add_compile_flags_if_supported(-fno-rtti) endif() +# Threading flags ============================================================= +if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED) + # Need to allow unresolved symbols if this is to work with shared library builds + if (APPLE) + add_link_flags("-undefined dynamic_lookup") + else() + # Relax this restriction from HandleLLVMOptions + string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") + endif() +endif() + # Assertion flags ============================================================= define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) -if (LIBCXX_ENABLE_ASSERTIONS) +define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0) +define_if(LIBCXX_DEBUG_BUILD -D_DEBUG) +if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD) # MSVC doesn't like _DEBUG on release builds. See PR 4379. - define_if_not(MSVC -D_DEBUG) + define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG) endif() -# Feature flags =============================================================== -define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) +# Modules flags =============================================================== +# FIXME The libc++ sources are fundamentally non-modular. They need special +# versions of the headers in order to provide C++03 and legacy ABI definitions. +# NOTE: The public headers can be used with modules in all other contexts. +if (LLVM_ENABLE_MODULES) + # Ignore that the rest of the modules flags are now unused. + add_compile_flags_if_supported(-Wno-unused-command-line-argument) + add_compile_flags(-fno-modules) +endif() # Sanitizer flags ============================================================= -# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do +# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. -if (LIBCXX_BUILT_STANDALONE) +if (LIBCXX_STANDALONE_BUILD) set(LLVM_USE_SANITIZER "" CACHE STRING "Define the sanitizer used to build the library and tests") # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. @@ -398,6 +604,8 @@ if (NOT LIBCXX_ABI_VERSION EQUAL "1") config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) endif() config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) +config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) +config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) @@ -407,16 +615,49 @@ config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOC config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) +config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) +config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) +config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) +if (LIBCXX_ABI_DEFINES) + set(abi_defines) + foreach (abi_define ${LIBCXX_ABI_DEFINES}) + if (NOT abi_define MATCHES "^_LIBCPP_ABI_") + message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") + endif() + list(APPEND abi_defines "#define ${abi_define}") + endforeach() + string(REPLACE ";" "\n" abi_defines "${abi_defines}") + config_define(${abi_defines} _LIBCPP_ABI_DEFINES) +endif() + +# By default libc++ on Windows expects to use a shared library, which requires +# the headers to use DLL import/export semantics. However when building a +# static library only we modify the headers to disable DLL import/export. +if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) + message(STATUS "Generating custom __config for non-DLL Windows build") + config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +endif() + +set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site") if (LIBCXX_NEEDS_SITE_CONFIG) - configure_file( - include/__config_site.in - ${LIBCXX_BINARY_DIR}/__config_site - @ONLY) + configure_file("include/__config_site.in" + "${site_config_path}" + @ONLY) + # Provide the config definitions by included the generated __config_site # file at compile time. - add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") + add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"") + else() + add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") + endif() +else() + if (EXISTS "${site_config_path}") + message(STATUS "Removing stale site configuration ${site_config_path}") + file(REMOVE "${site_config_path}") + endif() endif() #=============================================================================== @@ -426,9 +667,35 @@ include_directories(include) add_subdirectory(include) add_subdirectory(lib) -if (LIBCXX_INCLUDE_TESTS) + +if (LIBCXX_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + +# Create the lit.site.cfg file even when LIBCXX_INCLUDE_TESTS is OFF or +# LLVM_FOUND is OFF. This allows users to run the tests manually using +# LIT without requiring a full LLVM checkout. +# +# However, since some submission systems strip test/ subdirectories, check for +# it before adding it. + +if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test") add_subdirectory(test) endif() +if (LIBCXX_INCLUDE_TESTS) + add_subdirectory(lib/abi) +endif() + +if (LIBCXX_STANDALONE_BUILD AND EXISTS "${LLVM_MAIN_SRC_DIR}/utils/llvm-lit") + include(AddLLVM) # for get_llvm_lit_path + # Make sure the llvm-lit script is generated into the bin directory, and do + # it after adding all tests, since the generated script will only work + # correctly discovered tests against test locations from the source tree that + # have already been discovered. + add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit + ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit) +endif() + if (LIBCXX_INCLUDE_DOCS) add_subdirectory(docs) endif() diff --git a/lib/libcxx/CREDITS.TXT b/lib/libcxx/CREDITS.TXT index ceb12c42b96..46a06c6eab0 100644 --- a/lib/libcxx/CREDITS.TXT +++ b/lib/libcxx/CREDITS.TXT @@ -41,6 +41,10 @@ N: Jonathan B Coe E: jbcoe@me.com D: Implementation of propagate_const. +N: Glen Joseph Fernandes +E: glenjofe@gmail.com +D: Implementation of to_address. + N: Eric Fiselier E: eric@efcs.ca D: LFTS support, patches and bug fixes. @@ -80,6 +84,10 @@ N: Andrew Morrow E: andrew.c.morrow@gmail.com D: Minor patches and Linux fixes. +N: Michael Park +E: mcypark@gmail.com +D: Implementation of . + N: Arvid Picciani E: aep at exys dot org D: Minor patches and musl port. @@ -93,7 +101,7 @@ E: nico.rieck@gmail.com D: Windows fixes N: Jon Roelofs -E: jonathan@codesourcery.com +E: jroelofS@jroelofs.com D: Remote testing, Newlib port, baremetal/single-threaded support. N: Jonathan Sauer diff --git a/lib/libcxx/LICENSE.TXT b/lib/libcxx/LICENSE.TXT index 339e232c68f..c278f2c9283 100644 --- a/lib/libcxx/LICENSE.TXT +++ b/lib/libcxx/LICENSE.TXT @@ -14,7 +14,7 @@ Full text of the relevant licenses is included below. University of Illinois/NCSA Open Source License -Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT +Copyright (c) 2009-2017 by the contributors listed in CREDITS.TXT All rights reserved. diff --git a/lib/libcxx/NOTES.TXT b/lib/libcxx/NOTES.TXT new file mode 100644 index 00000000000..f0597de64ae --- /dev/null +++ b/lib/libcxx/NOTES.TXT @@ -0,0 +1,28 @@ +//===---------------------------------------------------------------------===// +// Notes relating to various libc++ tasks +//===---------------------------------------------------------------------===// + +This file contains notes about various libc++ tasks and processes. + +//===---------------------------------------------------------------------===// +// Post-Release TODO +//===---------------------------------------------------------------------===// + +These notes contain a list of things that must be done after branching for +an LLVM release. + +1. Update _LIBCPP_VERSION in `__config` +2. Update the __libcpp_version file. +3. Update the version number in `docs/conf.py` +4. Create ABI lists for the previous release under `lib/abi` + +//===---------------------------------------------------------------------===// +// Adding a new header TODO +//===---------------------------------------------------------------------===// + +These notes contain a list of things that must be done upon adding a new header +to libc++. + +1. Add a test under `test/libcxx` that the header defines `_LIBCPP_VERSION`. +2. Update `test/libcxx/double_include.sh.cpp` to include the new header. +3. Create a submodule in `include/module.modulemap` for the new header. diff --git a/lib/libcxx/TODO.TXT b/lib/libcxx/TODO.TXT index bdb94de343d..652a38de75a 100644 --- a/lib/libcxx/TODO.TXT +++ b/lib/libcxx/TODO.TXT @@ -1,56 +1,76 @@ This is meant to be a general place to list things that should be done "someday" -3.8 Release Goals -================= -* LFTS v1 (EricWF, MClow) -* Filesystem TS (EricWF) -* ASIO TS (MClow) -* Improvements (MClow) -* Setup ABI Versioning policy (EricWF) -* Fix PR19302 - Fix UB in list and __tree. - - -ABI Related Tasks -================= -* Explicitly manage and verify symbols exported from the dylib. -* Explore using namespaces for managing symbol visibility. -* Introduce and document ABI versioning/evolution policy. - CXX Runtime Library Tasks ========================= -* Cleanup #ifdef hell in sources files that supports the different ABI libraries. * Fix that CMake always link to /usr/lib/libc++abi.dylib on OS X. -* Fix selection of ABI symbol list on OS X. -* Have CMake generate linker scripts for libc++.so that it properly links the - runtime library. * Look into mirroring libsupc++'s typeinfo vtable layout when libsupc++/libstdc++ is used as the runtime library. -* Audit libraries that CMake links into libc++. Are they all required? * Investigate and document interoperability between libc++ and libstdc++ on linux. Do this for every supported c++ runtime library. Atomic Related Tasks ==================== -* Enable mixing of clang and GCC atomics internally. Currently some - parts of libc++ use atomics only when clang provides them. - (see memory@5380 for an example) -* Audit use of libatomic builtins in with GCC. * future should use for synchronization. Test Suite Tasks ================ -* Move all libc++ specific tests from test/std into test/libcxx. -* Improve how LIT handles compiler warnings. * Improve the quality and portability of the locale test data. * Convert failure tests to use Clang Verify. +Filesystem Tasks +================ +* P0492r2 - Implement National body comments for Filesystem + * INCOMPLETE - US 25: has_filename() is equivalent to just !empty() + * INCOMPLETE - US 31: Everything is defined in terms of one implicit host system + * INCOMPLETE - US 32: Meaning of 27.10.2.1 unclear + * INCOMPLETE - US 33: Definition of canonical path problematic + * INCOMPLETE - US 34: Are there attributes of a file that are not an aspect of the file system? + * INCOMPLETE - US 35: What synchronization is required to avoid a file system race? + * INCOMPLETE - US 36: Symbolic links themselves are attached to a directory via (hard) links + * INCOMPLETE - US 37: The term “redundant current directory (dot) elements” is not defined + * INCOMPLETE - US 38: Duplicates §17.3.16 + * INCOMPLETE - US 39: Remove note: Dot and dot-dot are not directories + * INCOMPLETE - US 40: Not all directories have a parent. + * INCOMPLETE - US 41: The term “parent directory” for a (non-directory) file is unusual + * INCOMPLETE - US 42: Pathname resolution does not always resolve a symlink + * INCOMPLETE - US 43: Concerns about encoded character types + * INCOMPLETE - US 44: Definition of path in terms of a string requires leaky abstraction + * INCOMPLETE - US 45: Generic format portability compromised by unspecified root-name + * INCOMPLETE - US 46: filename can be empty so productions for relative-path are redundant + * INCOMPLETE - US 47: “.” and “..” already match the name production + * INCOMPLETE - US 48: Multiple separators are often meaningful in a root-name + * INCOMPLETE - US 49: What does “method of conversion method” mean? + * INCOMPLETE - US 50: 27.10.8.1 ¶ 1.4 largely redundant with ¶ 1.3 + * INCOMPLETE - US 51: Failing to add / when appending empty string prevents useful apps + * INCOMPLETE - US 52: remove_filename() postcondition is not by itself a definition + * INCOMPLETE - US 53: remove_filename()'s name does not correspond to its behavior + * INCOMPLETE - US 54: remove_filename() is broken + * INCOMPLETE - US 55: replace_extension()'s use of path as parameter is inappropriate + * INCOMPLETE - US 56: Remove replace_extension()'s conditional addition of period + * INCOMPLETE - US 57: On Windows, absolute paths will sort in among relative paths + * INCOMPLETE - US 58: parent_path() behavior for root paths is useless + * INCOMPLETE - US 59: filename() returning path for single path components is bizarre + * INCOMPLETE - US 60: path("/foo/").filename()==path(".") is surprising + * INCOMPLETE - US 61: Leading dots in filename() should not begin an extension + * INCOMPLETE - US 62: It is important that stem()+extension()==filename() + * INCOMPLETE - US 63: lexically_normal() inconsistently treats trailing "/" but not "/.." as directory + * INCOMPLETE - US 73, CA 2: root-name is effectively implementation defined + * INCOMPLETE - US 74, CA 3: The term “pathname” is ambiguous in some contexts + * INCOMPLETE - US 75, CA 4: Extra flag in path constructors is needed + * INCOMPLETE - US 76, CA 5: root-name definition is over-specified. + * INCOMPLETE - US 77, CA 6: operator/ and other appends not useful if arg has root-name + * INCOMPLETE - US 78, CA 7: Member absolute() in 27.10.4.1 is overspecified for non-POSIX-like O/S + * INCOMPLETE - US 79, CA 8: Some operation functions are overspecified for implementation-defined file types + * INCOMPLETE - US 185: Fold error_code and non-error_code signatures into one signature + * INCOMPLETE - FI 14: directory_entry comparisons are members + * INCOMPLETE - Late 36: permissions() error_code overload should be noexcept + * INCOMPLETE - Late 37: permissions() actions should be separate parameter + * INCOMPLETE - Late 42: resize_file() Postcondition missing argument + Misc Tasks ========== * Find all sequences of >2 underscores and eradicate them. * run clang-tidy on libc++ * Document the "conditionally-supported" bits of libc++ * Look at basic_string's move assignment operator, re LWG 2063 and POCMA -* libc++ is missing try_emplace * Put a static_assert in std::allocator to deny const/volatile types (LWG 2447) -* Document support (or lack of) for C++11 libraries in C++03. -* Document supported compilers. diff --git a/lib/libcxx/benchmarks/CMakeLists.txt b/lib/libcxx/benchmarks/CMakeLists.txt new file mode 100644 index 00000000000..8211ebd009a --- /dev/null +++ b/lib/libcxx/benchmarks/CMakeLists.txt @@ -0,0 +1,156 @@ +include(ExternalProject) +include(CheckCXXCompilerFlag) + +#============================================================================== +# Build Google Benchmark for libc++ +#============================================================================== + +set(BENCHMARK_LIBCXX_COMPILE_FLAGS + -Wno-unused-command-line-argument + -nostdinc++ + -isystem ${LIBCXX_SOURCE_DIR}/include + -L${LIBCXX_LIBRARY_DIR} + -Wl,-rpath,${LIBCXX_LIBRARY_DIR} + ) +if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH) + list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS + -L${LIBCXX_CXX_ABI_LIBRARY_PATH} + -Wl,-rpath,${LIBCXX_CXX_ABI_LIBRARY_PATH}) +endif() +split_list(BENCHMARK_LIBCXX_COMPILE_FLAGS) + +ExternalProject_Add(google-benchmark-libcxx + EXCLUDE_FROM_ALL ON + DEPENDS cxx + PREFIX benchmark-libcxx + SOURCE_DIR ${LIBCXX_SOURCE_DIR}/utils/google-benchmark + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx + CMAKE_CACHE_ARGS + -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_BUILD_TYPE:STRING=RELEASE + -DCMAKE_INSTALL_PREFIX:PATH= + -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_LIBCXX_COMPILE_FLAGS} + -DBENCHMARK_USE_LIBCXX:BOOL=ON + -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) + +#============================================================================== +# Build Google Benchmark for the native stdlib +#============================================================================== +set(BENCHMARK_NATIVE_TARGET_FLAGS) +if (LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN) + set(BENCHMARK_NATIVE_TARGET_FLAGS + -gcc-toolchain ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN}) +endif() +split_list(BENCHMARK_NATIVE_TARGET_FLAGS) + +if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + ExternalProject_Add(google-benchmark-native + EXCLUDE_FROM_ALL ON + PREFIX benchmark-native + SOURCE_DIR ${LIBCXX_SOURCE_DIR}/utils/google-benchmark + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native + CMAKE_CACHE_ARGS + -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_NATIVE_TARGET_FLAGS} + -DCMAKE_BUILD_TYPE:STRING=RELEASE + -DCMAKE_INSTALL_PREFIX:PATH= + -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) +endif() + +#============================================================================== +# Benchmark tests configuration +#============================================================================== +add_custom_target(cxx-benchmarks) +set(BENCHMARK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx) +set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native) +set(BENCHMARK_TEST_COMPILE_FLAGS + -std=c++14 -O2 + -I${BENCHMARK_LIBCXX_INSTALL}/include + -I${LIBCXX_SOURCE_DIR}/test/support +) +set(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS + -nostdinc++ + -isystem ${LIBCXX_SOURCE_DIR}/include + ${BENCHMARK_TEST_COMPILE_FLAGS} + -Wno-user-defined-literals +) +set(BENCHMARK_TEST_LIBCXX_LINK_FLAGS + -nodefaultlibs + -L${BENCHMARK_LIBCXX_INSTALL}/lib/ +) +set(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS + ${BENCHMARK_NATIVE_TARGET_FLAGS} + ${BENCHMARK_TEST_COMPILE_FLAGS} +) +set(BENCHMARK_TEST_NATIVE_LINK_FLAGS + ${BENCHMARK_NATIVE_TARGET_FLAGS} + -L${BENCHMARK_NATIVE_INSTALL}/lib +) +split_list(BENCHMARK_TEST_COMPILE_FLAGS) +split_list(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS) +split_list(BENCHMARK_TEST_LIBCXX_LINK_FLAGS) +split_list(BENCHMARK_TEST_NATIVE_COMPILE_FLAGS) +split_list(BENCHMARK_TEST_NATIVE_LINK_FLAGS) +macro(add_benchmark_test name source_file) + set(libcxx_target ${name}_libcxx) + add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file}) + add_dependencies(${libcxx_target} cxx google-benchmark-libcxx) + add_dependencies(cxx-benchmarks ${libcxx_target}) + if (LIBCXX_ENABLE_SHARED) + target_link_libraries(${libcxx_target} cxx_shared) + else() + target_link_libraries(${libcxx_target} cxx_static) + endif() + if (TARGET cxx_experimental) + target_link_libraries(${libcxx_target} cxx_experimental) + endif() + target_link_libraries(${libcxx_target} -lbenchmark) + set_target_properties(${libcxx_target} + PROPERTIES + OUTPUT_NAME "${name}.libcxx.out" + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + COMPILE_FLAGS "${BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${BENCHMARK_TEST_LIBCXX_LINK_FLAGS}") + if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + set(native_target ${name}_native) + add_executable(${native_target} EXCLUDE_FROM_ALL ${source_file}) + add_dependencies(${native_target} google-benchmark-native + google-benchmark-libcxx) + target_link_libraries(${native_target} -lbenchmark) + if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++") + target_link_libraries(${native_target} -lstdc++fs) + elseif (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++") + target_link_libraries(${native_target} -lc++experimental) + endif() + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${native_target} -pthread) + endif() + add_dependencies(cxx-benchmarks ${native_target}) + set_target_properties(${native_target} + PROPERTIES + OUTPUT_NAME "${name}.native.out" + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + INCLUDE_DIRECTORIES "" + COMPILE_FLAGS "${BENCHMARK_TEST_NATIVE_COMPILE_FLAGS}" + LINK_FLAGS "${BENCHMARK_TEST_NATIVE_LINK_FLAGS}") + endif() +endmacro() + + +#============================================================================== +# Register Benchmark tests +#============================================================================== +file(GLOB BENCHMARK_TESTS "*.bench.cpp") +foreach(test_path ${BENCHMARK_TESTS}) + get_filename_component(test_file "${test_path}" NAME) + string(REPLACE ".bench.cpp" "" test_name "${test_file}") + if (NOT DEFINED ${test_name}_REPORTED) + message(STATUS "Adding Benchmark: ${test_file}") + # Only report the adding of the benchmark once. + set(${test_name}_REPORTED ON CACHE INTERNAL "") + endif() + add_benchmark_test(${test_name} ${test_file}) +endforeach() diff --git a/lib/libcxx/benchmarks/ContainerBenchmarks.hpp b/lib/libcxx/benchmarks/ContainerBenchmarks.hpp new file mode 100644 index 00000000000..dc268e7ebca --- /dev/null +++ b/lib/libcxx/benchmarks/ContainerBenchmarks.hpp @@ -0,0 +1,113 @@ +#ifndef BENCHMARK_CONTAINER_BENCHMARKS_HPP +#define BENCHMARK_CONTAINER_BENCHMARKS_HPP + +#include + +#include "benchmark/benchmark_api.h" + +namespace ContainerBenchmarks { + + +template +void BM_ConstructIterIter(benchmark::State& st, Container, GenInputs gen) { + auto in = gen(st.range(0)); + const auto begin = in.begin(); + const auto end = in.end(); + benchmark::DoNotOptimize(&in); + while (st.KeepRunning()) { + Container c(begin, end); + benchmark::DoNotOptimize(c.data()); + } +} + +template +void BM_InsertValue(benchmark::State& st, Container c, GenInputs gen) { + auto in = gen(st.range(0)); + const auto end = in.end(); + while (st.KeepRunning()) { + c.clear(); + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.insert(*it).first)); + } + benchmark::ClobberMemory(); + } +} + +template +void BM_InsertValueRehash(benchmark::State& st, Container c, GenInputs gen) { + auto in = gen(st.range(0)); + const auto end = in.end(); + while (st.KeepRunning()) { + c.clear(); + c.rehash(16); + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.insert(*it).first)); + } + benchmark::ClobberMemory(); + } +} + + +template +void BM_InsertDuplicate(benchmark::State& st, Container c, GenInputs gen) { + auto in = gen(st.range(0)); + const auto end = in.end(); + c.insert(in.begin(), in.end()); + benchmark::DoNotOptimize(&c); + benchmark::DoNotOptimize(&in); + while (st.KeepRunning()) { + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.insert(*it).first)); + } + benchmark::ClobberMemory(); + } +} + + +template +void BM_EmplaceDuplicate(benchmark::State& st, Container c, GenInputs gen) { + auto in = gen(st.range(0)); + const auto end = in.end(); + c.insert(in.begin(), in.end()); + benchmark::DoNotOptimize(&c); + benchmark::DoNotOptimize(&in); + while (st.KeepRunning()) { + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.emplace(*it).first)); + } + benchmark::ClobberMemory(); + } +} + +template +static void BM_Find(benchmark::State& st, Container c, GenInputs gen) { + auto in = gen(st.range(0)); + c.insert(in.begin(), in.end()); + benchmark::DoNotOptimize(&(*c.begin())); + const auto end = in.data() + in.size(); + while (st.KeepRunning()) { + for (auto it = in.data(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.find(*it))); + } + benchmark::ClobberMemory(); + } +} + +template +static void BM_FindRehash(benchmark::State& st, Container c, GenInputs gen) { + c.rehash(8); + auto in = gen(st.range(0)); + c.insert(in.begin(), in.end()); + benchmark::DoNotOptimize(&(*c.begin())); + const auto end = in.data() + in.size(); + while (st.KeepRunning()) { + for (auto it = in.data(); it != end; ++it) { + benchmark::DoNotOptimize(&(*c.find(*it))); + } + benchmark::ClobberMemory(); + } +} + +} // end namespace ContainerBenchmarks + +#endif // BENCHMARK_CONTAINER_BENCHMARKS_HPP diff --git a/lib/libcxx/benchmarks/GenerateInput.hpp b/lib/libcxx/benchmarks/GenerateInput.hpp new file mode 100644 index 00000000000..9d5adac4af4 --- /dev/null +++ b/lib/libcxx/benchmarks/GenerateInput.hpp @@ -0,0 +1,142 @@ +#ifndef BENCHMARK_GENERATE_INPUT_HPP +#define BENCHMARK_GENERATE_INPUT_HPP + +#include +#include +#include +#include +#include +#include + +static const char Letters[] = { + '0','1','2','3','4', + '5','6','7','8','9', + 'A','B','C','D','E','F', + 'G','H','I','J','K', + 'L','M','N','O','P', + 'Q','R','S','T','U', + 'V','W','X','Y','Z', + 'a','b','c','d','e','f', + 'g','h','i','j','k', + 'l','m','n','o','p', + 'q','r','s','t','u', + 'v','w','x','y','z' +}; +static const std::size_t LettersSize = sizeof(Letters); + +inline std::default_random_engine& getRandomEngine() { + static std::default_random_engine RandEngine(std::random_device{}()); + return RandEngine; +} + +inline char getRandomChar() { + std::uniform_int_distribution<> LettersDist(0, LettersSize-1); + return Letters[LettersDist(getRandomEngine())]; +} + +template +inline IntT getRandomInteger() { + std::uniform_int_distribution dist; + return dist(getRandomEngine()); +} + +inline std::string getRandomString(std::size_t Len) { + std::string str(Len, 0); + std::generate_n(str.begin(), Len, &getRandomChar); + return str; +} + +template +inline std::vector getDuplicateIntegerInputs(size_t N) { + std::vector inputs(N, static_cast(-1)); + return inputs; +} + +template +inline std::vector getSortedIntegerInputs(size_t N) { + std::vector inputs; + for (size_t i=0; i < N; i += 1) + inputs.push_back(i); + return inputs; +} + +template +std::vector getSortedLargeIntegerInputs(size_t N) { + std::vector inputs; + for (size_t i=0; i < N; ++i) { + inputs.push_back(i + N); + } + return inputs; +} + +template +std::vector getSortedTopBitsIntegerInputs(size_t N) { + std::vector inputs = getSortedIntegerInputs(N); + for (auto& E : inputs) E <<= ((sizeof(IntT) / 2) * CHAR_BIT); + return inputs; +} + +template +inline std::vector getReverseSortedIntegerInputs(size_t N) { + std::vector inputs; + std::size_t i = N; + while (i > 0) { + --i; + inputs.push_back(i); + } + return inputs; +} + +template +std::vector getPipeOrganIntegerInputs(size_t N) { + std::vector v; v.reserve(N); + for (size_t i = 0; i < N/2; ++i) v.push_back(i); + for (size_t i = N/2; i < N; ++i) v.push_back(N - i); + return v; +} + + +template +std::vector getRandomIntegerInputs(size_t N) { + std::vector inputs; + for (size_t i=0; i < N; ++i) { + inputs.push_back(getRandomInteger()); + } + return inputs; +} + +inline std::vector getDuplicateStringInputs(size_t N) { + std::vector inputs(N, getRandomString(1024)); + return inputs; +} + +inline std::vector getRandomStringInputs(size_t N) { + std::vector inputs; + for (size_t i=0; i < N; ++i) { + inputs.push_back(getRandomString(1024)); + } + return inputs; +} + +inline std::vector getSortedStringInputs(size_t N) { + std::vector inputs = getRandomStringInputs(N); + std::sort(inputs.begin(), inputs.end()); + return inputs; +} + +inline std::vector getReverseSortedStringInputs(size_t N) { + std::vector inputs = getSortedStringInputs(N); + std::reverse(inputs.begin(), inputs.end()); + return inputs; +} + +inline std::vector getRandomCStringInputs(size_t N) { + static std::vector inputs = getRandomStringInputs(N); + std::vector cinputs; + for (auto const& str : inputs) + cinputs.push_back(str.c_str()); + return cinputs; +} + + +#endif // BENCHMARK_GENERATE_INPUT_HPP diff --git a/lib/libcxx/benchmarks/algorithms.bench.cpp b/lib/libcxx/benchmarks/algorithms.bench.cpp new file mode 100644 index 00000000000..745cc172718 --- /dev/null +++ b/lib/libcxx/benchmarks/algorithms.bench.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "benchmark/benchmark_api.h" +#include "GenerateInput.hpp" + +constexpr std::size_t TestNumInputs = 1024; + +template +void BM_Sort(benchmark::State& st, GenInputs gen) { + using ValueType = typename decltype(gen(0))::value_type; + const auto in = gen(st.range(0)); + std::vector inputs[5]; + auto reset_inputs = [&]() { + for (auto& C : inputs) { + C = in; + benchmark::DoNotOptimize(C.data()); + } + }; + reset_inputs(); + while (st.KeepRunning()) { + for (auto& I : inputs) { + std::sort(I.data(), I.data() + I.size()); + benchmark::DoNotOptimize(I.data()); + } + st.PauseTiming(); + reset_inputs(); + benchmark::ClobberMemory(); + st.ResumeTiming(); + } +} + +BENCHMARK_CAPTURE(BM_Sort, random_uint32, + getRandomIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_uint32, + getSortedIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, sorted_descending_uint32, + getReverseSortedIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, single_element_uint32, + getDuplicateIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, pipe_organ_uint32, + getPipeOrganIntegerInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, random_strings, + getRandomStringInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, sorted_ascending_strings, + getSortedStringInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, sorted_descending_strings, + getReverseSortedStringInputs)->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Sort, single_element_strings, + getDuplicateStringInputs)->Arg(TestNumInputs); + + +BENCHMARK_MAIN() diff --git a/lib/libcxx/benchmarks/filesystem.bench.cpp b/lib/libcxx/benchmarks/filesystem.bench.cpp new file mode 100644 index 00000000000..f7949a163a7 --- /dev/null +++ b/lib/libcxx/benchmarks/filesystem.bench.cpp @@ -0,0 +1,138 @@ +#include + +#include "benchmark/benchmark_api.h" +#include "GenerateInput.hpp" +#include "test_iterators.h" + +namespace fs = std::experimental::filesystem; + +static const size_t TestNumInputs = 1024; + + +template +void BM_PathConstructString(benchmark::State &st, GenInputs gen) { + using namespace fs; + const auto in = gen(st.range(0)); + path PP; + for (auto& Part : in) + PP /= Part; + benchmark::DoNotOptimize(PP.native().data()); + while (st.KeepRunning()) { + const path P(PP.native()); + benchmark::DoNotOptimize(P.native().data()); + } +} +BENCHMARK_CAPTURE(BM_PathConstructString, large_string, + getRandomStringInputs)->Arg(TestNumInputs); + + +template +void BM_PathConstructCStr(benchmark::State &st, GenInputs gen) { + using namespace fs; + const auto in = gen(st.range(0)); + path PP; + for (auto& Part : in) + PP /= Part; + benchmark::DoNotOptimize(PP.native().data()); + while (st.KeepRunning()) { + const path P(PP.native().c_str()); + benchmark::DoNotOptimize(P.native().data()); + } +} +BENCHMARK_CAPTURE(BM_PathConstructCStr, large_string, + getRandomStringInputs)->Arg(TestNumInputs); + + +template