diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b5971036b88..1f8b24d17e24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,6 +352,13 @@ else() endif() file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") +set(LIBCXX_INSTALL_PREFIX "" CACHE STRING + "Define libc++ destination prefix.") + +if (NOT LIBCXX_INSTALL_PREFIX MATCHES "^$|.*/") + message(FATAL_ERROR "LIBCXX_INSTALL_PREFIX has to end with \"/\".") +endif() + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake index b404e36c1480..b1f6bee8f945 100644 --- a/cmake/Modules/HandleLibCXXABI.cmake +++ b/cmake/Modules/HandleLibCXXABI.cmake @@ -55,7 +55,7 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) ) if (LIBCXX_INSTALL_HEADERS) install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" - DESTINATION include/c++/v1/${dstdir} + DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir} COMPONENT libcxx PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) diff --git a/docs/BuildingLibcxx.rst b/docs/BuildingLibcxx.rst index c7b5e96422f0..81a7c2341473 100644 --- a/docs/BuildingLibcxx.rst +++ b/docs/BuildingLibcxx.rst @@ -216,6 +216,11 @@ libc++ specific options Extra suffix to append to the directory where libraries are to be installed. This option overrides `LLVM_LIBDIR_SUFFIX`. +.. option:: LIBCXX_INSTALL_PREFIX:STRING + + **Default**: ``""`` + + Define libc++ destination prefix. .. _libc++experimental options: diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 1c6790ab4652..5a1b2ccdc426 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -20,7 +20,7 @@ endif() if (LIBCXX_INSTALL_HEADERS) install(DIRECTORY . - DESTINATION include/c++/v1 + DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 COMPONENT cxx-headers FILES_MATCHING ${LIBCXX_HEADER_PATTERN} @@ -44,7 +44,7 @@ if (LIBCXX_INSTALL_HEADERS) set(generated_config_deps generate_config_header) # Install the generated header as __config. install(FILES ${LIBCXX_BINARY_DIR}/__generated_config - DESTINATION include/c++/v1 + DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ RENAME __config COMPONENT cxx-headers) diff --git a/include/cmath b/include/cmath index b41f247af59c..917928a1f42f 100644 --- a/include/cmath +++ b/include/cmath @@ -549,7 +549,7 @@ hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isnan) return __builtin_isnan(__lcpp_x); @@ -561,7 +561,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT { return isnan(__lcpp_x); } @@ -569,7 +569,7 @@ __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isinf) return __builtin_isinf(__lcpp_x); @@ -581,7 +581,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT { return isinf(__lcpp_x); } @@ -589,7 +589,7 @@ __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT { #if __has_builtin(__builtin_isfinite) return __builtin_isfinite(__lcpp_x); @@ -601,7 +601,7 @@ __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT template _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR typename enable_if::value, bool>::type -__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT +__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT { return isfinite(__lcpp_x); } diff --git a/include/complex b/include/complex index d41971b3b4db..41a47cfba47c 100644 --- a/include/complex +++ b/include/complex @@ -599,39 +599,39 @@ operator*(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __bc = __b * __c; _Tp __x = __ac - __bd; _Tp __y = __ad + __bc; - if (__libcpp_isnan(__x) && __libcpp_isnan(__y)) + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) { bool __recalc = false; - if (__libcpp_isinf(__a) || __libcpp_isinf(__b)) + if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) { - __a = copysign(__libcpp_isinf(__a) ? _Tp(1) : _Tp(0), __a); - __b = copysign(__libcpp_isinf(__b) ? _Tp(1) : _Tp(0), __b); - if (__libcpp_isnan(__c)) + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); + if (__libcpp_isnan_or_builtin(__c)) __c = copysign(_Tp(0), __c); - if (__libcpp_isnan(__d)) + if (__libcpp_isnan_or_builtin(__d)) __d = copysign(_Tp(0), __d); __recalc = true; } - if (__libcpp_isinf(__c) || __libcpp_isinf(__d)) + if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d)) { - __c = copysign(__libcpp_isinf(__c) ? _Tp(1) : _Tp(0), __c); - __d = copysign(__libcpp_isinf(__d) ? _Tp(1) : _Tp(0), __d); - if (__libcpp_isnan(__a)) + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); + if (__libcpp_isnan_or_builtin(__a)) __a = copysign(_Tp(0), __a); - if (__libcpp_isnan(__b)) + if (__libcpp_isnan_or_builtin(__b)) __b = copysign(_Tp(0), __b); __recalc = true; } - if (!__recalc && (__libcpp_isinf(__ac) || __libcpp_isinf(__bd) || - __libcpp_isinf(__ad) || __libcpp_isinf(__bc))) + if (!__recalc && (__libcpp_isinf_or_builtin(__ac) || __libcpp_isinf_or_builtin(__bd) || + __libcpp_isinf_or_builtin(__ad) || __libcpp_isinf_or_builtin(__bc))) { - if (__libcpp_isnan(__a)) + if (__libcpp_isnan_or_builtin(__a)) __a = copysign(_Tp(0), __a); - if (__libcpp_isnan(__b)) + if (__libcpp_isnan_or_builtin(__b)) __b = copysign(_Tp(0), __b); - if (__libcpp_isnan(__c)) + if (__libcpp_isnan_or_builtin(__c)) __c = copysign(_Tp(0), __c); - if (__libcpp_isnan(__d)) + if (__libcpp_isnan_or_builtin(__d)) __d = copysign(_Tp(0), __d); __recalc = true; } @@ -674,7 +674,7 @@ operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __c = __w.real(); _Tp __d = __w.imag(); _Tp __logbw = logb(fmax(fabs(__c), fabs(__d))); - if (__libcpp_isfinite(__logbw)) + if (__libcpp_isfinite_or_builtin(__logbw)) { __ilogbw = static_cast(__logbw); __c = scalbn(__c, -__ilogbw); @@ -683,24 +683,24 @@ operator/(const complex<_Tp>& __z, const complex<_Tp>& __w) _Tp __denom = __c * __c + __d * __d; _Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw); _Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw); - if (__libcpp_isnan(__x) && __libcpp_isnan(__y)) + if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y)) { - if ((__denom == _Tp(0)) && (!__libcpp_isnan(__a) || !__libcpp_isnan(__b))) + if ((__denom == _Tp(0)) && (!__libcpp_isnan_or_builtin(__a) || !__libcpp_isnan_or_builtin(__b))) { __x = copysign(_Tp(INFINITY), __c) * __a; __y = copysign(_Tp(INFINITY), __c) * __b; } - else if ((__libcpp_isinf(__a) || __libcpp_isinf(__b)) && __libcpp_isfinite(__c) && __libcpp_isfinite(__d)) + else if ((__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) && __libcpp_isfinite_or_builtin(__c) && __libcpp_isfinite_or_builtin(__d)) { - __a = copysign(__libcpp_isinf(__a) ? _Tp(1) : _Tp(0), __a); - __b = copysign(__libcpp_isinf(__b) ? _Tp(1) : _Tp(0), __b); + __a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a); + __b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b); __x = _Tp(INFINITY) * (__a * __c + __b * __d); __y = _Tp(INFINITY) * (__b * __c - __a * __d); } - else if (__libcpp_isinf(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite(__a) && __libcpp_isfinite(__b)) + else if (__libcpp_isinf_or_builtin(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite_or_builtin(__a) && __libcpp_isfinite_or_builtin(__b)) { - __c = copysign(__libcpp_isinf(__c) ? _Tp(1) : _Tp(0), __c); - __d = copysign(__libcpp_isinf(__d) ? _Tp(1) : _Tp(0), __d); + __c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c); + __d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d); __x = _Tp(0) * (__a * __c + __b * __d); __y = _Tp(0) * (__b * __c - __a * __d); } @@ -910,9 +910,9 @@ inline _LIBCPP_INLINE_VISIBILITY _Tp norm(const complex<_Tp>& __c) { - if (__libcpp_isinf(__c.real())) + if (__libcpp_isinf_or_builtin(__c.real())) return abs(__c.real()); - if (__libcpp_isinf(__c.imag())) + if (__libcpp_isinf_or_builtin(__c.imag())) return abs(__c.imag()); return __c.real() * __c.real() + __c.imag() * __c.imag(); } @@ -955,7 +955,7 @@ complex<_Tp> proj(const complex<_Tp>& __c) { std::complex<_Tp> __r = __c; - if (__libcpp_isinf(__c.real()) || __libcpp_isinf(__c.imag())) + if (__libcpp_isinf_or_builtin(__c.real()) || __libcpp_isinf_or_builtin(__c.imag())) __r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag())); return __r; } @@ -969,7 +969,7 @@ typename enable_if >::type proj(_Tp __re) { - if (__libcpp_isinf(__re)) + if (__libcpp_isinf_or_builtin(__re)) __re = abs(__re); return complex<_Tp>(__re); } @@ -993,25 +993,25 @@ template complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta = _Tp(0)) { - if (__libcpp_isnan(__rho) || signbit(__rho)) + if (__libcpp_isnan_or_builtin(__rho) || signbit(__rho)) return complex<_Tp>(_Tp(NAN), _Tp(NAN)); - if (__libcpp_isnan(__theta)) + if (__libcpp_isnan_or_builtin(__theta)) { - if (__libcpp_isinf(__rho)) + if (__libcpp_isinf_or_builtin(__rho)) return complex<_Tp>(__rho, __theta); return complex<_Tp>(__theta, __theta); } - if (__libcpp_isinf(__theta)) + if (__libcpp_isinf_or_builtin(__theta)) { - if (__libcpp_isinf(__rho)) + if (__libcpp_isinf_or_builtin(__rho)) return complex<_Tp>(__rho, _Tp(NAN)); return complex<_Tp>(_Tp(NAN), _Tp(NAN)); } _Tp __x = __rho * cos(__theta); - if (__libcpp_isnan(__x)) + if (__libcpp_isnan_or_builtin(__x)) __x = 0; _Tp __y = __rho * sin(__theta); - if (__libcpp_isnan(__y)) + if (__libcpp_isnan_or_builtin(__y)) __y = 0; return complex<_Tp>(__x, __y); } @@ -1042,13 +1042,13 @@ template complex<_Tp> sqrt(const complex<_Tp>& __x) { - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(_Tp(INFINITY), __x.imag()); - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { if (__x.real() > _Tp(0)) - return complex<_Tp>(__x.real(), __libcpp_isnan(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); - return complex<_Tp>(__libcpp_isnan(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); + return complex<_Tp>(__x.real(), __libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag())); + return complex<_Tp>(__libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag())); } return polar(sqrt(abs(__x)), arg(__x) / _Tp(2)); } @@ -1060,21 +1060,21 @@ complex<_Tp> exp(const complex<_Tp>& __x) { _Tp __i = __x.imag(); - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { if (__x.real() < _Tp(0)) { - if (!__libcpp_isfinite(__i)) + if (!__libcpp_isfinite_or_builtin(__i)) __i = _Tp(1); } - else if (__i == 0 || !__libcpp_isfinite(__i)) + else if (__i == 0 || !__libcpp_isfinite_or_builtin(__i)) { - if (__libcpp_isinf(__i)) + if (__libcpp_isinf_or_builtin(__i)) __i = _Tp(NAN); return complex<_Tp>(__x.real(), __i); } } - else if (__libcpp_isnan(__x.real()) && __x.imag() == 0) + else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) return __x; _Tp __e = exp(__x.real()); return complex<_Tp>(__e * cos(__i), __e * sin(__i)); @@ -1132,23 +1132,23 @@ complex<_Tp> asinh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (__libcpp_isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return __x; - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); } - if (__libcpp_isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.imag(), __x.real()); if (__x.imag() == 0) return __x; return complex<_Tp>(__x.real(), __x.real()); } - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag())); complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) + _Tp(1))); return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag())); @@ -1161,11 +1161,11 @@ complex<_Tp> acosh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (__libcpp_isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.real()), __x.imag()); - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { if (__x.real() > 0) return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag())); @@ -1176,13 +1176,13 @@ acosh(const complex<_Tp>& __x) return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag())); return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag())); } - if (__libcpp_isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.imag()), __x.real()); return complex<_Tp>(__x.real(), __x.real()); } - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag())); complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1))); return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag())); @@ -1195,21 +1195,21 @@ complex<_Tp> atanh(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); } - if (__libcpp_isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) { - if (__libcpp_isinf(__x.real()) || __x.real() == 0) + if (__libcpp_isinf_or_builtin(__x.real()) || __x.real() == 0) return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag()); return complex<_Tp>(__x.imag(), __x.imag()); } - if (__libcpp_isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { return complex<_Tp>(__x.real(), __x.real()); } - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag())); } @@ -1227,11 +1227,11 @@ template complex<_Tp> sinh(const complex<_Tp>& __x) { - if (__libcpp_isinf(__x.real()) && !__libcpp_isfinite(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), _Tp(NAN)); - if (__x.real() == 0 && !__libcpp_isfinite(__x.imag())) + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), _Tp(NAN)); - if (__x.imag() == 0 && !__libcpp_isfinite(__x.real())) + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) return __x; return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag())); } @@ -1242,13 +1242,13 @@ template complex<_Tp> cosh(const complex<_Tp>& __x) { - if (__libcpp_isinf(__x.real()) && !__libcpp_isfinite(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(abs(__x.real()), _Tp(NAN)); - if (__x.real() == 0 && !__libcpp_isfinite(__x.imag())) + if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(_Tp(NAN), __x.real()); if (__x.real() == 0 && __x.imag() == 0) return complex<_Tp>(_Tp(1), __x.imag()); - if (__x.imag() == 0 && !__libcpp_isfinite(__x.real())) + if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real())) return complex<_Tp>(abs(__x.real()), __x.imag()); return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag())); } @@ -1259,19 +1259,19 @@ template complex<_Tp> tanh(const complex<_Tp>& __x) { - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (!__libcpp_isfinite(__x.imag())) + if (!__libcpp_isfinite_or_builtin(__x.imag())) return complex<_Tp>(_Tp(1), _Tp(0)); return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag()))); } - if (__libcpp_isnan(__x.real()) && __x.imag() == 0) + if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0) return __x; _Tp __2r(_Tp(2) * __x.real()); _Tp __2i(_Tp(2) * __x.imag()); _Tp __d(cosh(__2r) + cos(__2i)); _Tp __2rsh(sinh(__2r)); - if (__libcpp_isinf(__2rsh) && __libcpp_isinf(__d)) + if (__libcpp_isinf_or_builtin(__2rsh) && __libcpp_isinf_or_builtin(__d)) return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1), __2i > _Tp(0) ? _Tp(0) : _Tp(-0.)); return complex<_Tp>(__2rsh/__d, sin(__2i)/__d); @@ -1294,11 +1294,11 @@ complex<_Tp> acos(const complex<_Tp>& __x) { const _Tp __pi(atan2(+0., -0.)); - if (__libcpp_isinf(__x.real())) + if (__libcpp_isinf_or_builtin(__x.real())) { - if (__libcpp_isnan(__x.imag())) + if (__libcpp_isnan_or_builtin(__x.imag())) return complex<_Tp>(__x.imag(), __x.real()); - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) { if (__x.real() < _Tp(0)) return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag()); @@ -1308,13 +1308,13 @@ acos(const complex<_Tp>& __x) return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real()); return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real()); } - if (__libcpp_isnan(__x.real())) + if (__libcpp_isnan_or_builtin(__x.real())) { - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__x.real(), -__x.imag()); return complex<_Tp>(__x.real(), __x.real()); } - if (__libcpp_isinf(__x.imag())) + if (__libcpp_isinf_or_builtin(__x.imag())) return complex<_Tp>(__pi/_Tp(2), -__x.imag()); if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag()))) return complex<_Tp>(__pi/_Tp(2), -__x.imag()); diff --git a/include/optional b/include/optional index c0fd0e7bc49f..1fb953bab743 100644 --- a/include/optional +++ b/include/optional @@ -439,46 +439,122 @@ struct __optional_storage_base<_Tp, true> } }; -template ::value> -struct __optional_storage; - -template -struct __optional_storage<_Tp, true> : __optional_storage_base<_Tp> +template ::value> +struct __optional_copy_base : __optional_storage_base<_Tp> { using __optional_storage_base<_Tp>::__optional_storage_base; }; template -struct __optional_storage<_Tp, false> : __optional_storage_base<_Tp> +struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp> { - using value_type = _Tp; using __optional_storage_base<_Tp>::__optional_storage_base; _LIBCPP_INLINE_VISIBILITY - __optional_storage() = default; + __optional_copy_base() = default; _LIBCPP_INLINE_VISIBILITY - __optional_storage(const __optional_storage& __opt) + __optional_copy_base(const __optional_copy_base& __opt) { this->__construct_from(__opt); } _LIBCPP_INLINE_VISIBILITY - __optional_storage(__optional_storage&& __opt) + __optional_copy_base(__optional_copy_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(const __optional_copy_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_base& operator=(__optional_copy_base&&) = default; +}; + +template ::value> +struct __optional_move_base : __optional_copy_base<_Tp> +{ + using __optional_copy_base<_Tp>::__optional_copy_base; +}; + +template +struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_base<_Tp>::__optional_copy_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(const __optional_move_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_base(__optional_move_base&& __opt) noexcept(is_nothrow_move_constructible_v) { this->__construct_from(_VSTD::move(__opt)); } _LIBCPP_INLINE_VISIBILITY - __optional_storage& operator=(const __optional_storage& __opt) + __optional_move_base& operator=(const __optional_move_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_base& operator=(__optional_move_base&&) = default; +}; + +template ::value && + is_trivially_copy_constructible<_Tp>::value && + is_trivially_copy_assignable<_Tp>::value> +struct __optional_copy_assign_base : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; +}; + +template +struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp> +{ + using __optional_move_base<_Tp>::__optional_move_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(const __optional_copy_assign_base&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base(__optional_copy_assign_base&&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt) { this->__assign_from(__opt); return *this; } _LIBCPP_INLINE_VISIBILITY - __optional_storage& operator=(__optional_storage&& __opt) + __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; +}; + +template ::value && + is_trivially_move_constructible<_Tp>::value && + is_trivially_move_assignable<_Tp>::value> +struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> +{ + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; +}; + +template +struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp> +{ + using value_type = _Tp; + using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base() = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base(__optional_move_assign_base&&) = default; + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; + + _LIBCPP_INLINE_VISIBILITY + __optional_move_assign_base& operator=(__optional_move_assign_base&& __opt) noexcept(is_nothrow_move_assignable_v && is_nothrow_move_constructible_v) { @@ -501,11 +577,11 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base< template class optional - : private __optional_storage<_Tp> + : private __optional_move_assign_base<_Tp> , private __optional_sfinae_ctor_base_t<_Tp> , private __optional_sfinae_assign_base_t<_Tp> { - using __base = __optional_storage<_Tp>; + using __base = __optional_move_assign_base<_Tp>; public: using value_type = _Tp; diff --git a/include/regex b/include/regex index 443c2e303465..77ca648109b2 100644 --- a/include/regex +++ b/include/regex @@ -6142,7 +6142,7 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() { __flags_ |= regex_constants::__no_update_pos; _BidirectionalIterator __start = __match_[0].second; - if (__match_.empty()) + if (__match_[0].first == __match_[0].second) { if (__start == __end_) { diff --git a/include/string b/include/string index d1a3a1f8e6cc..010a4c7816ea 100644 --- a/include/string +++ b/include/string @@ -676,11 +676,11 @@ private: }; #if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? @@ -706,11 +706,11 @@ private: }; #if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f04ef82a83d6..9fc0d1394336 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -355,8 +355,8 @@ if (LIBCXX_INSTALL_LIBRARY) set(experimental_lib cxx_experimental) endif() install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib} - LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx - ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ) # NOTE: This install command must go after the cxx install command otherwise # it will not be executed after the library symlinks are installed. @@ -364,7 +364,7 @@ if (LIBCXX_INSTALL_LIBRARY) # Replace the libc++ filename with $ # after we required CMake 3.0. install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" - DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} + DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx) endif() endif() diff --git a/src/experimental/filesystem/filesystem_time_helper.h b/src/experimental/filesystem/filesystem_time_helper.h new file mode 100644 index 000000000000..a60fdef5f0d9 --- /dev/null +++ b/src/experimental/filesystem/filesystem_time_helper.h @@ -0,0 +1,173 @@ +//===----------------------------------------------------------------------===//// +// +// 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. +// +//===----------------------------------------------------------------------===//// + +#ifndef FILESYSTEM_TIME_HELPER_H +#define FILESYSTEM_TIME_HELPER_H + +#include "experimental/__config" +#include "chrono" +#include "cstdlib" +#include "climits" + +#include +#include +#if !defined(UTIME_OMIT) +#include // for ::utimes as used in __last_write_time +#endif + +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM + +namespace time_detail { namespace { + +using namespace chrono; + +template ::value> +struct fs_time_util_base { + static constexpr auto max_seconds = + duration_cast(FileTimeT::duration::max()).count(); + + static constexpr auto max_nsec = + duration_cast(FileTimeT::duration::max() - + seconds(max_seconds)) + .count(); + + static constexpr auto min_seconds = + duration_cast(FileTimeT::duration::min()).count(); + + static constexpr auto min_nsec_timespec = + duration_cast( + (FileTimeT::duration::min() - seconds(min_seconds)) + seconds(1)) + .count(); + + // Static assert that these values properly round trip. + static_assert((seconds(min_seconds) + + duration_cast(nanoseconds(min_nsec_timespec))) - + duration_cast(seconds(1)) == + FileTimeT::duration::min(), + ""); +}; + +template +struct fs_time_util_base { + static const long long max_seconds; + static const long long max_nsec; + static const long long min_seconds; + static const long long min_nsec_timespec; +}; + +template +const long long fs_time_util_base::max_seconds = + duration_cast(FileTimeT::duration::max()).count(); + +template +const long long fs_time_util_base::max_nsec = + duration_cast(FileTimeT::duration::max() - + seconds(max_seconds)) + .count(); + +template +const long long fs_time_util_base::min_seconds = + duration_cast(FileTimeT::duration::min()).count(); + +template +const long long fs_time_util_base::min_nsec_timespec = + duration_cast((FileTimeT::duration::min() - + seconds(min_seconds)) + + seconds(1)) + .count(); + +template +struct fs_time_util : fs_time_util_base { + using Base = fs_time_util_base; + using Base::max_nsec; + using Base::max_seconds; + using Base::min_nsec_timespec; + using Base::min_seconds; + +public: + template + static bool checked_set(CType* out, ChronoType time) { + using Lim = numeric_limits; + if (time > Lim::max() || time < Lim::min()) + return false; + *out = static_cast(time); + return true; + } + + static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(TimeSpecT tm) { + if (tm.tv_sec >= 0) { + return (tm.tv_sec < max_seconds) || + (tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec); + } else if (tm.tv_sec == (min_seconds - 1)) { + return tm.tv_nsec >= min_nsec_timespec; + } else { + return (tm.tv_sec >= min_seconds); + } + } + + static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(FileTimeT tm) { + auto secs = duration_cast(tm.time_since_epoch()); + auto nsecs = duration_cast(tm.time_since_epoch() - secs); + if (nsecs.count() < 0) { + secs = secs + seconds(1); + nsecs = nsecs + seconds(1); + } + using TLim = numeric_limits; + if (secs.count() >= 0) + return secs.count() <= TLim::max(); + return secs.count() >= TLim::min(); + } + + static _LIBCPP_CONSTEXPR_AFTER_CXX11 FileTimeT + convert_timespec(TimeSpecT tm) { + auto adj_msec = duration_cast(nanoseconds(tm.tv_nsec)); + if (tm.tv_sec >= 0) { + auto Dur = seconds(tm.tv_sec) + microseconds(adj_msec); + return FileTimeT(Dur); + } else if (duration_cast(nanoseconds(tm.tv_nsec)).count() == + 0) { + return FileTimeT(seconds(tm.tv_sec)); + } else { // tm.tv_sec < 0 + auto adj_subsec = + duration_cast(seconds(1) - nanoseconds(tm.tv_nsec)); + auto Dur = seconds(tm.tv_sec + 1) - adj_subsec; + return FileTimeT(Dur); + } + } + + template + static bool set_times_checked(TimeT* sec_out, SubSecT* subsec_out, + FileTimeT tp) { + using namespace chrono; + auto dur = tp.time_since_epoch(); + auto sec_dur = duration_cast(dur); + auto subsec_dur = duration_cast(dur - sec_dur); + // The tv_nsec and tv_usec fields must not be negative so adjust accordingly + if (subsec_dur.count() < 0) { + if (sec_dur.count() > min_seconds) { + sec_dur -= seconds(1); + subsec_dur += seconds(1); + } else { + subsec_dur = SubSecDurT::zero(); + } + } + return checked_set(sec_out, sec_dur.count()) && + checked_set(subsec_out, subsec_dur.count()); + } +}; + +} // end namespace +} // end namespace time_detail + +using time_detail::fs_time_util; + +_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM + +#endif // FILESYSTEM_TIME_HELPER_H diff --git a/src/experimental/filesystem/operations.cpp b/src/experimental/filesystem/operations.cpp index e9bc0eb6e30e..641a3c53636d 100644 --- a/src/experimental/filesystem/operations.cpp +++ b/src/experimental/filesystem/operations.cpp @@ -15,6 +15,8 @@ #include "cstdlib" #include "climits" +#include "filesystem_time_helper.h" + #include #include #include @@ -426,17 +428,20 @@ void __current_path(const path& p, std::error_code *ec) { bool __equivalent(const path& p1, const path& p2, std::error_code *ec) { + auto make_unsupported_error = [&]() { + set_or_throw(make_error_code(errc::not_supported), ec, + "equivalent", p1, p2); + return false; + }; std::error_code ec1, ec2; struct ::stat st1 = {}; struct ::stat st2 = {}; auto s1 = detail::posix_stat(p1.native(), st1, &ec1); + if (!exists(s1)) + return make_unsupported_error(); auto s2 = detail::posix_stat(p2.native(), st2, &ec2); - - if ((!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))) { - set_or_throw(make_error_code(errc::not_supported), ec, - "equivalent", p1, p2); - return false; - } + if (!exists(s2)) + return make_unsupported_error(); if (ec) ec->clear(); return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino); } @@ -502,17 +507,6 @@ bool __fs_is_empty(const path& p, std::error_code *ec) namespace detail { namespace { -using namespace std::chrono; - -template -bool checked_set(CType* out, ChronoType time) { - using Lim = numeric_limits; - if (time > Lim::max() || time < Lim::min()) - return false; - *out = static_cast(time); - return true; -} - using TimeSpec = struct timespec; using StatT = struct stat; @@ -525,137 +519,10 @@ __attribute__((unused)) // Suppress warning TimeSpec extract_atime(StatT const& st) { return st.st_atim; } #endif -constexpr auto max_seconds = duration_cast( - file_time_type::duration::max()).count(); - -constexpr auto max_nsec = duration_cast( - file_time_type::duration::max() - seconds(max_seconds)).count(); - -constexpr auto min_seconds = duration_cast( - file_time_type::duration::min()).count(); - -constexpr auto min_nsec_timespec = duration_cast( - (file_time_type::duration::min() - seconds(min_seconds)) + seconds(1)).count(); - -// Static assert that these values properly round trip. -static_assert((seconds(min_seconds) + duration_cast(nanoseconds(min_nsec_timespec))) - - duration_cast(seconds(1)) - == file_time_type::duration::min(), ""); - -constexpr auto max_time_t = numeric_limits::max(); -constexpr auto min_time_t = numeric_limits::min(); - -#if !defined(__LP64__) && defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" -#endif - -_LIBCPP_CONSTEXPR_AFTER_CXX11 -bool is_representable(TimeSpec const& tm) { - if (tm.tv_sec >= 0) { - return (tm.tv_sec < max_seconds) || - (tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec); - } else if (tm.tv_sec == (min_seconds - 1)) { - return tm.tv_nsec >= min_nsec_timespec; - } else { - return (tm.tv_sec >= min_seconds); - } -} -#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR -#if defined(__LP64__) -static_assert(is_representable({max_seconds, max_nsec}), ""); -static_assert(!is_representable({max_seconds + 1, 0}), ""); -static_assert(!is_representable({max_seconds, max_nsec + 1}), ""); -static_assert(!is_representable({max_time_t, 0}), ""); -static_assert(is_representable({min_seconds, 0}), ""); -static_assert(is_representable({min_seconds - 1, min_nsec_timespec}), ""); -static_assert(is_representable({min_seconds - 1, min_nsec_timespec + 1}), ""); -static_assert(!is_representable({min_seconds - 1, min_nsec_timespec - 1}), ""); -static_assert(!is_representable({min_time_t, 999999999}), ""); -#else -static_assert(is_representable({max_time_t, 999999999}), ""); -static_assert(is_representable({max_time_t, 1000000000}), ""); -static_assert(is_representable({min_time_t, 0}), ""); -#endif -#endif - -_LIBCPP_CONSTEXPR_AFTER_CXX11 -bool is_representable(file_time_type const& tm) { - auto secs = duration_cast(tm.time_since_epoch()); - auto nsecs = duration_cast(tm.time_since_epoch() - secs); - if (nsecs.count() < 0) { - secs = secs + seconds(1); - nsecs = nsecs + seconds(1); - } - using TLim = numeric_limits; - if (secs.count() >= 0) - return secs.count() <= TLim::max(); - return secs.count() >= TLim::min(); -} -#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR -#if defined(__LP64__) -static_assert(is_representable(file_time_type::max()), ""); -static_assert(is_representable(file_time_type::min()), ""); -#else -static_assert(!is_representable(file_time_type::max()), ""); -static_assert(!is_representable(file_time_type::min()), ""); -static_assert(is_representable(file_time_type(seconds(max_time_t))), ""); -static_assert(is_representable(file_time_type(seconds(min_time_t))), ""); -#endif -#endif - -_LIBCPP_CONSTEXPR_AFTER_CXX11 -file_time_type convert_timespec(TimeSpec const& tm) { - auto adj_msec = duration_cast(nanoseconds(tm.tv_nsec)); - if (tm.tv_sec >= 0) { - auto Dur = seconds(tm.tv_sec) + microseconds(adj_msec); - return file_time_type(Dur); - } else if (duration_cast(nanoseconds(tm.tv_nsec)).count() == 0) { - return file_time_type(seconds(tm.tv_sec)); - } else { // tm.tv_sec < 0 - auto adj_subsec = duration_cast(seconds(1) - nanoseconds(tm.tv_nsec)); - auto Dur = seconds(tm.tv_sec + 1) - adj_subsec; - return file_time_type(Dur); - } -} -#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR -#if defined(__LP64__) -static_assert(convert_timespec({max_seconds, max_nsec}) == file_time_type::max(), ""); -static_assert(convert_timespec({max_seconds, max_nsec - 1}) < file_time_type::max(), ""); -static_assert(convert_timespec({max_seconds - 1, 999999999}) < file_time_type::max(), ""); -static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec}) == file_time_type::min(), ""); -static_assert(convert_timespec({min_seconds - 1, min_nsec_timespec + 1}) > file_time_type::min(), ""); -static_assert(convert_timespec({min_seconds , 0}) > file_time_type::min(), ""); -#else -// FIXME add tests for 32 bit builds -#endif -#endif - -#if !defined(__LP64__) && defined(__clang__) -#pragma clang diagnostic pop -#endif - -template -bool set_times_checked(time_t* sec_out, SubSecT* subsec_out, file_time_type tp) { - using namespace chrono; - auto dur = tp.time_since_epoch(); - auto sec_dur = duration_cast(dur); - auto subsec_dur = duration_cast(dur - sec_dur); - // The tv_nsec and tv_usec fields must not be negative so adjust accordingly - if (subsec_dur.count() < 0) { - if (sec_dur.count() > min_seconds) { - sec_dur -= seconds(1); - subsec_dur += seconds(1); - } else { - subsec_dur = SubSecDurT::zero(); - } - } - return checked_set(sec_out, sec_dur.count()) - && checked_set(subsec_out, subsec_dur.count()); -} - }} // end namespace detail +using FSTime = fs_time_util; + file_time_type __last_write_time(const path& p, std::error_code *ec) { using namespace ::std::chrono; @@ -668,12 +535,12 @@ file_time_type __last_write_time(const path& p, std::error_code *ec) } if (ec) ec->clear(); auto ts = detail::extract_mtime(st); - if (!detail::is_representable(ts)) { + if (!FSTime::is_representable(ts)) { set_or_throw(error_code(EOVERFLOW, generic_category()), ec, "last_write_time", p); return file_time_type::min(); } - return detail::convert_timespec(ts); + return FSTime::convert_timespec(ts); } void __last_write_time(const path& p, file_time_type new_time, @@ -698,7 +565,7 @@ void __last_write_time(const path& p, file_time_type new_time, struct ::timeval tbuf[2]; tbuf[0].tv_sec = atime.tv_sec; tbuf[0].tv_usec = duration_cast(nanoseconds(atime.tv_nsec)).count(); - const bool overflowed = !detail::set_times_checked( + const bool overflowed = !FSTime::set_times_checked( &tbuf[1].tv_sec, &tbuf[1].tv_usec, new_time); if (overflowed) { @@ -714,7 +581,7 @@ void __last_write_time(const path& p, file_time_type new_time, tbuf[0].tv_sec = 0; tbuf[0].tv_nsec = UTIME_OMIT; - const bool overflowed = !detail::set_times_checked( + const bool overflowed = !FSTime::set_times_checked( &tbuf[1].tv_sec, &tbuf[1].tv_nsec, new_time); if (overflowed) { set_or_throw(make_error_code(errc::invalid_argument), diff --git a/include/__refstring b/src/include/refstring.h similarity index 97% rename from include/__refstring rename to src/include/refstring.h index 7f417a03c491..f0d5b4456da5 100644 --- a/include/__refstring +++ b/src/include/refstring.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___REFSTRING -#define _LIBCPP___REFSTRING +#ifndef _LIBCPP_REFSTRING_H +#define _LIBCPP_REFSTRING_H #include <__config> #include @@ -124,4 +124,4 @@ bool __libcpp_refstring::__uses_refcount() const { _LIBCPP_END_NAMESPACE_STD -#endif //_LIBCPP___REFSTRING +#endif //_LIBCPP_REFSTRING_H diff --git a/src/stdexcept.cpp b/src/stdexcept.cpp index 3f333309dd8f..5e06e521e404 100644 --- a/src/stdexcept.cpp +++ b/src/stdexcept.cpp @@ -11,7 +11,7 @@ #include "new" #include "string" #include "system_error" -#include "__refstring" +#include "include/refstring.h" /* For _LIBCPPABI_VERSION */ #if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f2eac0546fc..7b8a8322a11f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -85,3 +85,36 @@ if (LIBCXX_GENERATE_COVERAGE) set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src") setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}") endif() + + +if (LIBCXX_CONFIGURE_IDE) + # Create dummy targets for each of the tests in the test suite, this allows + # IDE's such as CLion to correctly highlight the tests because it knows + # roughly what include paths/compile flags/macro definitions are needed. + include_directories(support) + file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp) + file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*) + file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) + add_executable(libcxx_test_objects EXCLUDE_FROM_ALL + ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS}) + add_dependencies(libcxx_test_objects cxx) + + set(STATIC_ROOT ${LIBCXX_SOURCE_DIR}/test/std/experimental/filesystem/Inputs/static_test_env) + add_definitions(-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="${STATIC_ROOT}") + + set(DYNAMIC_ROOT ${LIBCXX_BINARY_DIR}/test/filesystem/Output/dynamic_env) + add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="${DYNAMIC_ROOT}") + + set(DYNAMIC_HELPER "python ${LIBCXX_SOURCE_DIR}/test/support/filesystem_dynamic_test_helper.py ") + add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="${DYNAMIC_HELPER}") + + split_list(LIBCXX_COMPILE_FLAGS) + split_list(LIBCXX_LINK_FLAGS) + + set_target_properties(libcxx_test_objects + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + EXCLUDE_FROM_ALL ON + ) +endif() diff --git a/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp b/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp index 9c6cad8ee2d3..4009841355f9 100644 --- a/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp +++ b/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp @@ -16,7 +16,7 @@ // UNSUPPORTED: c++98, c++03, c++11 // The sanitizers replace new/delete with versions that do not throw bad_alloc. -// UNSUPPORTED: sanitizer-new-delete, ubsan +// UNSUPPORTED: sanitizer-new-delete #include diff --git a/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp b/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp new file mode 100644 index 000000000000..972d51813961 --- /dev/null +++ b/test/libcxx/experimental/filesystem/convert_file_time.sh.cpp @@ -0,0 +1,200 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11 + +// + +// typedef TrivialClock file_time_type; + +// RUN: %build -I%libcxx_src_root/src/experimental/filesystem +// RUN: %run + +#include +#include +#include +#include +#include +#include + +#include "filesystem_time_helper.h" + +using namespace std::chrono; +namespace fs = std::experimental::filesystem; +using fs::file_time_type; +using fs::fs_time_util; + +enum TestKind { TK_64Bit, TK_32Bit, TK_FloatingPoint }; + +template +constexpr TestKind getTestKind() { + if (sizeof(TimeT) == 8 && !std::is_floating_point::value) + return TK_64Bit; + else if (sizeof(TimeT) == 4 && !std::is_floating_point::value) + return TK_32Bit; + else if (std::is_floating_point::value) + return TK_FloatingPoint; + else + assert(false && "test kind not supported"); +} + +template , + TestKind = getTestKind()> +struct check_is_representable; + +template +struct check_is_representable + : public Base { + + using Base::convert_timespec; + using Base::is_representable; + using Base::max_nsec; + using Base::max_seconds; + using Base::min_nsec_timespec; + using Base::min_seconds; + + static constexpr auto max_time_t = std::numeric_limits::max(); + static constexpr auto min_time_t = std::numeric_limits::min(); + + static constexpr bool test_timespec() { + static_assert(is_representable(TimeSpecT{max_seconds, max_nsec}), ""); + static_assert(!is_representable(TimeSpecT{max_seconds + 1, 0}), ""); + static_assert(!is_representable(TimeSpecT{max_seconds, max_nsec + 1}), ""); + static_assert(!is_representable(TimeSpecT{max_time_t, 0}), ""); + static_assert(is_representable(TimeSpecT{min_seconds, 0}), ""); + static_assert( + is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec}), ""); + static_assert( + is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}), + ""); + static_assert( + !is_representable(TimeSpecT{min_seconds - 1, min_nsec_timespec - 1}), + ""); + static_assert(!is_representable(TimeSpecT{min_time_t, 999999999}), ""); + return true; + } + + static constexpr bool test_file_time_type() { + static_assert(Base::is_representable(FileTimeT::max()), ""); + static_assert(Base::is_representable(FileTimeT::min()), ""); + return true; + } + + static constexpr bool test_convert_timespec() { + static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec}) == + FileTimeT::max(), + ""); + static_assert(convert_timespec(TimeSpecT{max_seconds, max_nsec - 1}) < + FileTimeT::max(), + ""); + static_assert(convert_timespec(TimeSpecT{max_seconds - 1, 999999999}) < + FileTimeT::max(), + ""); + static_assert(convert_timespec(TimeSpecT{ + min_seconds - 1, min_nsec_timespec}) == FileTimeT::min(), + ""); + static_assert( + convert_timespec(TimeSpecT{min_seconds - 1, min_nsec_timespec + 1}) > + FileTimeT::min(), + ""); + static_assert( + convert_timespec(TimeSpecT{min_seconds, 0}) > FileTimeT::min(), ""); + return true; + } + + static bool test() { + static_assert(test_timespec(), ""); + static_assert(test_file_time_type(), ""); + static_assert(test_convert_timespec(), ""); + return true; + } +}; + +template +struct check_is_representable + : public Base { + static constexpr auto max_time_t = std::numeric_limits::max(); + static constexpr auto min_time_t = std::numeric_limits::min(); + + using Base::convert_timespec; + using Base::is_representable; + using Base::max_nsec; + using Base::max_seconds; + using Base::min_nsec_timespec; + using Base::min_seconds; + + static constexpr bool test_timespec() { + static_assert(is_representable(TimeSpecT{max_time_t, 999999999}), ""); + static_assert(is_representable(TimeSpecT{max_time_t, 1000000000}), ""); + static_assert(is_representable(TimeSpecT{min_time_t, 0}), ""); + return true; + } + + static constexpr bool test_file_time_type() { + static_assert(!is_representable(FileTimeT::max()), ""); + static_assert(!is_representable(FileTimeT::min()), ""); + static_assert(is_representable(FileTimeT(seconds(max_time_t))), ""); + static_assert(is_representable(FileTimeT(seconds(min_time_t))), ""); + return true; + } + + static constexpr bool test_convert_timespec() { + // FIXME add tests for 32 bit builds + return true; + } + + static bool test() { + static_assert(test_timespec(), ""); + static_assert(test_file_time_type(), ""); + static_assert(test_convert_timespec(), ""); + return true; + } +}; + +template +struct check_is_representable : public Base { + + static bool test() { return true; } +}; + +template +struct TestTimeSpec { + TimeT tv_sec; + NSecT tv_nsec; +}; + +template +struct TestClock { + typedef Dur duration; + typedef typename duration::rep rep; + typedef typename duration::period period; + typedef std::chrono::time_point time_point; + static constexpr const bool is_steady = false; + + static time_point now() noexcept { return {}; } +}; + +template > +using TestFileTimeT = time_point >; + +int main() { + assert(( + check_is_representable::test())); + assert((check_is_representable, int64_t, + TestTimeSpec >::test())); + assert((check_is_representable, int32_t, + TestTimeSpec >::test())); + + // Test that insane platforms like ppc64 linux, which use long double as time_t, + // at least compile. + assert((check_is_representable, double, + TestTimeSpec >::test())); +} diff --git a/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp b/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp index 9123be1f0990..a58c389cd7ac 100644 --- a/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp +++ b/test/libcxx/numerics/c.math/constexpr-fns.pass.cpp @@ -23,9 +23,9 @@ #include -static_assert(std::__libcpp_isnan(0.) == false, ""); -static_assert(std::__libcpp_isinf(0.0) == false, ""); -static_assert(std::__libcpp_isfinite(0.0) == true, ""); +static_assert(std::__libcpp_isnan_or_builtin(0.) == false, ""); +static_assert(std::__libcpp_isinf_or_builtin(0.0) == false, ""); +static_assert(std::__libcpp_isfinite_or_builtin(0.0) == true, ""); int main() { diff --git a/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp b/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp new file mode 100644 index 000000000000..37aaa2acf1d9 --- /dev/null +++ b/test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// test that cmath builds with -fdelayed-template-parsing + +// REQUIRES: fdelayed-template-parsing + +// RUN: %build -fdelayed-template-parsing +// RUN: %run + +#include +#include + +#include "test_macros.h" + +int main() { + assert(std::isfinite(1.0)); + assert(!std::isinf(1.0)); + assert(!std::isnan(1.0)); +} + +using namespace std; diff --git a/test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp b/test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp deleted file mode 100644 index 9493d6bb766c..000000000000 --- a/test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp +++ /dev/null @@ -1,66 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++98, c++03, c++11, c++14 -// - - -#include -#include -#include - -#include "archetypes.hpp" - -template -struct SpecialMemberTest { - using O = std::optional; - - template