diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..cfa0c289635c59c0d9e0a9941085fece52d7eccc --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +BasedOnStyle: LLVM + +--- +Language: Cpp +Standard: Cpp03 + +AlwaysBreakTemplateDeclarations: true +PointerAlignment: Left + +# Disable formatting options which may break tests. +SortIncludes: false +ReflowComments: false + +# libc++ has some long names so we need more than the 80 column limit imposed by LLVM style, for sensible formatting +ColumnLimit: 120 +--- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4b214ca4b3e63b2a7728a79a4f28e970ffc8bf12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,55 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +#lib/ # We actually have things checked in to lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# MSVC libraries test harness +env.lst +keep.lst + +# Editor by-products +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..06ee1d74a03e60cd9e83c33218ffe0f7a2c7d337 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,957 @@ +# See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how +# to build libcxx with CMake. + +if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxxabi") + message(FATAL_ERROR "libc++ now requires being built in a monorepo layout with libcxxabi available") +endif() + +#=============================================================================== +# Setup Project +#=============================================================================== +cmake_minimum_required(VERSION 3.13.4) + +set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) + +# Add path for custom modules +set(CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" + ${CMAKE_MODULE_PATH} + ) + +set(CMAKE_FOLDER "libc++") + +set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 13.0.0git) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") + set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org") + + # In a standalone build, we don't have llvm to automatically generate the + # llvm-lit script for us. So we need to provide an explicit directory that + # the configurator should write the script into. + set(LIBCXX_STANDALONE_BUILD 1) + set(LLVM_LIT_OUTPUT_DIR "${LIBCXX_BINARY_DIR}/bin") + + # Find the LLVM sources and simulate LLVM CMake options. + include(HandleOutOfTreeLLVM) +endif() + +if (LIBCXX_STANDALONE_BUILD) + find_package(Python3 COMPONENTS Interpreter) + if(NOT Python3_Interpreter_FOUND) + message(WARNING "Python3 not found, using python2 as a fallback") + find_package(Python2 COMPONENTS Interpreter REQUIRED) + if(Python2_VERSION VERSION_LESS 2.7) + message(SEND_ERROR "Python 2.7 or newer is required") + endif() + + # Treat python2 as python3 + add_executable(Python3::Interpreter IMPORTED) + set_target_properties(Python3::Interpreter PROPERTIES + IMPORTED_LOCATION ${Python2_EXECUTABLE}) + set(Python3_EXECUTABLE ${Python2_EXECUTABLE}) + endif() +endif() + +# Require out of source build. +include(MacroEnsureOutOfSourceBuild) +MACRO_ENSURE_OUT_OF_SOURCE_BUILD( + "${PROJECT_NAME} requires an out of source build. Please create a separate + build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." + ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") + message(STATUS "Configuring for clang-cl") + set(LIBCXX_TARGETING_CLANG_CL ON) +endif() + +if (MSVC) + set(LIBCXX_TARGETING_MSVC ON) + message(STATUS "Configuring for MSVC") +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." 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) +set(ENABLE_FILESYSTEM_DEFAULT ON) +if (WIN32 AND NOT MINGW) + # Filesystem is buildable for windows, but it requires __int128 helper + # functions, that currently are provided by libgcc or compiler_rt builtins. + # These are available in MinGW environments, but not currently in MSVC + # environments. + set(ENABLE_FILESYSTEM_DEFAULT OFF) +endif() +option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library" + ${ENABLE_FILESYSTEM_DEFAULT}) +option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) +option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF) +option(LIBCXX_ENABLE_DEBUG_MODE_SUPPORT + "Whether to include support for libc++'s debugging mode in the library. + By default, this is turned on. If you turn it off and try to enable the + debug mode when compiling a program against libc++, it will fail to link + since the required support isn't provided in the library." ON) +option(LIBCXX_ENABLE_RANDOM_DEVICE + "Whether to include support for std::random_device in the library. Disabling + this can be useful when building the library for platforms that don't have + a source of randomness, such as some embedded platforms. When this is not + supported, most of will still be available, but std::random_device + will not." ON) +option(LIBCXX_ENABLE_LOCALIZATION + "Whether to include support for localization in the library. Disabling + localization can be useful when porting to platforms that don't support + the C locale API (e.g. embedded). When localization is not supported, + several parts of the library will be disabled: , , + will be completely unusable, and other parts may be only partly available." ON) +option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS + "Whether to turn on vendor availability annotations on declarations that depend + on definitions in a shared library. By default, we assume that we're not building + libc++ for any specific vendor, and we disable those annotations. Vendors wishing + to provide compile-time errors when using features unavailable on some version of + the shared library they shipped should turn this on and see `include/__availability` + for more details." OFF) +set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/legacy.cfg.in" CACHE STRING + "The Lit testing configuration to use when running the tests.") +set(LIBCXX_TEST_PARAMS "" CACHE STRING + "A list of parameters to run the Lit test suite with.") + +# Benchmark options ----------------------------------------------------------- +option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON) + +set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01) +set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING + "Arguments to pass when running the benchmarks using check-cxx-benchmarks") + +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) +cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY + "Install the static libc++ library." ON + "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) +cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY + "Install the shared libc++ library." ON + "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" 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++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1.") +set(LIBCXX_ABI_NAMESPACE "" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") +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_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING + "Override the implementation to use for comparing typeinfos. By default, this + is detected automatically by the library, but this option allows overriding + which implementation is used unconditionally. + + See the documentation in for details on what each + value means.") +set(TYPEINFO_COMPARISON_VALUES "default;1;2;3") +if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES)) + message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for + LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION") +endif() + +option(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT "Enable per TU ABI insulation by default. To be used by vendors." OFF) +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) +set(LIBCXX_LIBCPPABI_VERSION "2" CACHE STRING "Version of libc++abi's ABI to re-export from libc++ when re-exporting is enabled. + Note that this is not related to the version of libc++'s ABI itself!") + +# ABI Library options --------------------------------------------------------- +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 (LIBCXX_CXX_ABI STREQUAL "default") + if (LIBCXX_TARGETING_MSVC) + # FIXME: Figure out how to configure the ABI library on Windows. + set(LIBCXX_CXX_ABI_LIBNAME "vcruntime") + elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(LIBCXX_CXX_ABI_LIBNAME "libcxxrt") + elseif (NOT LIBCXX_STANDALONE_BUILD OR HAVE_LIBCXXABI) + set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") + else() + set(LIBCXX_CXX_ABI_LIBNAME "default") + endif() +else() + set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") +endif() + +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY + "Use a static copy of the ABI library when linking libc++. + This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF) + +cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY + "Statically link the ABI library to static library" ON + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_STATIC" OFF) + +cmake_dependent_option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY + "Statically link the ABI library to shared library" ON + "LIBCXX_ENABLE_STATIC_ABI_LIBRARY;LIBCXX_ENABLE_SHARED" 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' +# 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_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY + AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" + AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "default" + AND Python3_EXECUTABLE + AND LIBCXX_ENABLE_SHARED) + set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) +endif() + +option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT + "Use and install a linker script for the given ABI library" + ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) + +option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS + "Build libc++ with definitions for operator new/delete. These are normally + defined in libc++abi, but this option can be used to define them in libc++ + instead. If you define them in libc++, make sure they are NOT defined in + libc++abi. Doing otherwise is an ODR violation." OFF) +# 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) + +# Target options -------------------------------------------------------------- +option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) +set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.") +set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") +set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") + +# Feature options ------------------------------------------------------------- +option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) +option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) +option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) +option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) +option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) +option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) +option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) +option(LIBCXX_ENABLE_MONOTONIC_CLOCK + "Build libc++ with support for a 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_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread 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 +# about #include_next which is used everywhere. +option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) +option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) +option(LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS "Disable #warnings about conflicting macros." OFF) + +option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) +set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING + "The Profile-rt library used to build with code coverage") + +set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) +if (XCODE OR MSVC_IDE) + set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) +endif() +option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" + ${LIBCXX_CONFIGURE_IDE_DEFAULT}) + +option(LIBCXX_HERMETIC_STATIC_LIBRARY + "Do not export any symbols from the static library." OFF) + +#=============================================================================== +# Check option configurations +#=============================================================================== + +# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when +# LIBCXX_ENABLE_THREADS is on. +if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) + message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" + " when LIBCXX_ENABLE_THREADS is also set to OFF.") +endif() + +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() + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API 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() + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" + "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" + "set to ON at the same time.") + endif() +endif() + +if (LIBCXX_HAS_PTHREAD_API) + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" + "and LIBCXX_HAS_WIN32_THREAD_API cannot be both" + "set to ON at the same time.") + endif() +endif() + +# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE +# is ON. +if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) + message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") +endif() + +# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) +# and check that we can build with 32 bits if requested. +if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) + if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM + message(STATUS "Building 32 bits executables and libraries.") + endif() +elseif(LIBCXX_BUILD_32_BITS) + message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") +endif() + +# Warn users that LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option. +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") + if (LIBCXX_ENABLE_STATIC AND NOT Python3_EXECUTABLE) + message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY requires python but it was not found.") + endif() +endif() + +if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + if (APPLE) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") + endif() + if (NOT LIBCXX_ENABLE_SHARED) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") + endif() +endif() + +if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + message(FATAL_ERROR "Conflicting options given. + LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with + LIBCXX_ENABLE_ABI_LINKER_SCRIPT") +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 +#=============================================================================== + +# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR +# instead of hard-coding include/c++/v1. +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") + set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + endif() +elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") + set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}") +else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") + set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}") +endif() + +file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") + +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. +set(LIBCXX_COMPILE_FLAGS "") +set(LIBCXX_LINK_FLAGS "") +set(LIBCXX_LIBRARIES "") + +# Include macros for adding and removing libc++ flags. +include(HandleLibcxxFlags) + +# Target flags ================================================================ +# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that +# '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") + +if(LIBCXX_TARGET_TRIPLE) + add_target_flags("--target=${LIBCXX_TARGET_TRIPLE}") +elseif(CMAKE_CXX_COMPILER_TARGET) + set(LIBCXX_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}") +endif() +if(LIBCXX_SYSROOT) + add_target_flags("--sysroot=${LIBCXX_SYSROOT}") +elseif(CMAKE_SYSROOT) + set(LIBCXX_SYSROOT "${CMAKE_SYSROOT}") +endif() +if(LIBCXX_GCC_TOOLCHAIN) + add_target_flags("--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") +elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN) + set(LIBCXX_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") +endif() + +if(LIBCXX_TARGET_TRIPLE) + set(TARGET_TRIPLE "${LIBCXX_TARGET_TRIPLE}") +endif() + +# Configure compiler. +include(config-ix) + +# Configure coverage options. +if (LIBCXX_GENERATE_COVERAGE) + include(CodeCoverage) + set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) +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 +#=============================================================================== + +include(HandleLibCXXABI) # Setup the ABI library flags + +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=libc++ --stdlib=libstdc++ -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 respectively. +remove_flags(-Wno-pedantic -pedantic-errors -pedantic) + +# Required flags ============================================================== +function(cxx_add_basic_build_flags target) + + # Require C++20 for all targets. C++17 is needed to use aligned allocation + # in the dylib. C++20 is needed to use char8_t. + set_target_properties(${target} PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED NO + CXX_EXTENSIONS NO) + + # When building the dylib, don't warn for unavailable aligned allocation + # functions based on the deployment target -- they are always available + # because they are provided by the dylib itself with the excepton of z/OS. + if (ZOS) + target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation) + else() + target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation) + endif() + + # On all systems the system c++ standard library headers need to be excluded. + # MSVC only has -X, which disables all default includes; including the crt. + # Thus, we do nothing and hope we don't accidentally include any of the C++ + # headers + target_add_compile_flags_if_supported(${target} PUBLIC -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. + target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden) + + # Our visibility annotations are not quite right for non-Clang compilers, + # so we end up not exporting all the symbols we should. In the future, we + # can improve the situation by providing an explicit list of exported + # symbols on all compilers. + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden) + endif() + + if (LIBCXX_CONFIGURE_IDE) + # This simply allows IDE to process + target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts) + endif() + + # Let the library headers know they are currently being used to build the + # library. + target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY) + + if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) + endif() + + if (LIBCXX_HAS_COMMENT_LIB_PRAGMA) + if (LIBCXX_HAS_PTHREAD_LIB) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB) + endif() + if (LIBCXX_HAS_RT_LIB) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB) + endif() + endif() +endfunction() + +# Warning flags =============================================================== +function(cxx_add_warning_flags target) + target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) + if (MSVC) + # -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl, + # -Wall is equivalent to -Weverything in GCC style compiler drivers.) + target_add_compile_flags_if_supported(${target} PRIVATE -W4) + else() + target_add_compile_flags_if_supported(${target} PRIVATE -Wall) + endif() + target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings + -Wno-unused-parameter -Wno-long-long + -Werror=return-type -Wextra-semi -Wundef) + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + target_add_compile_flags_if_supported(${target} PRIVATE + -Wno-user-defined-literals + -Wno-covered-switch-default + -Wno-suggest-override + -Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs + ) + if (LIBCXX_TARGETING_CLANG_CL) + target_add_compile_flags_if_supported(${target} PRIVATE + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-c++11-compat + -Wno-undef + -Wno-reserved-id-macro + -Wno-gnu-include-next + -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings + -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences. + -Wno-deprecated-dynamic-exception-spec # For auto_ptr + -Wno-sign-conversion + -Wno-old-style-cast + -Wno-deprecated # FIXME: Remove this and fix all occurrences. + -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang? + -Wno-double-promotion # FIXME: remove me + ) + endif() + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + target_add_compile_flags_if_supported(${target} PRIVATE + -Wno-literal-suffix + -Wno-c++14-compat + -Wno-noexcept-type + -Wno-suggest-override) + endif() + if (LIBCXX_ENABLE_WERROR) + target_add_compile_flags_if_supported(${target} PRIVATE -Werror) + target_add_compile_flags_if_supported(${target} PRIVATE -WX) + else() + # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is + # added elsewhere. + target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error) + endif() + if (LIBCXX_ENABLE_PEDANTIC) + target_add_compile_flags_if_supported(${target} PRIVATE -pedantic) + endif() + if (LIBCXX_DISABLE_MACRO_CONFLICT_WARNINGS) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS) + endif() +endfunction() + +# Exception flags ============================================================= +function(cxx_add_exception_flags target) + if (LIBCXX_ENABLE_EXCEPTIONS) + # Catches C++ exceptions only and tells the compiler to assume that extern C + # functions never throw a C++ exception. + target_add_compile_flags_if_supported(${target} PUBLIC -EHsc) + else() + target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-) + target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions) + endif() +endfunction() + +# RTTI flags ================================================================== +function(cxx_add_rtti_flags target) + if (NOT LIBCXX_ENABLE_RTTI) + target_add_compile_flags_if_supported(${target} PUBLIC -GR-) + target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) + endif() +endfunction() + +# 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) +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(LIBCXX_TARGETING_MSVC -D_DEBUG) +endif() + +# 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. +function(cxx_add_module_flags target) + if (LLVM_ENABLE_MODULES) + # Ignore that the rest of the modules flags are now unused. + target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument) + target_compile_options(${target} PUBLIC -fno-modules) + endif() +endfunction() + +# Sanitizer flags ============================================================= + +function(get_sanitizer_flags OUT_VAR USE_SANITIZER) + set(SANITIZER_FLAGS) + set(USE_SANITIZER "${USE_SANITIZER}") + # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. + # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. + if (USE_SANITIZER AND NOT MSVC) + append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer") + append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") + + if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND + NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") + endif() + if (USE_SANITIZER STREQUAL "Address") + append_flags(SANITIZER_FLAGS "-fsanitize=address") + elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?") + append_flags(SANITIZER_FLAGS -fsanitize=memory) + if (USE_SANITIZER STREQUAL "MemoryWithOrigins") + append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins") + endif() + elseif (USE_SANITIZER STREQUAL "Undefined") + append_flags(SANITIZER_FLAGS "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") + elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR + USE_SANITIZER STREQUAL "Undefined;Address") + append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") + elseif (USE_SANITIZER STREQUAL "Thread") + append_flags(SANITIZER_FLAGS -fsanitize=thread) + elseif (USE_SANITIZER STREQUAL "DataFlow") + append_flags(SANITIZER_FLAGS -fsanitize=dataflow) + else() + message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") + endif() + elseif(USE_SANITIZER AND MSVC) + message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") + endif() + set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE) +endfunction() + +# 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_STANDALONE_BUILD) + set(LLVM_USE_SANITIZER "" CACHE STRING + "Define the sanitizer used to build the library and tests") +endif() +get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}") +if (LIBCXX_STANDALONE_BUILD AND SANITIZER_FLAGS) + add_flags(${SANITIZER_FLAGS}) +endif() + +# Link system libraries ======================================================= +function(cxx_link_system_libraries target) + +# In order to remove just libc++ from the link step +# we need to use -nostdlib++ whenever it is supported. +# Unfortunately this cannot be used universally because for example g++ supports +# only -nodefaultlibs in which case all libraries will be removed and +# all libraries but c++ have to be added in manually. + if (LIBCXX_SUPPORTS_NOSTDLIBXX_FLAG) + target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++") + else() + target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs") + target_add_compile_flags_if_supported(${target} PRIVATE "/Zl") + target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib") + endif() + + if (LIBCXX_HAS_SYSTEM_LIB) + target_link_libraries(${target} PRIVATE System) + endif() + + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${target} PRIVATE pthread) + endif() + + if (LIBCXX_HAS_C_LIB) + target_link_libraries(${target} PRIVATE c) + endif() + + if (LIBCXX_HAS_M_LIB) + target_link_libraries(${target} PRIVATE m) + endif() + + if (LIBCXX_HAS_RT_LIB) + target_link_libraries(${target} PRIVATE rt) + endif() + + if (LIBCXX_USE_COMPILER_RT) + find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) + if (LIBCXX_BUILTINS_LIBRARY) + target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}") + endif() + elseif (LIBCXX_HAS_GCC_LIB) + target_link_libraries(${target} PRIVATE gcc) + elseif (LIBCXX_HAS_GCC_S_LIB) + target_link_libraries(${target} PRIVATE gcc_s) + endif() + + if (LIBCXX_HAS_ATOMIC_LIB) + target_link_libraries(${target} PRIVATE atomic) + endif() + + if (MINGW) + target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}") + endif() + + if (LIBCXX_TARGETING_MSVC) + if (LIBCXX_DEBUG_BUILD) + set(LIB_SUFFIX "d") + else() + set(LIB_SUFFIX "") + endif() + + target_link_libraries(${target} PRIVATE ucrt${LIB_SUFFIX}) # Universal C runtime + target_link_libraries(${target} PRIVATE vcruntime${LIB_SUFFIX}) # C++ runtime + target_link_libraries(${target} PRIVATE msvcrt${LIB_SUFFIX}) # C runtime startup files + target_link_libraries(${target} PRIVATE msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. + # Required for standards-complaint wide character formatting functions + # (e.g. `printfw`/`scanfw`) + target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers) + endif() + + if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21) + target_link_libraries(${target} PUBLIC android_support) + endif() +endfunction() + +# Windows-related flags ======================================================= +function(cxx_add_windows_flags target) + if(WIN32 AND NOT MINGW) + target_compile_definitions(${target} PRIVATE + # Ignore the -MSC_VER mismatch, as we may build + # with a different compatibility version. + _ALLOW_MSC_VER_MISMATCH + # Don't check the msvcprt iterator debug levels + # as we will define the iterator types; libc++ + # uses a different macro to identify the debug + # level. + _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH + # We are building the c++ runtime, don't pull in + # msvcprt. + _CRTBLD + # Don't warn on the use of "deprecated" + # "insecure" functions which are standards + # specified. + _CRT_SECURE_NO_WARNINGS + # Use the ISO conforming behaviour for conversion + # in printf, scanf. + _CRT_STDIO_ISO_WIDE_SPECIFIERS) + endif() +endfunction() + +# Configuration file flags ===================================================== +if (NOT LIBCXX_ABI_VERSION EQUAL 1) + config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) +endif() +if (NOT LIBCXX_ABI_NAMESPACE STREQUAL "") + if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") + message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier.") + endif() + if (LIBCXX_ABI_NAMESPACE MATCHES "__[0-9]+$") + message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE '${LIBCXX_ABI_NAMESPACE}' is reserved for use by libc++.") + endif() + config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) +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(LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT) +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) +config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) +config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) +config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) +config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) +if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default") + config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION) +endif() +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_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32) +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) +config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS) +config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY) +config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE) +config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION) +config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) + +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() + +if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + # If linking libcxxabi statically into libcxx, skip the dllimport attributes + # on symbols we refer to from libcxxabi. + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) +endif() + +# Setup all common build flags ================================================= +function(cxx_add_common_build_flags target) + cxx_add_basic_build_flags(${target}) + cxx_add_warning_flags(${target}) + cxx_add_windows_flags(${target}) + cxx_add_exception_flags(${target}) + cxx_add_rtti_flags(${target}) + cxx_add_module_flags(${target}) + cxx_link_system_libraries(${target}) +endfunction() + +#=============================================================================== +# Setup Source Code And Tests +#=============================================================================== +add_subdirectory(include) +add_subdirectory(src) + +set(LIBCXX_TEST_DEPS "") + +if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) + list(APPEND LIBCXX_TEST_DEPS cxx_experimental) +endif() + +if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) + list(APPEND LIBCXX_TEST_DEPS cxx_external_threads) +endif() + +if (LIBCXX_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + +if (LIBCXX_INCLUDE_TESTS) + add_subdirectory(test) + add_subdirectory(lib/abi) + if (LIBCXX_STANDALONE_BUILD) + 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() +endif() + +if (LIBCXX_INCLUDE_DOCS) + add_subdirectory(docs) +endif() diff --git a/CREDITS.TXT b/CREDITS.TXT new file mode 100644 index 0000000000000000000000000000000000000000..49f095d296459c365831ecd35139fd20defb9c54 --- /dev/null +++ b/CREDITS.TXT @@ -0,0 +1,159 @@ +This file is a partial list of people who have contributed to the LLVM/libc++ +project. If you have contributed a patch or made some other contribution to +LLVM/libc++, please submit a patch to this file to add yourself, and it will be +done! + +The list is sorted by surname and formatted to allow easy grepping and +beautification by scripts. The fields are: name (N), email (E), web-address +(W), PGP key ID and fingerprint (P), description (D), and snail-mail address +(S). + +N: Saleem Abdulrasool +E: compnerd@compnerd.org +D: Minor patches and Linux fixes. + +N: Dan Albert +E: danalbert@google.com +D: Android support and test runner improvements. + +N: Dimitry Andric +E: dimitry@andric.com +D: Visibility fixes, minor FreeBSD portability patches. + +N: Holger Arnold +E: holgerar@gmail.com +D: Minor fix. + +N: Ruben Van Boxem +E: vanboxem dot ruben at gmail dot com +D: Initial Windows patches. + +N: David Chisnall +E: theraven at theravensnest dot org +D: FreeBSD and Solaris ports, libcxxrt support, some atomics work. + +N: Marshall Clow +E: mclow.lists@gmail.com +E: marshall@idio.com +D: C++14 support, patches and bug fixes. + +N: Jonathan B Coe +E: jbcoe@me.com +D: Implementation of propagate_const. + +N: Christopher Di Bella +E: cjdb@google.com +E: cjdb.ns@gmail.com +D: Library concepts. + +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. + +N: Bill Fisher +E: william.w.fisher@gmail.com +D: Regex bug fixes. + +N: Matthew Dempsky +E: matthew@dempsky.org +D: Minor patches and bug fixes. + +N: Google Inc. +D: Copyright owner and contributor of the CityHash algorithm + +N: Howard Hinnant +E: hhinnant@apple.com +D: Architect and primary author of libc++ + +N: Sergej Jaskiewicz +E: jaskiewiczs@icloud.com +D: Minor improvements in the testing infrastructure + +N: Hyeon-bin Jeong +E: tuhertz@gmail.com +D: Minor patches and bug fixes. + +N: Argyrios Kyrtzidis +E: kyrtzidis@apple.com +D: Bug fixes. + +N: Bruce Mitchener, Jr. +E: bruce.mitchener@gmail.com +D: Emscripten-related changes. + +N: Michel Morin +E: mimomorin@gmail.com +D: Minor patches to is_convertible. + +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. + +N: Bjorn Reese +E: breese@users.sourceforge.net +D: Initial regex prototype + +N: Nico Rieck +E: nico.rieck@gmail.com +D: Windows fixes + +N: Jon Roelofs +E: jroelofS@jroelofs.com +D: Remote testing, Newlib port, baremetal/single-threaded support. + +N: Jonathan Sauer +D: Minor patches, mostly related to constexpr + +N: Craig Silverstein +E: csilvers@google.com +D: Implemented Cityhash as the string hash function on 64-bit machines + +N: Richard Smith +D: Minor patches. + +N: Joerg Sonnenberger +E: joerg@NetBSD.org +D: NetBSD port. + +N: Stephan Tolksdorf +E: st@quanttec.com +D: Minor fix + +N: Michael van der Westhuizen +E: r1mikey at gmail dot com + +N: Larisse Voufo +D: Minor patches. + +N: Klaas de Vries +E: klaas at klaasgaaf dot nl +D: Minor bug fix. + +N: Zhang Xiongpang +E: zhangxiongpang@gmail.com +D: Minor patches and bug fixes. + +N: Xing Xue +E: xingxue@ca.ibm.com +D: AIX port + +N: Zhihao Yuan +E: lichray@gmail.com +D: Standard compatibility fixes. + +N: Jeffrey Yasskin +E: jyasskin@gmail.com +E: jyasskin@google.com +D: Linux fixes. diff --git a/LICENSE.TXT b/LICENSE.TXT new file mode 100644 index 0000000000000000000000000000000000000000..e159d283443f92ac78b964d2bccebe8f95d5d445 --- /dev/null +++ b/LICENSE.TXT @@ -0,0 +1,311 @@ +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): +============================================================================== + +The libc++ library is dual licensed under both the University of Illinois +"BSD-Like" license and the MIT license. As a user of this code you may choose +to use it under either license. As a contributor, you agree to allow your code +to be used under both. + +Full text of the relevant licenses is included below. + +============================================================================== + +University of Illinois/NCSA +Open Source License + +Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT + +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. + +============================================================================== + +Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..545c4d685d496dac492b3329b45e0587bb62f2f1 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.OpenSource b/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..10738d9f3ee13a71a2b5775e9930e133f94b4135 --- /dev/null +++ b/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "llvm-project", + "License": "Apache License v2.0 with LLVM Exceptions", + "License File": "LICENSE.TXT", + "Version Number": "79a2e924d96e2fc1e4b937c42efd08898fa472d7", + "Owner": "liujixin@huawei.com", + "Upstream URL": "https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git@79a2e924d96e2fc1e4b937c42efd08898fa472d7", + "Description": "Chromium 编译库" + } +] \ No newline at end of file diff --git a/TODO.TXT b/TODO.TXT new file mode 100644 index 0000000000000000000000000000000000000000..cf489d29149d1e76e6489eedd6c793a2177b247a --- /dev/null +++ b/TODO.TXT @@ -0,0 +1,75 @@ +This is meant to be a general place to list things that should be done "someday" + +CXX Runtime Library Tasks +========================= +* Look into mirroring libsupc++'s typeinfo vtable layout when libsupc++/libstdc++ + is used as the runtime library. +* Investigate and document interoperability between libc++ and libstdc++ on + linux. Do this for every supported c++ runtime library. + +Atomic Related Tasks +==================== +* future should use for synchronization. + +Test Suite Tasks +================ +* 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 +* Put a static_assert in std::allocator to deny const/volatile types (LWG 2447) diff --git a/appveyor-reqs-install.cmd b/appveyor-reqs-install.cmd new file mode 100644 index 0000000000000000000000000000000000000000..e3bd018dd3742eb5eb613985bab70bed9be866e0 --- /dev/null +++ b/appveyor-reqs-install.cmd @@ -0,0 +1,53 @@ +@echo on + +if NOT EXIST C:\projects\deps ( + mkdir C:\projects\deps +) +cd C:\projects\deps + +::########################################################################### +:: Setup Compiler +::########################################################################### +if NOT EXIST llvm-installer.exe ( + appveyor DownloadFile https://prereleases.llvm.org/win-snapshots/LLVM-9.0.0-r357435-win32.exe -FileName llvm-installer.exe +) +if "%CLANG_VERSION%"=="ToT" ( + START /WAIT llvm-installer.exe /S /D=C:\"Program Files\LLVM" +) +if DEFINED CLANG_VERSION @set PATH="C:\Program Files\LLVM\bin";%PATH% +if DEFINED CLANG_VERSION clang-cl -v + +if DEFINED MINGW_PATH rename "C:\Program Files\Git\usr\bin\sh.exe" "sh-ignored.exe" +if DEFINED MINGW_PATH @set "PATH=%PATH:C:\Program Files (x86)\Git\bin=%" +if DEFINED MINGW_PATH @set "PATH=%PATH%;%MINGW_PATH%" +if DEFINED MINGW_PATH g++ -v + +::########################################################################### +:: Install a recent CMake +::########################################################################### +if NOT EXIST cmake ( + appveyor DownloadFile https://cmake.org/files/v3.7/cmake-3.7.2-win64-x64.zip -FileName cmake.zip + 7z x cmake.zip -oC:\projects\deps > nul + move C:\projects\deps\cmake-* C:\projects\deps\cmake + rm cmake.zip +) +@set PATH=C:\projects\deps\cmake\bin;%PATH% +cmake --version + +::########################################################################### +:: Install Ninja +::########################################################################### +if NOT EXIST ninja ( + appveyor DownloadFile https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip -FileName ninja.zip + 7z x ninja.zip -oC:\projects\deps\ninja > nul + rm ninja.zip +) +@set PATH=C:\projects\deps\ninja;%PATH% +ninja --version + +::########################################################################### +:: Setup the cached copy of LLVM +::########################################################################### +git clone --depth=1 http://llvm.org/git/llvm.git + +@echo off diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000000000000000000000000000000000..ae7c7ad7cf67272173c2c082584f4c8703ba4038 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,71 @@ +version: '{build}' + +shallow_clone: true + +build: + verbosity: detailed + +configuration: + - Debug + +environment: + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_OPTIONS: -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe + CLANG_VERSION: ToT + MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat + MSVC_SETUP_ARG: x86 + GENERATOR: Ninja + MAKE_PROGRAM: ninja + APPVEYOR_SAVE_CACHE_ON_ERROR: true +# TODO: Maybe re-enable this configuration? Do we want to support MSVC 2015's runtime? +# - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 +# MINGW_PATH: C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin +# GENERATOR: MinGW Makefiles +# MAKE_PROGRAM: mingw32-make +# APPVEYOR_SAVE_CACHE_ON_ERROR: true + +install: + ############################################################################ + # All external dependencies are installed in C:\projects\deps + ############################################################################ + - call "%APPVEYOR_BUILD_FOLDER%\\appveyor-reqs-install.cmd" + +before_build: + - if DEFINED MSVC_SETUP_PATH call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG% + - cd %APPVEYOR_BUILD_FOLDER% + +build_script: + - md C:\projects\build-libcxx + - cd C:\projects\build-libcxx + - echo %configuration% + + ############################################################################# + # Configuration Step + ############################################################################# + - cmake -G "%GENERATOR%" %CMAKE_OPTIONS% + "-DCMAKE_BUILD_TYPE=%configuration%" + "-DLLVM_PATH=C:\projects\deps\llvm" -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF + -DLLVM_LIT_ARGS="-sv --show-xfail --show-unsupported" + %APPVEYOR_BUILD_FOLDER% + + ############################################################################# + # Build Step + ############################################################################# + - "%MAKE_PROGRAM%" + +test_script: + - "%MAKE_PROGRAM% check-cxx" + +on_failure: + - appveyor PushArtifact CMakeFiles/CMakeOutput.log + - appveyor PushArtifact CMakeFiles/CMakeError.log + +artifacts: + - path: '_build/CMakeFiles/*.log' + name: logs + +cache: + - C:\projects\deps\ninja + - C:\projects\deps\cmake + - C:\projects\deps\llvm-installer.exe diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4b8247da63b102338e96a2f2df110290d820caf --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,218 @@ +include(ExternalProject) +include(CheckCXXCompilerFlag) + +#============================================================================== +# Build Google Benchmark for libc++ +#============================================================================== + +set(CMAKE_FOLDER "${CMAKE_FOLDER}/Benchmarks") + +set(BENCHMARK_LIBCXX_COMPILE_FLAGS + -Wno-unused-command-line-argument + -nostdinc++ + -isystem "${LIBCXX_GENERATED_INCLUDE_DIR}" + -L${LIBCXX_LIBRARY_DIR} + -Wl,-rpath,${LIBCXX_LIBRARY_DIR} + ${SANITIZER_FLAGS} + ) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS + -isystem "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}") +endif() +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 cxx-headers + 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 + -O2 + -fsized-deallocation + -I${BENCHMARK_LIBCXX_INSTALL}/include + -I${LIBCXX_SOURCE_DIR}/test/support +) +set(BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS + ${BENCHMARK_TEST_COMPILE_FLAGS} + ${SANITIZER_FLAGS} + -Wno-user-defined-literals + -Wno-suggest-override +) + +set(BENCHMARK_TEST_LIBCXX_LINK_FLAGS + -nodefaultlibs + -L${BENCHMARK_LIBCXX_INSTALL}/lib/ + ${SANITIZER_FLAGS} +) +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) + +if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++") + find_library(LIBSTDCXX_FILESYSTEM_TEST stdc++fs + PATHS ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN} + PATH_SUFFIXES lib lib64 + DOC "The libstdc++ filesystem library used by the benchmarks" + ) + if (NOT "${LIBSTDCXX_FILESYSTEM_TEST}" STREQUAL "LIBSTDCXX_FILESYSTEM_TEST-NOTFOUND") + set(LIBSTDCXX_FILESYSTEM_LIB "stdc++fs") + endif() +endif() + +set(libcxx_benchmark_targets) + +function(add_benchmark_test name source_file) + set(libcxx_target ${name}_libcxx) + list(APPEND libcxx_benchmark_targets ${libcxx_target}) + 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} PRIVATE cxx_shared) + else() + target_link_libraries(${libcxx_target} PRIVATE cxx_static) + endif() + if (TARGET cxx_experimental) + target_link_libraries(${libcxx_target} PRIVATE cxx_experimental) + endif() + target_link_libraries(${libcxx_target} PRIVATE -lbenchmark) + if (LLVM_USE_SANITIZER) + target_link_libraries(${libcxx_target} PRIVATE -ldl) + endif() + 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}" + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO) + cxx_link_system_libraries(${libcxx_target}) + if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++" AND NOT DEFINED LIBSTDCXX_FILESYSTEM_LIB + AND "${name}" STREQUAL "filesystem") + return() + endif() + 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} PRIVATE -lbenchmark) + if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++") + target_link_libraries(${native_target} PRIVATE ${LIBSTDCXX_FILESYSTEM_LIB}) + elseif (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++") + target_link_libraries(${native_target} PRIVATE -lc++fs -lc++experimental) + endif() + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${native_target} PRIVATE -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}" + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO) + endif() +endfunction() + + +#============================================================================== +# 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() + +if (LIBCXX_INCLUDE_TESTS) + include(AddLLVM) + + if (NOT DEFINED LIBCXX_TEST_DEPS) + message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined") + endif() + + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py) + + set(BENCHMARK_LIT_ARGS "--show-all --show-xfail --show-unsupported ${LIT_ARGS_DEFAULT}") + + add_lit_target(check-cxx-benchmarks + "Running libcxx benchmarks tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS cxx-benchmarks ${LIBCXX_TEST_DEPS} + ARGS ${BENCHMARK_LIT_ARGS}) +endif() diff --git a/benchmarks/CartesianBenchmarks.h b/benchmarks/CartesianBenchmarks.h new file mode 100644 index 0000000000000000000000000000000000000000..2eea156819330575d0f3311e067e5881966f25c5 --- /dev/null +++ b/benchmarks/CartesianBenchmarks.h @@ -0,0 +1,133 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + + +#include +#include +#include +#include + +#include "benchmark/benchmark.h" +#include "test_macros.h" + +namespace internal { + +template +struct EnumValue : std::integral_constant(I)> { + static std::string name() { return std::string("_") + D::Names[I]; } +}; + +template +constexpr auto makeEnumValueTuple(std::index_sequence) { + return std::make_tuple(EnumValue{}...); +} + +template +static auto skip(const B& Bench, int) -> decltype(Bench.skip()) { + return Bench.skip(); +} +template +static auto skip(const B& Bench, char) { + return false; +} + +template +void makeBenchmarkFromValuesImpl(const Args& A, std::index_sequence) { + for (auto& V : A) { + B Bench{std::get(V)...}; + if (!internal::skip(Bench, 0)) { + benchmark::RegisterBenchmark(Bench.name().c_str(), + [=](benchmark::State& S) { Bench.run(S); }); + } + } +} + +template +void makeBenchmarkFromValues(const std::vector >& A) { + makeBenchmarkFromValuesImpl(A, std::index_sequence_for()); +} + +template