[libc++] Mark <filesystem> as unavailable on Apple platforms using pragmas

Summary:
Also add the corresponding XFAILs to tests that require filesystem.
The approach taken to mark <filesystem> 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 <filesystem> 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
This commit is contained in:
Louis Dionne 2019-03-20 21:18:14 +00:00
parent ce2670ada3
commit 080f06df54
6 changed files with 30 additions and 3 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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 <class... _Args>
_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

View File

@ -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
// <chrono>
// file_clock

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
// XFAIL: dylib-has-no-filesystem
// <chrono>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
// XFAIL: dylib-has-no-filesystem
// <chrono>