From 080f06df5416fa8f6efdf413ff1239d33b5d5310 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 20 Mar 2019 21:18:14 +0000 Subject: [PATCH] [libc++] Mark as unavailable on Apple platforms using pragmas Summary: Also add the corresponding XFAILs to tests that require filesystem. The approach taken to mark as unavailable in this patch is to mark all the header as unavailable using #pragma clang attribute. Marking each declaration using the attribute is more intrusive and does not provide a lot of value right now because pretty much everything in requires dylib support, often transitively. This is an alternative to https://reviews.llvm.org/D59093. A similar (but partial) patch was already applied in r356558. Reviewers: mclow.lists, EricWF, serge-sans-paille Subscribers: christof, jkorous, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D59224 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@356616 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 15 ++++++++++++++- include/chrono | 2 +- include/filesystem | 12 +++++++++++- .../time.clock.file/consistency.pass.cpp | 2 ++ .../time.clock/time.clock.file/file_time.pass.cpp | 1 + .../time.clock.file/rep_signed.pass.cpp | 1 + 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/__config b/include/__config index c9c634dc1..b94237036 100644 --- a/include/__config +++ b/include/__config @@ -1311,7 +1311,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #if !defined(_LIBCPP_BUILDING_LIBRARY) && \ !defined(_LIBCPP_DISABLE_AVAILABILITY) && \ __has_feature(attribute_availability_with_strict) && \ - __has_feature(attribute_availability_in_templates) + __has_feature(attribute_availability_in_templates) && \ + __has_extension(pragma_clang_attribute_external_declaration) # ifdef __APPLE__ # define _LIBCPP_USE_AVAILABILITY_APPLE # endif @@ -1359,6 +1360,16 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( __attribute__((availability(ios,strict,unavailable))) \ __attribute__((availability(tvos,strict,unavailable))) \ __attribute__((availability(watchos,strict,unavailable))) +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \ + _Pragma("clang attribute push(__attribute__((availability(macosx,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(ios,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(tvos,strict,unavailable))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(watchos,strict,unavailable))), apply_to=any(function,record))") +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") #else # define _LIBCPP_AVAILABILITY_SHARED_MUTEX # define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS @@ -1371,6 +1382,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY # define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR # define _LIBCPP_AVAILABILITY_FILESYSTEM +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP #endif // Define availability that depends on _LIBCPP_NO_EXCEPTIONS. diff --git a/include/chrono b/include/chrono index a003751ba..b70aded70 100644 --- a/include/chrono +++ b/include/chrono @@ -2841,7 +2841,7 @@ struct _FilesystemClock { static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; - _LIBCPP_FUNC_VIS static time_point now() noexcept; + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; _LIBCPP_INLINE_VISIBILITY static time_t to_time_t(const time_point& __t) noexcept { diff --git a/include/filesystem b/include/filesystem index d599b5403..3aaa7988a 100644 --- a/include/filesystem +++ b/include/filesystem @@ -258,6 +258,8 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + typedef chrono::time_point<_FilesystemClock> file_time_type; struct _LIBCPP_TYPE_VIS space_info { @@ -1310,7 +1312,11 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs, return !(__lhs == __rhs); } -class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { +// TODO(ldionne): We need to pop the pragma and push it again after +// filesystem_error to work around PR41078. +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { public: _LIBCPP_INLINE_VISIBILITY filesystem_error(const string& __what, error_code __ec) @@ -1361,6 +1367,8 @@ private: shared_ptr<_Storage> __storage_; }; +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + template _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY #ifndef _LIBCPP_NO_EXCEPTIONS @@ -2624,6 +2632,8 @@ end(const recursive_directory_iterator&) noexcept { return recursive_directory_iterator(); } +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // !_LIBCPP_CXX03_LANG diff --git a/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp index 34244a871..2bc53a292 100644 --- a/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp @@ -12,6 +12,8 @@ // violation because Clock::is_steady is defined in both the dylib and this TU. // UNSUPPORTED: asan +// XFAIL: dylib-has-no-filesystem + // // file_clock diff --git a/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp index 61d92381f..07c5aa66e 100644 --- a/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// XFAIL: dylib-has-no-filesystem // diff --git a/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp b/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp index c87fad258..69d91f571 100644 --- a/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// XFAIL: dylib-has-no-filesystem //