diff options
Diffstat (limited to 'contrib/libc++/src')
55 files changed, 1096 insertions, 672 deletions
diff --git a/contrib/libc++/src/CMakeLists.txt b/contrib/libc++/src/CMakeLists.txt new file mode 100644 index 000000000000..31cd24333a5e --- /dev/null +++ b/contrib/libc++/src/CMakeLists.txt @@ -0,0 +1,495 @@ +set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE) + +# Get sources +set(LIBCXX_SOURCES + algorithm.cpp + any.cpp + bind.cpp + charconv.cpp + chrono.cpp + condition_variable.cpp + condition_variable_destructor.cpp + debug.cpp + exception.cpp + functional.cpp + future.cpp + hash.cpp + include/apple_availability.h + include/atomic_support.h + include/config_elast.h + include/refstring.h + ios.cpp + iostream.cpp + locale.cpp + memory.cpp + mutex.cpp + mutex_destructor.cpp + new.cpp + optional.cpp + random.cpp + regex.cpp + shared_mutex.cpp + stdexcept.cpp + string.cpp + strstream.cpp + support/runtime/exception_fallback.ipp + support/runtime/exception_glibcxx.ipp + support/runtime/exception_libcxxabi.ipp + support/runtime/exception_libcxxrt.ipp + support/runtime/exception_msvc.ipp + support/runtime/exception_pointer_cxxabi.ipp + support/runtime/exception_pointer_glibcxx.ipp + support/runtime/exception_pointer_msvc.ipp + support/runtime/exception_pointer_unimplemented.ipp + support/runtime/new_handler_fallback.ipp + support/runtime/stdexcept_default.ipp + support/runtime/stdexcept_vcruntime.ipp + system_error.cpp + thread.cpp + typeinfo.cpp + utility.cpp + valarray.cpp + variant.cpp + vector.cpp + ) + +if(WIN32) + list(APPEND LIBCXX_SOURCES + support/win32/locale_win32.cpp + support/win32/support.cpp + support/win32/thread_win32.cpp + ) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") + list(APPEND LIBCXX_SOURCES + support/solaris/mbsnrtowcs.inc + support/solaris/wcsnrtombs.inc + support/solaris/xlocale.cpp + ) +endif() + +if (LIBCXX_ENABLE_FILESYSTEM) + list(APPEND LIBCXX_SOURCES + filesystem/filesystem_common.h + filesystem/operations.cpp + filesystem/directory_iterator.cpp + ) + # Filesystem uses __int128_t, which requires a definition of __muloi4 when + # compiled with UBSAN. This definition is not provided by libgcc_s, but is + # provided by compiler-rt. So we need to disable it to avoid having multiple + # definitions. See filesystem/int128_builtins.cpp. + if (NOT LIBCXX_USE_COMPILER_RT) + list(APPEND LIBCXX_SOURCES + filesystem/int128_builtins.cpp + ) + endif() +endif() + +# Add all the headers to the project for IDEs. +if (LIBCXX_CONFIGURE_IDE) + file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) + if(WIN32) + file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) + list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) + endif() + # Force them all into the headers dir on MSVC, otherwise they end up at + # project scope because they don't have extensions. + if (MSVC_IDE) + source_group("Header Files" FILES ${LIBCXX_HEADERS}) + endif() +endif() + +if(NOT LIBCXX_INSTALL_LIBRARY) + set(exclude_from_all EXCLUDE_FROM_ALL) +endif() + +# If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. +add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH + "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") + + +if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) + find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) +endif() +add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") + +if (APPLE AND LLVM_USE_SANITIZER) + if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR + ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR + ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) + set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") + elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") + set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") + elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") + set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") + else() + message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") + endif() + if (LIBFILE) + find_compiler_rt_dir(LIBDIR) + if (NOT IS_DIRECTORY "${LIBDIR}") + message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") + endif() + set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") + set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) + message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") + add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") + add_link_flags("-Wl,-rpath,${LIBDIR}") + endif() +endif() + +function(cxx_link_system_libraries target) + 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") + + if (LIBCXX_HAS_SYSTEM_LIB) + target_link_libraries(${target} PUBLIC System) + endif() + + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${target} PUBLIC pthread) + endif() + + if (LIBCXX_HAS_C_LIB) + target_link_libraries(${target} PUBLIC c) + endif() + + if (LIBCXX_HAS_M_LIB) + target_link_libraries(${target} PUBLIC m) + endif() + + if (LIBCXX_HAS_RT_LIB) + target_link_libraries(${target} PUBLIC rt) + endif() + + if (LIBCXX_USE_COMPILER_RT) + find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) + if (LIBCXX_BUILTINS_LIBRARY) + target_link_libraries(${target} PUBLIC "${LIBCXX_BUILTINS_LIBRARY}") + endif() + elseif (LIBCXX_HAS_GCC_S_LIB) + target_link_libraries(${target} PUBLIC gcc_s) + endif() + + if (LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB) + target_link_libraries(${target} PUBLIC atomic) + endif() + + if (MINGW) + target_link_libraries(${target} PUBLIC "${MINGW_LIBRARIES}") + endif() + + if (LIBCXX_TARGETING_MSVC) + if (LIBCXX_DEBUG_BUILD) + set(LIB_SUFFIX "d") + else() + set(LIB_SUFFIX "") + endif() + + target_link_libraries(${target} PUBLIC ucrt${LIB_SUFFIX}) # Universal C runtime + target_link_libraries(${target} PUBLIC vcruntime${LIB_SUFFIX}) # C++ runtime + target_link_libraries(${target} PUBLIC msvcrt${LIB_SUFFIX}) # C runtime startup files + target_link_libraries(${target} PUBLIC 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} PUBLIC iso_stdio_wide_specifiers) + endif() +endfunction() + +function(cxx_set_common_defines name) + if(LIBCXX_CXX_ABI_HEADER_TARGET) + add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) + endif() + if(WIN32 AND NOT MINGW) + target_compile_definitions(${name} + 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() + +split_list(LIBCXX_COMPILE_FLAGS) +split_list(LIBCXX_LINK_FLAGS) + +# Build the shared library. +if (LIBCXX_ENABLE_SHARED) + add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + if(COMMAND llvm_setup_rpath) + llvm_setup_rpath(cxx_shared) + endif() + cxx_link_system_libraries(cxx_shared) + target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES}) + set_target_properties(cxx_shared + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++" + VERSION "${LIBCXX_ABI_VERSION}.0" + SOVERSION "${LIBCXX_ABI_VERSION}" + DEFINE_SYMBOL "" + ) + cxx_set_common_defines(cxx_shared) + + # Link against LLVM libunwind + if (LIBCXXABI_USE_LLVM_UNWINDER) + if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) + target_link_libraries(cxx_shared PUBLIC unwind_shared) + list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind_shared) # For the linker script + elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) + # libunwind is already included in libc++abi + else() + target_link_libraries(cxx_shared PRIVATE unwind) + list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind) # For the linker script + endif() + endif() + + # Link against libc++abi + if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) + if (APPLE) + target_link_libraries(cxx_shared PRIVATE "-Wl,-force_load" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}") + else() + target_link_libraries(cxx_shared PRIVATE "-Wl,--whole-archive,-Bstatic" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" "-Wl,-Bdynamic,--no-whole-archive") + endif() + else() + target_link_libraries(cxx_shared PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") + list(APPEND LIBCXX_INTERFACE_LIBRARIES "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") # For the linker script + endif() + + # Maybe re-export symbols from libc++abi + if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR + LIBCXX_CXX_ABI_LIBNAME STREQUAL "default") + AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) + set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) + endif() + + if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) + if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$") + set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++sjlj-abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") + else() + set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") + endif() + target_link_libraries(cxx_shared PRIVATE + "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp" + "-Wl,-reexported_symbols_list,${RE_EXPORT_LIST}" + "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp" + "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp") + + if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + target_link_libraries(cxx_shared PRIVATE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi-new-delete.exp") + endif() + endif() + + # Generate a linker script in place of a libc++.so symlink. Rerun this command + # after cxx builds. + if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + # Get the name of the ABI library and handle the case where CXXABI_LIBNAME + # is a target name and not a library. Ex cxxabi_shared. + set(LIBCXX_INTERFACE_LIBRARY_NAMES) + foreach(lib ${LIBCXX_INTERFACE_LIBRARIES}) + # FIXME: Handle cxxabi_static and unwind_static. + if (TARGET ${lib} OR + (${lib} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI) OR + (${lib} MATCHES "unwind(_static|_shared)?" AND HAVE_LIBUNWIND)) + list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$<TARGET_PROPERTY:${lib},OUTPUT_NAME>") + else() + list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}") + endif() + endforeach() + add_custom_command(TARGET cxx_shared POST_BUILD + COMMAND + ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py + ARGS + --input "$<TARGET_SONAME_FILE:cxx_shared>" + --output "$<TARGET_LINKER_FILE:cxx_shared>" + ${LIBCXX_INTERFACE_LIBRARY_NAMES} + WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} + ) + endif() + + list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") + if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") + # Since we most likely do not have a mt.exe replacement, disable the + # manifest bundling. This allows a normal cmake invocation to pass which + # will attempt to use the manifest tool to generate the bundled manifest + set_target_properties(cxx_shared PROPERTIES + APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") + endif() +endif() + +# Build the static library. +if (LIBCXX_ENABLE_STATIC) + add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + cxx_link_system_libraries(cxx_static) + target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES}) + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") + set_target_properties(cxx_static + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++" + ) + cxx_set_common_defines(cxx_static) + + if (LIBCXX_HERMETIC_STATIC_LIBRARY) + append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility=hidden) + # If the hermetic library doesn't define the operator new/delete functions + # then its code shouldn't declare them with hidden visibility. They might + # actually be provided by a shared library at link time. + if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) + endif() + target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) + target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) + endif() + + list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") + # Attempt to merge the libc++.a archive and the ABI library archive into one. + if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) + set(MERGE_ARCHIVES_SEARCH_PATHS "") + if (LIBCXX_CXX_ABI_LIBRARY_PATH) + set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") + endif() + if (TARGET "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" OR HAVE_LIBCXXABI) + set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:${LIBCXX_CXX_STATIC_ABI_LIBRARY}>") + else() + set(MERGE_ARCHIVES_ABI_TARGET + "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + if (APPLE) + set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}") + endif() + add_custom_command(TARGET cxx_static POST_BUILD + COMMAND + ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py + ARGS + -o $<TARGET_LINKER_FILE:cxx_static> + --ar "${CMAKE_AR}" + ${MERGE_ARCHIVES_LIBTOOL} + "$<TARGET_LINKER_FILE:cxx_static>" + "${MERGE_ARCHIVES_ABI_TARGET}" + "${MERGE_ARCHIVES_SEARCH_PATHS}" + WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} + ) + endif() +endif() + +# Add a meta-target for both libraries. +add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS}) + +if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) + set(LIBCXX_EXPERIMENTAL_SOURCES + experimental/memory_resource.cpp + ) + add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) + if (LIBCXX_ENABLE_SHARED) + target_link_libraries(cxx_experimental cxx_shared) + else() + target_link_libraries(cxx_experimental cxx_static) + endif() + + set(experimental_flags "${LIBCXX_COMPILE_FLAGS}") + check_flag_supported(-std=c++14) + if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) + string(REPLACE "-std=c++11" "-std=c++14" experimental_flags "${LIBCXX_COMPILE_FLAGS}") + endif() + set_target_properties(cxx_experimental + PROPERTIES + COMPILE_FLAGS "${experimental_flags}" + OUTPUT_NAME "c++experimental" + ) +endif() + +if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) + file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) + + if (LIBCXX_ENABLE_SHARED) + add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) + else() + add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) + endif() + + set_target_properties(cxx_external_threads + PROPERTIES + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + OUTPUT_NAME "c++external_threads" + ) +endif() + +if (LIBCXX_INSTALL_LIBRARY) + if (LIBCXX_INSTALL_SHARED_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib} + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise + # it will not be executed after the library symlinks are installed. + if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> + # after we required CMake 3.0. + install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" + DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} + COMPONENT libcxx) + endif() +endif() + +if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR + LIBCXX_INSTALL_HEADERS)) + if(LIBCXX_INSTALL_LIBRARY) + set(lib_install_target cxx) + endif() + if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + set(experimental_lib_install_target cxx_experimental) + endif() + if(LIBCXX_INSTALL_HEADERS) + set(header_install_target install-cxx-headers) + endif() + add_custom_target(install-cxx + DEPENDS ${lib_install_target} + ${experimental_lib_install_target} + ${header_install_target} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx + -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") + add_custom_target(install-cxx-stripped + DEPENDS ${lib_install_target} + ${experimental_lib_install_target} + ${header_install_target} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx + -DCMAKE_INSTALL_DO_STRIP=1 + -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") + add_custom_target(install-libcxx DEPENDS install-cxx) +endif() diff --git a/contrib/libc++/src/algorithm.cpp b/contrib/libc++/src/algorithm.cpp index f036eb7abe1c..a110ae8b1a6e 100644 --- a/contrib/libc++/src/algorithm.cpp +++ b/contrib/libc++/src/algorithm.cpp @@ -1,15 +1,19 @@ //===----------------------- algorithm.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 "algorithm" #include "random" +#ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/contrib/libc++/src/any.cpp b/contrib/libc++/src/any.cpp index 3795258bb061..0cf09068837d 100644 --- a/contrib/libc++/src/any.cpp +++ b/contrib/libc++/src/any.cpp @@ -1,9 +1,8 @@ //===---------------------------- any.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/bind.cpp b/contrib/libc++/src/bind.cpp index b4c76ffe6a4d..53efdf9df375 100644 --- a/contrib/libc++/src/bind.cpp +++ b/contrib/libc++/src/bind.cpp @@ -1,9 +1,8 @@ //===-------------------------- bind.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/charconv.cpp b/contrib/libc++/src/charconv.cpp index ec241db74471..d3035883a78f 100644 --- a/contrib/libc++/src/charconv.cpp +++ b/contrib/libc++/src/charconv.cpp @@ -1,9 +1,8 @@ //===------------------------- charconv.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -61,48 +60,50 @@ append4(char* buffer, T i) return append2(append2(buffer, (i) / 100), (i) % 100); } -char* -__u32toa(uint32_t value, char* buffer) +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append2_no_zeros(char* buffer, T v) +{ + if (v < 10) + return append1(buffer, v); + else + return append2(buffer, v); +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append4_no_zeros(char* buffer, T v) +{ + if (v < 100) + return append2_no_zeros(buffer, v); + else if (v < 1000) + return append3(buffer, v); + else + return append4(buffer, v); +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append8_no_zeros(char* buffer, T v) { - if (value < 10000) + if (v < 10000) { - if (value < 100) - { - if (value < 10) - buffer = append1(buffer, value); - else - buffer = append2(buffer, value); - } - else - { - if (value < 1000) - buffer = append3(buffer, value); - else - buffer = append4(buffer, value); - } + buffer = append4_no_zeros(buffer, v); } - else if (value < 100000000) + else + { + buffer = append4_no_zeros(buffer, v / 10000); + buffer = append4(buffer, v % 10000); + } + return buffer; +} + +char* +__u32toa(uint32_t value, char* buffer) +{ + if (value < 100000000) { - // value = bbbbcccc - const uint32_t b = value / 10000; - const uint32_t c = value % 10000; - - if (value < 1000000) - { - if (value < 100000) - buffer = append1(buffer, b); - else - buffer = append2(buffer, b); - } - else - { - if (value < 10000000) - buffer = append3(buffer, b); - else - buffer = append4(buffer, b); - } - - buffer = append4(buffer, c); + buffer = append8_no_zeros(buffer, value); } else { @@ -110,11 +111,7 @@ __u32toa(uint32_t value, char* buffer) const uint32_t a = value / 100000000; // 1 to 42 value %= 100000000; - if (a < 10) - buffer = append1(buffer, a); - else - buffer = append2(buffer, a); - + buffer = append2_no_zeros(buffer, a); buffer = append4(buffer, value / 10000); buffer = append4(buffer, value % 10000); } @@ -128,71 +125,14 @@ __u64toa(uint64_t value, char* buffer) if (value < 100000000) { uint32_t v = static_cast<uint32_t>(value); - if (v < 10000) - { - if (v < 100) - { - if (v < 10) - buffer = append1(buffer, v); - else - buffer = append2(buffer, v); - } - else - { - if (v < 1000) - buffer = append3(buffer, v); - else - buffer = append4(buffer, v); - } - } - else - { - // value = bbbbcccc - const uint32_t b = v / 10000; - const uint32_t c = v % 10000; - - if (v < 1000000) - { - if (v < 100000) - buffer = append1(buffer, b); - else - buffer = append2(buffer, b); - } - else - { - if (v < 10000000) - buffer = append3(buffer, b); - else - buffer = append4(buffer, b); - } - - buffer = append4(buffer, c); - } + buffer = append8_no_zeros(buffer, v); } else if (value < 10000000000000000) { const uint32_t v0 = static_cast<uint32_t>(value / 100000000); const uint32_t v1 = static_cast<uint32_t>(value % 100000000); - const uint32_t b0 = v0 / 10000; - const uint32_t c0 = v0 % 10000; - - if (v0 < 1000000) - { - if (v0 < 100000) - buffer = append1(buffer, b0); - else - buffer = append2(buffer, b0); - } - else - { - if (v0 < 10000000) - buffer = append3(buffer, b0); - else - buffer = append4(buffer, b0); - } - - buffer = append4(buffer, c0); + buffer = append8_no_zeros(buffer, v0); buffer = append4(buffer, v1 / 10000); buffer = append4(buffer, v1 % 10000); } @@ -202,20 +142,7 @@ __u64toa(uint64_t value, char* buffer) static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844 value %= 10000000000000000; - if (a < 100) - { - if (a < 10) - buffer = append1(buffer, a); - else - buffer = append2(buffer, a); - } - else - { - if (a < 1000) - buffer = append3(buffer, a); - else - buffer = append4(buffer, a); - } + buffer = append4_no_zeros(buffer, a); const uint32_t v0 = static_cast<uint32_t>(value / 100000000); const uint32_t v1 = static_cast<uint32_t>(value % 100000000); diff --git a/contrib/libc++/src/chrono.cpp b/contrib/libc++/src/chrono.cpp index 882d50b9d731..8f533f1059ed 100644 --- a/contrib/libc++/src/chrono.cpp +++ b/contrib/libc++/src/chrono.cpp @@ -1,9 +1,8 @@ //===------------------------- chrono.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -38,6 +37,10 @@ #endif #endif +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "rt") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono @@ -178,16 +181,26 @@ steady_clock::now() _NOEXCEPT #elif defined(_LIBCPP_WIN32API) +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says: +// If the function fails, the return value is zero. <snip> +// On systems that run Windows XP or later, the function will always succeed +// and will thus never return zero. + +static LARGE_INTEGER +__QueryPerformanceFrequency() +{ + LARGE_INTEGER val; + (void) QueryPerformanceFrequency(&val); + return val; +} + steady_clock::time_point steady_clock::now() _NOEXCEPT { - static LARGE_INTEGER freq; - static BOOL initialized = FALSE; - if (!initialized) - initialized = QueryPerformanceFrequency(&freq); // always succceeds + static const LARGE_INTEGER freq = __QueryPerformanceFrequency(); LARGE_INTEGER counter; - QueryPerformanceCounter(&counter); + (void) QueryPerformanceCounter(&counter); return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart)); } diff --git a/contrib/libc++/src/condition_variable.cpp b/contrib/libc++/src/condition_variable.cpp index 2200aefb804d..b8426c66fde6 100644 --- a/contrib/libc++/src/condition_variable.cpp +++ b/contrib/libc++/src/condition_variable.cpp @@ -1,9 +1,8 @@ //===-------------------- condition_variable.cpp --------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -16,12 +15,13 @@ #include "system_error" #include "__undef_macros" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD -condition_variable::~condition_variable() -{ - __libcpp_condvar_destroy(&__cv_); -} +// ~condition_variable is defined elsewhere. void condition_variable::notify_one() _NOEXCEPT @@ -57,7 +57,7 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk, nanoseconds d = tp.time_since_epoch(); if (d > nanoseconds(0x59682F000000E941)) d = nanoseconds(0x59682F000000E941); - timespec ts; + __libcpp_timespec_t ts; seconds s = duration_cast<seconds>(d); typedef decltype(ts.tv_sec) ts_sec; _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); diff --git a/contrib/libc++/src/condition_variable_destructor.cpp b/contrib/libc++/src/condition_variable_destructor.cpp new file mode 100644 index 000000000000..44fa240ba78b --- /dev/null +++ b/contrib/libc++/src/condition_variable_destructor.cpp @@ -0,0 +1,46 @@ +//===---------------- condition_variable_destructor.cpp ------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// Define ~condition_variable. +// +// On some platforms ~condition_variable has been made trivial and the +// definition is only provided for ABI compatibility. + +#include "__config" +#include "__threading_support" + +#if !defined(_LIBCPP_HAS_NO_THREADS) +# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION) +# define NEEDS_CONDVAR_DESTRUCTOR +# endif +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef NEEDS_CONDVAR_DESTRUCTOR + +class _LIBCPP_TYPE_VIS condition_variable +{ + __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; +public: + _LIBCPP_INLINE_VISIBILITY + constexpr condition_variable() noexcept = default; + + ~condition_variable(); + + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; +}; + +condition_variable::~condition_variable() +{ + __libcpp_condvar_destroy(&__cv_); +} +#endif + +_LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libc++/src/debug.cpp b/contrib/libc++/src/debug.cpp index f2fc1ceb495a..c4cc281d586b 100644 --- a/contrib/libc++/src/debug.cpp +++ b/contrib/libc++/src/debug.cpp @@ -1,9 +1,8 @@ //===-------------------------- debug.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -14,18 +13,27 @@ #include "string" #include "cstdio" #include "__hash_table" +#ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif _LIBCPP_BEGIN_NAMESPACE_STD -static std::string make_what_str(__libcpp_debug_info const& info) { - string msg = info.__file_; - msg += ":" + to_string(info.__line_) + ": _LIBCPP_ASSERT '"; - msg += info.__pred_; +std::string __libcpp_debug_info::what() const { + string msg = __file_; + msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '"; + msg += __pred_; msg += "' failed. "; - msg += info.__msg_; + msg += __msg_; return msg; } +_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { + std::fprintf(stderr, "%s\n", info.what().c_str()); + std::abort(); +} _LIBCPP_SAFE_STATIC __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function; @@ -35,56 +43,11 @@ bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) { return true; } -_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { - std::fprintf(stderr, "%s\n", make_what_str(info).c_str()); - std::abort(); -} - -_LIBCPP_NORETURN void __libcpp_throw_debug_function(__libcpp_debug_info const& info) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw __libcpp_debug_exception(info); -#else - __libcpp_abort_debug_function(info); -#endif -} - -struct __libcpp_debug_exception::__libcpp_debug_exception_imp { - __libcpp_debug_info __info_; - std::string __what_str_; -}; - -__libcpp_debug_exception::__libcpp_debug_exception() _NOEXCEPT - : __imp_(nullptr) { -} - -__libcpp_debug_exception::__libcpp_debug_exception( - __libcpp_debug_info const& info) : __imp_(new __libcpp_debug_exception_imp) -{ - __imp_->__info_ = info; - __imp_->__what_str_ = make_what_str(info); -} -__libcpp_debug_exception::__libcpp_debug_exception( - __libcpp_debug_exception const& other) : __imp_(nullptr) { - if (other.__imp_) - __imp_ = new __libcpp_debug_exception_imp(*other.__imp_); -} - -__libcpp_debug_exception::~__libcpp_debug_exception() _NOEXCEPT { - if (__imp_) - delete __imp_; -} - -const char* __libcpp_debug_exception::what() const _NOEXCEPT { - if (__imp_) - return __imp_->__what_str_.c_str(); - return "__libcpp_debug_exception"; -} - _LIBCPP_FUNC_VIS __libcpp_db* __get_db() { - static __libcpp_db db; + static _LIBCPP_NO_DESTROY __libcpp_db db; return &db; } @@ -106,7 +69,7 @@ typedef lock_guard<mutex_type> RLock; mutex_type& mut() { - static mutex_type m; + static _LIBCPP_NO_DESTROY mutex_type m; return m; } #endif // !_LIBCPP_HAS_NO_THREADS @@ -204,8 +167,8 @@ __libcpp_db::__insert_ic(void* __i, const void* __c) i->__c_ = c; } -__c_node* -__libcpp_db::__insert_c(void* __c) +void +__libcpp_db::__insert_c(void* __c, __libcpp_db::_InsertConstruct *__fn) { #ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); @@ -213,7 +176,7 @@ __libcpp_db::__insert_c(void* __c) if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1); - __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*))); + __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(__c_node*))); if (cbeg == nullptr) __throw_bad_alloc(); @@ -235,15 +198,12 @@ __libcpp_db::__insert_c(void* __c) } size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); __c_node* p = __cbeg_[hc]; - __c_node* r = __cbeg_[hc] = - static_cast<__c_node*>(malloc(sizeof(__c_node))); - if (__cbeg_[hc] == nullptr) - __throw_bad_alloc(); + void *buf = malloc(sizeof(__c_node)); + if (buf == nullptr) + __throw_bad_alloc(); + __cbeg_[hc] = __fn(buf, __c, p); - r->__c_ = __c; - r->__next_ = p; ++__csz_; - return r; } void @@ -553,7 +513,7 @@ __libcpp_db::__insert_iterator(void* __i) if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1); - __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*))); + __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(__i_node*))); if (ibeg == nullptr) __throw_bad_alloc(); diff --git a/contrib/libc++/src/exception.cpp b/contrib/libc++/src/exception.cpp index 3d2dcfd5b10e..fce6db7c38b6 100644 --- a/contrib/libc++/src/exception.cpp +++ b/contrib/libc++/src/exception.cpp @@ -1,9 +1,8 @@ //===------------------------ exception.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,8 +10,7 @@ #include "new" #include "typeinfo" -#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) || \ - (defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)) +#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) #include <cxxabi.h> using namespace __cxxabiv1; #define HAVE_DEPENDENT_EH_ABI 1 diff --git a/contrib/libc++/src/experimental/memory_resource.cpp b/contrib/libc++/src/experimental/memory_resource.cpp index 7f0052f2b50a..9aa077942b0d 100644 --- a/contrib/libc++/src/experimental/memory_resource.cpp +++ b/contrib/libc++/src/experimental/memory_resource.cpp @@ -1,9 +1,8 @@ //===------------------------ memory_resource.cpp -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -13,6 +12,9 @@ #include "atomic" #elif !defined(_LIBCPP_HAS_NO_THREADS) #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif #endif _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR @@ -26,19 +28,23 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { -public: - ~__new_delete_memory_resource_imp() = default; - -protected: - virtual void* do_allocate(size_t __size, size_t __align) - { return _VSTD::__libcpp_allocate(__size, __align); /* FIXME */} + void *do_allocate(size_t size, size_t align) override { +#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + if (__is_overaligned_for_new(align)) + __throw_bad_alloc(); +#endif + return _VSTD::__libcpp_allocate(size, align); + } - virtual void do_deallocate(void* __p, size_t __n, size_t __align) { - _VSTD::__libcpp_deallocate(__p, __n, __align); /* FIXME */ + void do_deallocate(void *p, size_t n, size_t align) override { + _VSTD::__libcpp_deallocate(p, n, align); } - virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT - { return &__other == this; } + bool do_is_equal(memory_resource const & other) const _NOEXCEPT override + { return &other == this; } + +public: + ~__new_delete_memory_resource_imp() override = default; }; // null_memory_resource() diff --git a/contrib/libc++/src/filesystem/directory_iterator.cpp b/contrib/libc++/src/filesystem/directory_iterator.cpp index f0d807a03db6..ca88dee06402 100644 --- a/contrib/libc++/src/filesystem/directory_iterator.cpp +++ b/contrib/libc++/src/filesystem/directory_iterator.cpp @@ -1,9 +1,8 @@ //===------------------ directory_iterator.cpp ----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -25,6 +24,8 @@ namespace detail { namespace { #if !defined(_LIBCPP_WIN32API) + +#if defined(DT_BLK) template <class DirEntT, class = decltype(DirEntT::d_type)> static file_type get_file_type(DirEntT* ent, int) { switch (ent->d_type) { @@ -50,6 +51,7 @@ static file_type get_file_type(DirEntT* ent, int) { } return file_type::none; } +#endif // defined(DT_BLK) template <class DirEntT> static file_type get_file_type(DirEntT* ent, long) { diff --git a/contrib/libc++/src/filesystem/filesystem_common.h b/contrib/libc++/src/filesystem/filesystem_common.h index 40419ee35e6a..fe5c42f5e6d0 100644 --- a/contrib/libc++/src/filesystem/filesystem_common.h +++ b/contrib/libc++/src/filesystem/filesystem_common.h @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===//// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===//// diff --git a/contrib/libc++/src/filesystem/int128_builtins.cpp b/contrib/libc++/src/filesystem/int128_builtins.cpp index 66adbdd2dc89..a55540fe276e 100644 --- a/contrib/libc++/src/filesystem/int128_builtins.cpp +++ b/contrib/libc++/src/filesystem/int128_builtins.cpp @@ -1,9 +1,8 @@ /*===-- int128_builtins.cpp - Implement __muloti4 --------------------------=== * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. + * 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 * * ===----------------------------------------------------------------------=== * diff --git a/contrib/libc++/src/filesystem/operations.cpp b/contrib/libc++/src/filesystem/operations.cpp index b41061888724..69350ddfe9da 100644 --- a/contrib/libc++/src/filesystem/operations.cpp +++ b/contrib/libc++/src/filesystem/operations.cpp @@ -1,9 +1,8 @@ //===--------------------- filesystem/ops.cpp -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -45,6 +44,10 @@ #include <sys/time.h> // for gettimeofday and timeval #endif // !defined(CLOCK_REALTIME) +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "rt") +#endif + #if defined(_LIBCPP_COMPILER_GCC) #if _GNUC_VER < 500 #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -543,11 +546,19 @@ path __canonical(path const& orig_p, error_code* ec) { ErrorHandler<path> err("canonical", ec, &orig_p, &cwd); path p = __do_absolute(orig_p, &cwd, ec); +#if _POSIX_VERSION >= 200112 + std::unique_ptr<char, decltype(&::free)> + hold(::realpath(p.c_str(), nullptr), &::free); + if (hold.get() == nullptr) + return err.report(capture_errno()); + return {hold.get()}; +#else char buff[PATH_MAX + 1]; char* ret; if ((ret = ::realpath(p.c_str(), buff)) == nullptr) return err.report(capture_errno()); return {ret}; +#endif } void __copy(const path& from, const path& to, copy_options options, @@ -1089,16 +1100,27 @@ void __permissions(const path& p, perms prms, perm_options opts, path __read_symlink(const path& p, error_code* ec) { ErrorHandler<path> err("read_symlink", ec, &p); - char buff[PATH_MAX + 1]; - error_code m_ec; - ::ssize_t ret; - if ((ret = ::readlink(p.c_str(), buff, PATH_MAX)) == -1) { +#ifdef PATH_MAX + struct NullDeleter { void operator()(void*) const {} }; + const size_t size = PATH_MAX + 1; + char stack_buff[size]; + auto buff = std::unique_ptr<char[], NullDeleter>(stack_buff); +#else + StatT sb; + if (::lstat(p.c_str(), &sb) == -1) { return err.report(capture_errno()); } - _LIBCPP_ASSERT(ret <= PATH_MAX, "TODO"); + const size_t size = sb.st_size + 1; + auto buff = unique_ptr<char[]>(new char[size]); +#endif + ::ssize_t ret; + if ((ret = ::readlink(p.c_str(), buff.get(), size)) == -1) + return err.report(capture_errno()); _LIBCPP_ASSERT(ret > 0, "TODO"); + if (static_cast<size_t>(ret) >= size) + return err.report(errc::value_too_large); buff[ret] = 0; - return {buff}; + return {buff.get()}; } bool __remove(const path& p, error_code* ec) { diff --git a/contrib/libc++/src/functional.cpp b/contrib/libc++/src/functional.cpp index 5c2646f01b2e..555d2c53f2b0 100644 --- a/contrib/libc++/src/functional.cpp +++ b/contrib/libc++/src/functional.cpp @@ -1,9 +1,8 @@ //===----------------------- functional.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/future.cpp b/contrib/libc++/src/future.cpp index cbcd2e7b7288..58d0b4c247cb 100644 --- a/contrib/libc++/src/future.cpp +++ b/contrib/libc++/src/future.cpp @@ -1,9 +1,8 @@ //===------------------------- future.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/hash.cpp b/contrib/libc++/src/hash.cpp index dc90f789c6b8..89bb736c86c2 100644 --- a/contrib/libc++/src/hash.cpp +++ b/contrib/libc++/src/hash.cpp @@ -1,9 +1,8 @@ //===-------------------------- hash.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -154,12 +153,8 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFB) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __throw_overflow_error("__next_prime overflow"); } template <size_t _Sz = sizeof(size_t)> @@ -167,12 +162,8 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFFFFFFFFC5ull) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __throw_overflow_error("__next_prime overflow"); } size_t diff --git a/contrib/libc++/src/include/apple_availability.h b/contrib/libc++/src/include/apple_availability.h index c12f7325cb41..0091138170fd 100644 --- a/contrib/libc++/src/include/apple_availability.h +++ b/contrib/libc++/src/include/apple_availability.h @@ -1,9 +1,8 @@ //===------------------------ apple_availability.h ------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H diff --git a/contrib/libc++/src/include/atomic_support.h b/contrib/libc++/src/include/atomic_support.h index ccd8d78d3d71..43c1a00234d2 100644 --- a/contrib/libc++/src/include/atomic_support.h +++ b/contrib/libc++/src/include/atomic_support.h @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===//// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===//// diff --git a/contrib/libc++/src/include/config_elast.h b/contrib/libc++/src/include/config_elast.h index c3cc19c2234f..501cbc4ffeba 100644 --- a/contrib/libc++/src/include/config_elast.h +++ b/contrib/libc++/src/include/config_elast.h @@ -1,9 +1,8 @@ //===----------------------- config_elast.h -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -24,6 +23,8 @@ #define _LIBCPP_ELAST __ELASTERROR #elif defined(__Fuchsia__) // No _LIBCPP_ELAST needed on Fuchsia +#elif defined(__wasi__) +// No _LIBCPP_ELAST needed on WASI #elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_ELAST 4095 #elif defined(__APPLE__) diff --git a/contrib/libc++/src/include/refstring.h b/contrib/libc++/src/include/refstring.h index 702f2b7388da..e464b79ba89c 100644 --- a/contrib/libc++/src/include/refstring.h +++ b/contrib/libc++/src/include/refstring.h @@ -1,9 +1,8 @@ //===------------------------ __refstring ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/ios.cpp b/contrib/libc++/src/ios.cpp index 0f1d88e378f5..2dc84be82873 100644 --- a/contrib/libc++/src/ios.cpp +++ b/contrib/libc++/src/ios.cpp @@ -1,9 +1,8 @@ //===-------------------------- ios.cpp -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -267,10 +266,9 @@ ios_base::clear(iostate state) __rdstate_ = state; else __rdstate_ = state | badbit; -#ifndef _LIBCPP_NO_EXCEPTIONS + if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0) - throw failure("ios_base::clear"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_failure("ios_base::clear"); } // init @@ -310,35 +308,27 @@ ios_base::copyfmt(const ios_base& rhs) { size_t newesize = sizeof(event_callback) * rhs.__event_size_; new_callbacks.reset(static_cast<event_callback*>(malloc(newesize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_callbacks) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); size_t newisize = sizeof(int) * rhs.__event_size_; new_ints.reset(static_cast<int *>(malloc(newisize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_ints) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } if (__iarray_cap_ < rhs.__iarray_size_) { size_t newsize = sizeof(long) * rhs.__iarray_size_; new_longs.reset(static_cast<long*>(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_longs) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } if (__parray_cap_ < rhs.__parray_size_) { size_t newsize = sizeof(void*) * rhs.__parray_size_; new_pointers.reset(static_cast<void**>(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_pointers) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_ __fmtflags_ = rhs.__fmtflags_; diff --git a/contrib/libc++/src/iostream.cpp b/contrib/libc++/src/iostream.cpp index 11bfb486208e..0a5d6e8d2264 100644 --- a/contrib/libc++/src/iostream.cpp +++ b/contrib/libc++/src/iostream.cpp @@ -1,13 +1,13 @@ //===------------------------ iostream.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 "__std_stream" +#include "__locale" #include "string" #include "new" @@ -79,8 +79,28 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t _LIBCPP_HIDDEN ios_base::Init __start_std_streams; +// On Windows the TLS storage for locales needs to be initialized before we create +// the standard streams, otherwise it may not be alive during program termination +// when we flush the streams. +static void force_locale_initialization() { +#if defined(_LIBCPP_MSVCRT_LIKE) + static bool once = []() { + auto loc = newlocale(LC_ALL_MASK, "C", 0); + { + __libcpp_locale_guard g(loc); // forces initialization of locale TLS + ((void)g); + } + freelocale(loc); + return true; + }(); + ((void)once); +#endif +} + ios_base::Init::Init() { + force_locale_initialization(); + #ifndef _LIBCPP_HAS_NO_STDIN istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin)); wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin)); diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp index b9c701137df2..5b29ee448685 100644 --- a/contrib/libc++/src/locale.cpp +++ b/contrib/libc++/src/locale.cpp @@ -1,9 +1,8 @@ //===------------------------- locale.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -469,10 +468,8 @@ locale::__imp::install(facet* f, long id) const locale::facet* locale::__imp::use_facet(long id) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!has_facet(id)) - throw bad_cast(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_cast(); return facets_[static_cast<size_t>(id)]; } @@ -538,12 +535,8 @@ locale::operator=(const locale& other) _NOEXCEPT } locale::locale(const char* name) -#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(name) - : throw runtime_error("locale constructed with null")) -#else // _LIBCPP_NO_EXCEPTIONS - : __locale_(new __imp(name)) -#endif + : (__throw_runtime_error("locale constructed with null"), (__imp*)0)) { __locale_->__add_shared(); } @@ -555,12 +548,8 @@ locale::locale(const string& name) } locale::locale(const locale& other, const char* name, category c) -#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(*other.__locale_, name, c) - : throw runtime_error("locale constructed with null")) -#else // _LIBCPP_NO_EXCEPTIONS - : __locale_(new __imp(*other.__locale_, name, c)) -#endif + : (__throw_runtime_error("locale constructed with null"), (__imp*)0)) { __locale_->__add_shared(); } @@ -4390,7 +4379,9 @@ void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err) { - if (__grouping.size() != 0) +// if the grouping pattern is empty _or_ there are no grouping bits, then do nothing +// we always have at least a single entry in [__g, __g_end); the end of the input sequence + if (__grouping.size() != 0 && __g_end - __g > 1) { reverse(__g, __g_end); const char* __ig = __grouping.data(); diff --git a/contrib/libc++/src/memory.cpp b/contrib/libc++/src/memory.cpp index 77ebe837c73c..c8c00383cf92 100644 --- a/contrib/libc++/src/memory.cpp +++ b/contrib/libc++/src/memory.cpp @@ -1,9 +1,8 @@ //===------------------------ memory.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,6 +10,9 @@ #ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" #include "thread" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif #endif #include "include/atomic_support.h" diff --git a/contrib/libc++/src/mutex.cpp b/contrib/libc++/src/mutex.cpp index e31ec83bceaf..ceb4980c9147 100644 --- a/contrib/libc++/src/mutex.cpp +++ b/contrib/libc++/src/mutex.cpp @@ -1,9 +1,8 @@ //===------------------------- mutex.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -13,6 +12,12 @@ #include "include/atomic_support.h" #include "__undef_macros" +#ifndef _LIBCPP_HAS_NO_THREADS +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_THREADS @@ -20,10 +25,7 @@ const defer_lock_t defer_lock = {}; const try_to_lock_t try_to_lock = {}; const adopt_lock_t adopt_lock = {}; -mutex::~mutex() -{ - __libcpp_mutex_destroy(&__m_); -} +// ~mutex is defined elsewhere void mutex::lock() @@ -198,8 +200,8 @@ _LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER; _LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER; #endif -void -__call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) +void __call_once(volatile once_flag::_State_type& flag, void* arg, + void (*func)(void*)) { #if defined(_LIBCPP_HAS_NO_THREADS) if (flag == 0) @@ -210,12 +212,12 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) #endif // _LIBCPP_NO_EXCEPTIONS flag = 1; func(arg); - flag = ~0ul; + flag = ~once_flag::_State_type(0); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - flag = 0ul; + flag = 0; throw; } #endif // _LIBCPP_NO_EXCEPTIONS @@ -230,11 +232,12 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) try { #endif // _LIBCPP_NO_EXCEPTIONS - __libcpp_relaxed_store(&flag, 1ul); + __libcpp_relaxed_store(&flag, once_flag::_State_type(1)); __libcpp_mutex_unlock(&mut); func(arg); __libcpp_mutex_lock(&mut); - __libcpp_atomic_store(&flag, ~0ul, _AO_Release); + __libcpp_atomic_store(&flag, ~once_flag::_State_type(0), + _AO_Release); __libcpp_mutex_unlock(&mut); __libcpp_condvar_broadcast(&cv); #ifndef _LIBCPP_NO_EXCEPTIONS @@ -242,7 +245,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) catch (...) { __libcpp_mutex_lock(&mut); - __libcpp_relaxed_store(&flag, 0ul); + __libcpp_relaxed_store(&flag, once_flag::_State_type(0)); __libcpp_mutex_unlock(&mut); __libcpp_condvar_broadcast(&cv); throw; @@ -252,7 +255,6 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) else __libcpp_mutex_unlock(&mut); #endif // !_LIBCPP_HAS_NO_THREADS - } _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libc++/src/mutex_destructor.cpp b/contrib/libc++/src/mutex_destructor.cpp new file mode 100644 index 000000000000..3a6b6b55eeb7 --- /dev/null +++ b/contrib/libc++/src/mutex_destructor.cpp @@ -0,0 +1,51 @@ +//===--------------------- mutex_destructor.cpp ---------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// Define ~mutex. +// +// On some platforms ~mutex has been made trivial and the definition is only +// provided for ABI compatibility. +// +// In order to avoid ODR violations within libc++ itself, we need to ensure +// that *nothing* sees the non-trivial mutex declaration. For this reason +// we re-declare the entire class in this file instead of using +// _LIBCPP_BUILDING_LIBRARY to change the definition in the headers. + +#include "__config" +#include "__threading_support" + +#if !defined(_LIBCPP_HAS_NO_THREADS) +#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION) +#define NEEDS_MUTEX_DESTRUCTOR +#endif +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef NEEDS_MUTEX_DESTRUCTOR +class _LIBCPP_TYPE_VIS mutex +{ + __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; + +public: + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + constexpr mutex() = default; + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + ~mutex() noexcept; +}; + + +mutex::~mutex() _NOEXCEPT +{ + __libcpp_mutex_destroy(&__m_); +} + +#endif // !_LIBCPP_HAS_NO_THREADS +_LIBCPP_END_NAMESPACE_STD + diff --git a/contrib/libc++/src/new.cpp b/contrib/libc++/src/new.cpp index cc8383d4f146..901e78565857 100644 --- a/contrib/libc++/src/new.cpp +++ b/contrib/libc++/src/new.cpp @@ -1,9 +1,8 @@ //===--------------------------- new.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -13,29 +12,25 @@ #include "include/atomic_support.h" #if defined(_LIBCPP_ABI_MICROSOFT) -#if defined(_LIBCPP_NO_VCRUNTIME) -#include "support/runtime/new_handler_fallback.ipp" -#endif +# if !defined(_LIBCPP_ABI_VCRUNTIME) +# include "support/runtime/new_handler_fallback.ipp" +# endif #elif defined(LIBCXX_BUILDING_LIBCXXABI) -#include <cxxabi.h> +# include <cxxabi.h> #elif defined(LIBCXXRT) -#include <cxxabi.h> -#include "support/runtime/new_handler_fallback.ipp" +# include <cxxabi.h> +# include "support/runtime/new_handler_fallback.ipp" #elif defined(__GLIBCXX__) -// nothing todo + // nothing to do #else -# if defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) -# include <cxxabi.h> // FIXME: remove this once buildit is gone. -# else # include "support/runtime/new_handler_fallback.ipp" -# endif #endif namespace std { #ifndef __GLIBCXX__ -const nothrow_t nothrow = {}; +const nothrow_t nothrow{}; #endif #ifndef LIBSTDCXX @@ -55,7 +50,7 @@ __throw_bad_alloc() } // std #if !defined(__GLIBCXX__) && \ - !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) && \ + !defined(_LIBCPP_ABI_VCRUNTIME) && \ !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) // Implement all new and delete operators as weak definitions @@ -299,4 +294,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT } #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -#endif // !__GLIBCXX__ && (!_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME) && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS +#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS diff --git a/contrib/libc++/src/optional.cpp b/contrib/libc++/src/optional.cpp index 6099b6b41e89..3aaf5ea553ef 100644 --- a/contrib/libc++/src/optional.cpp +++ b/contrib/libc++/src/optional.cpp @@ -1,9 +1,8 @@ //===------------------------ optional.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/random.cpp b/contrib/libc++/src/random.cpp index 4a2468368d06..04adc59f9bc9 100644 --- a/contrib/libc++/src/random.cpp +++ b/contrib/libc++/src/random.cpp @@ -1,9 +1,8 @@ //===-------------------------- random.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/regex.cpp b/contrib/libc++/src/regex.cpp index a7363599d5a5..a971f646459b 100644 --- a/contrib/libc++/src/regex.cpp +++ b/contrib/libc++/src/regex.cpp @@ -1,9 +1,8 @@ //===-------------------------- regex.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/shared_mutex.cpp b/contrib/libc++/src/shared_mutex.cpp index 6185f15deabd..eb3f5f3506f5 100644 --- a/contrib/libc++/src/shared_mutex.cpp +++ b/contrib/libc++/src/shared_mutex.cpp @@ -1,9 +1,8 @@ //===---------------------- shared_mutex.cpp ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,6 +10,9 @@ #ifndef _LIBCPP_HAS_NO_THREADS #include "shared_mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/contrib/libc++/src/stdexcept.cpp b/contrib/libc++/src/stdexcept.cpp index 5e06e521e404..f8f335f34ae1 100644 --- a/contrib/libc++/src/stdexcept.cpp +++ b/contrib/libc++/src/stdexcept.cpp @@ -1,9 +1,8 @@ //===------------------------ stdexcept.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,94 +10,10 @@ #include "new" #include "string" #include "system_error" -#include "include/refstring.h" - -/* For _LIBCPPABI_VERSION */ -#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ - (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(__APPLE__) || defined(LIBCXXRT)) -#include <cxxabi.h> -#endif - -static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char *), ""); - - -namespace std // purposefully not using versioning namespace -{ - -logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) -{ -} - -logic_error::logic_error(const char* msg) : __imp_(msg) -{ -} - -logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) -{ -} - -logic_error& -logic_error::operator=(const logic_error& le) _NOEXCEPT -{ - __imp_ = le.__imp_; - return *this; -} - -#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) - -logic_error::~logic_error() _NOEXCEPT -{ -} -const char* -logic_error::what() const _NOEXCEPT -{ - return __imp_.c_str(); -} +#ifdef _LIBCPP_ABI_VCRUNTIME +#include "support/runtime/stdexcept_vcruntime.ipp" +#else +#include "support/runtime/stdexcept_default.ipp" #endif - -runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) -{ -} - -runtime_error::runtime_error(const char* msg) : __imp_(msg) -{ -} - -runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT - : __imp_(le.__imp_) -{ -} - -runtime_error& -runtime_error::operator=(const runtime_error& le) _NOEXCEPT -{ - __imp_ = le.__imp_; - return *this; -} - -#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) - -runtime_error::~runtime_error() _NOEXCEPT -{ -} - -const char* -runtime_error::what() const _NOEXCEPT -{ - return __imp_.c_str(); -} - -domain_error::~domain_error() _NOEXCEPT {} -invalid_argument::~invalid_argument() _NOEXCEPT {} -length_error::~length_error() _NOEXCEPT {} -out_of_range::~out_of_range() _NOEXCEPT {} - -range_error::~range_error() _NOEXCEPT {} -overflow_error::~overflow_error() _NOEXCEPT {} -underflow_error::~underflow_error() _NOEXCEPT {} - -#endif - -} // std diff --git a/contrib/libc++/src/string.cpp b/contrib/libc++/src/string.cpp index d7ebdd3e5c9a..4802d63c811b 100644 --- a/contrib/libc++/src/string.cpp +++ b/contrib/libc++/src/string.cpp @@ -1,19 +1,20 @@ //===------------------------- string.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 "string" +#include "charconv" #include "cstdlib" #include "cwchar" #include "cerrno" #include "limits" #include "stdexcept" #include <stdio.h> +#include "__debug" _LIBCPP_BEGIN_NAMESPACE_STD @@ -172,7 +173,7 @@ as_integer( const string& func, const wstring& s, size_t* idx, int base ) // as_float -template<typename V, typename S, typename F> +template<typename V, typename S, typename F> inline V as_float_helper(const string& func, const S& str, size_t* idx, F f ) @@ -376,11 +377,11 @@ as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) return s; } -template <class S, class V, bool = is_floating_point<V>::value> +template <class S> struct initial_string; -template <class V, bool b> -struct initial_string<string, V, b> +template <> +struct initial_string<string> { string operator()() const @@ -391,23 +392,8 @@ struct initial_string<string, V, b> } }; -template <class V> -struct initial_string<wstring, V, false> -{ - wstring - operator()() const - { - const size_t n = (numeric_limits<unsigned long long>::digits / 3) - + ((numeric_limits<unsigned long long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - return s; - } -}; - -template <class V> -struct initial_string<wstring, V, true> +template <> +struct initial_string<wstring> { wstring operator()() const @@ -431,95 +417,42 @@ get_swprintf() #endif } -} // unnamed namespace - -string to_string(int val) -{ - return as_string(snprintf, initial_string<string, int>()(), "%d", val); -} - -string to_string(unsigned val) -{ - return as_string(snprintf, initial_string<string, unsigned>()(), "%u", val); -} - -string to_string(long val) -{ - return as_string(snprintf, initial_string<string, long>()(), "%ld", val); -} - -string to_string(unsigned long val) -{ - return as_string(snprintf, initial_string<string, unsigned long>()(), "%lu", val); -} - -string to_string(long long val) -{ - return as_string(snprintf, initial_string<string, long long>()(), "%lld", val); -} - -string to_string(unsigned long long val) -{ - return as_string(snprintf, initial_string<string, unsigned long long>()(), "%llu", val); -} - -string to_string(float val) -{ - return as_string(snprintf, initial_string<string, float>()(), "%f", val); -} - -string to_string(double val) -{ - return as_string(snprintf, initial_string<string, double>()(), "%f", val); -} - -string to_string(long double val) +template <typename S, typename V> +S i_to_string(const V v) { - return as_string(snprintf, initial_string<string, long double>()(), "%Lf", val); +// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. +// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), +// so we need +1 here. + constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10 + char buf[bufsize]; + const auto res = to_chars(buf, buf + bufsize, v); + _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value"); + return S(buf, res.ptr); } -wstring to_wstring(int val) -{ - return as_string(get_swprintf(), initial_string<wstring, int>()(), L"%d", val); -} - -wstring to_wstring(unsigned val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned>()(), L"%u", val); -} - -wstring to_wstring(long val) -{ - return as_string(get_swprintf(), initial_string<wstring, long>()(), L"%ld", val); -} +} // unnamed namespace -wstring to_wstring(unsigned long val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned long>()(), L"%lu", val); -} +string to_string (int val) { return i_to_string< string>(val); } +string to_string (long val) { return i_to_string< string>(val); } +string to_string (long long val) { return i_to_string< string>(val); } +string to_string (unsigned val) { return i_to_string< string>(val); } +string to_string (unsigned long val) { return i_to_string< string>(val); } +string to_string (unsigned long long val) { return i_to_string< string>(val); } -wstring to_wstring(long long val) -{ - return as_string(get_swprintf(), initial_string<wstring, long long>()(), L"%lld", val); -} +wstring to_wstring(int val) { return i_to_string<wstring>(val); } +wstring to_wstring(long val) { return i_to_string<wstring>(val); } +wstring to_wstring(long long val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); } -wstring to_wstring(unsigned long long val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned long long>()(), L"%llu", val); -} -wstring to_wstring(float val) -{ - return as_string(get_swprintf(), initial_string<wstring, float>()(), L"%f", val); -} +string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } +string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } +string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); } -wstring to_wstring(double val) -{ - return as_string(get_swprintf(), initial_string<wstring, double>()(), L"%f", val); -} +wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } +wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } +wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); } -wstring to_wstring(long double val) -{ - return as_string(get_swprintf(), initial_string<wstring, long double>()(), L"%Lf", val); -} _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libc++/src/strstream.cpp b/contrib/libc++/src/strstream.cpp index 8b8521f76af1..ae66806833aa 100644 --- a/contrib/libc++/src/strstream.cpp +++ b/contrib/libc++/src/strstream.cpp @@ -1,9 +1,8 @@ //===------------------------ strstream.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_fallback.ipp b/contrib/libc++/src/support/runtime/exception_fallback.ipp index 16d387b99e8c..376a0381f545 100644 --- a/contrib/libc++/src/support/runtime/exception_fallback.ipp +++ b/contrib/libc++/src/support/runtime/exception_fallback.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_glibcxx.ipp b/contrib/libc++/src/support/runtime/exception_glibcxx.ipp index dda4432b508a..4bf3c4d87759 100644 --- a/contrib/libc++/src/support/runtime/exception_glibcxx.ipp +++ b/contrib/libc++/src/support/runtime/exception_glibcxx.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_libcxxabi.ipp b/contrib/libc++/src/support/runtime/exception_libcxxabi.ipp index feefc5152891..6bc049bf382d 100644 --- a/contrib/libc++/src/support/runtime/exception_libcxxabi.ipp +++ b/contrib/libc++/src/support/runtime/exception_libcxxabi.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_libcxxrt.ipp b/contrib/libc++/src/support/runtime/exception_libcxxrt.ipp index 52fe8635db77..0ebffdedba94 100644 --- a/contrib/libc++/src/support/runtime/exception_libcxxrt.ipp +++ b/contrib/libc++/src/support/runtime/exception_libcxxrt.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_msvc.ipp b/contrib/libc++/src/support/runtime/exception_msvc.ipp index 042d3add6c7f..7315b8261b76 100644 --- a/contrib/libc++/src/support/runtime/exception_msvc.ipp +++ b/contrib/libc++/src/support/runtime/exception_msvc.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -83,7 +82,7 @@ int uncaught_exceptions() _NOEXCEPT { return __uncaught_exceptions(); } -#if defined(_LIBCPP_NO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_VCRUNTIME) bad_cast::bad_cast() _NOEXCEPT { } @@ -159,6 +158,6 @@ bad_array_new_length::what() const _NOEXCEPT { return "bad_array_new_length"; } -#endif // _LIBCPP_NO_VCRUNTIME +#endif // !_LIBCPP_ABI_VCRUNTIME } // namespace std diff --git a/contrib/libc++/src/support/runtime/exception_pointer_cxxabi.ipp b/contrib/libc++/src/support/runtime/exception_pointer_cxxabi.ipp index dfac8648c498..82a8e6972fa3 100644 --- a/contrib/libc++/src/support/runtime/exception_pointer_cxxabi.ipp +++ b/contrib/libc++/src/support/runtime/exception_pointer_cxxabi.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_pointer_glibcxx.ipp b/contrib/libc++/src/support/runtime/exception_pointer_glibcxx.ipp index 9d20dfe48622..3abc137c67ba 100644 --- a/contrib/libc++/src/support/runtime/exception_pointer_glibcxx.ipp +++ b/contrib/libc++/src/support/runtime/exception_pointer_glibcxx.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp b/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp index 9b0d2361e402..b1a36952232c 100644 --- a/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp +++ b/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/exception_pointer_unimplemented.ipp b/contrib/libc++/src/support/runtime/exception_pointer_unimplemented.ipp index 21c182c85974..991bca9ecfe3 100644 --- a/contrib/libc++/src/support/runtime/exception_pointer_unimplemented.ipp +++ b/contrib/libc++/src/support/runtime/exception_pointer_unimplemented.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/new_handler_fallback.ipp b/contrib/libc++/src/support/runtime/new_handler_fallback.ipp index ec3f52354ca8..720509394297 100644 --- a/contrib/libc++/src/support/runtime/new_handler_fallback.ipp +++ b/contrib/libc++/src/support/runtime/new_handler_fallback.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/support/runtime/stdexcept_default.ipp b/contrib/libc++/src/support/runtime/stdexcept_default.ipp new file mode 100644 index 000000000000..c827ca4c5130 --- /dev/null +++ b/contrib/libc++/src/support/runtime/stdexcept_default.ipp @@ -0,0 +1,64 @@ +//===--------------------- stdexcept_default.ipp --------------------------===// +// +// 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/refstring.h" + +/* For _LIBCPPABI_VERSION */ +#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ + (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(LIBCXXRT)) +#include <cxxabi.h> +#endif + +static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char*), ""); + +namespace std // purposefully not using versioning namespace +{ + +logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) {} + +logic_error::logic_error(const char* msg) : __imp_(msg) {} + +logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) {} + +logic_error& logic_error::operator=(const logic_error& le) _NOEXCEPT { + __imp_ = le.__imp_; + return *this; +} + +runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) {} + +runtime_error::runtime_error(const char* msg) : __imp_(msg) {} + +runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT + : __imp_(re.__imp_) {} + +runtime_error& runtime_error::operator=(const runtime_error& re) _NOEXCEPT { + __imp_ = re.__imp_; + return *this; +} + +#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) + +const char* logic_error::what() const _NOEXCEPT { return __imp_.c_str(); } + +const char* runtime_error::what() const _NOEXCEPT { return __imp_.c_str(); } + +logic_error::~logic_error() _NOEXCEPT {} +domain_error::~domain_error() _NOEXCEPT {} +invalid_argument::~invalid_argument() _NOEXCEPT {} +length_error::~length_error() _NOEXCEPT {} +out_of_range::~out_of_range() _NOEXCEPT {} + +runtime_error::~runtime_error() _NOEXCEPT {} +range_error::~range_error() _NOEXCEPT {} +overflow_error::~overflow_error() _NOEXCEPT {} +underflow_error::~underflow_error() _NOEXCEPT {} + +#endif + +} // namespace std diff --git a/contrib/libc++/src/support/runtime/stdexcept_vcruntime.ipp b/contrib/libc++/src/support/runtime/stdexcept_vcruntime.ipp new file mode 100644 index 000000000000..94eed465ae97 --- /dev/null +++ b/contrib/libc++/src/support/runtime/stdexcept_vcruntime.ipp @@ -0,0 +1,16 @@ +//===------------------- stdexcept_vcruntime.ipp --------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ABI_VCRUNTIME +#error This file may only be used when defering to vcruntime +#endif + +namespace std { +logic_error::logic_error(std::string const& s) : exception(s.c_str()) {} +runtime_error::runtime_error(std::string const& s) : exception(s.c_str()) {} +} // namespace std diff --git a/contrib/libc++/src/system_error.cpp b/contrib/libc++/src/system_error.cpp index 06caa6fecd9f..9ddf7bcbe030 100644 --- a/contrib/libc++/src/system_error.cpp +++ b/contrib/libc++/src/system_error.cpp @@ -1,9 +1,8 @@ //===---------------------- system_error.cpp ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp index 241cfee23c5b..39bb9e9bac63 100644 --- a/contrib/libc++/src/thread.cpp +++ b/contrib/libc++/src/thread.cpp @@ -1,9 +1,8 @@ //===------------------------- thread.cpp----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -24,9 +23,9 @@ # endif #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__) # include <unistd.h> -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__) #if defined(__NetBSD__) #pragma weak pthread_create // Do not create libpthread dependency @@ -36,6 +35,10 @@ #include <windows.h> #endif +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD thread::~thread() diff --git a/contrib/libc++/src/typeinfo.cpp b/contrib/libc++/src/typeinfo.cpp index 42ff9351ed21..49a07ef7dabe 100644 --- a/contrib/libc++/src/typeinfo.cpp +++ b/contrib/libc++/src/typeinfo.cpp @@ -1,15 +1,14 @@ //===------------------------- typeinfo.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 "typeinfo" -#if defined(_LIBCPP_ABI_MICROSOFT) && defined(_LIBCPP_NO_VCRUNTIME) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_VCRUNTIME) #include <string.h> int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT { @@ -46,11 +45,11 @@ size_t std::type_info::hash_code() const _NOEXCEPT { } #endif // _LIBCPP_ABI_MICROSOFT -// FIXME: Remove __APPLE__ default here once buildit is gone. // FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration. -#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) && \ - !defined(__GLIBCXX__) && !defined(__APPLE__) && \ - !(defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME))) || \ +#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && \ + !defined(LIBCXXRT) && \ + !defined(__GLIBCXX__) && \ + !defined(_LIBCPP_ABI_VCRUNTIME)) || \ defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) std::type_info::~type_info() { diff --git a/contrib/libc++/src/utility.cpp b/contrib/libc++/src/utility.cpp index 7dccffb73e5a..016a5d91b85a 100644 --- a/contrib/libc++/src/utility.cpp +++ b/contrib/libc++/src/utility.cpp @@ -1,9 +1,8 @@ //===------------------------ utility.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/valarray.cpp b/contrib/libc++/src/valarray.cpp index 2d8db52ac36b..7bf0b4175889 100644 --- a/contrib/libc++/src/valarray.cpp +++ b/contrib/libc++/src/valarray.cpp @@ -1,9 +1,8 @@ //===------------------------ valarray.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,8 +10,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD +// These two symbols are part of the v1 ABI but not part of the >=v2 ABI. +#if _LIBCPP_ABI_VERSION == 1 template valarray<size_t>::valarray(size_t); template valarray<size_t>::~valarray(); +#endif + template void valarray<size_t>::resize(size_t, size_t); void diff --git a/contrib/libc++/src/variant.cpp b/contrib/libc++/src/variant.cpp index 5bb508c3f467..1fe70a1809c9 100644 --- a/contrib/libc++/src/variant.cpp +++ b/contrib/libc++/src/variant.cpp @@ -1,9 +1,8 @@ //===------------------------ variant.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// diff --git a/contrib/libc++/src/vector.cpp b/contrib/libc++/src/vector.cpp index 300adaed5f47..3b65e558fd0a 100644 --- a/contrib/libc++/src/vector.cpp +++ b/contrib/libc++/src/vector.cpp @@ -1,9 +1,8 @@ //===------------------------- vector.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// |
