[libcxx-commits] [libcxx] r356616 - [libc++] Mark <filesystem> as unavailable on Apple platforms using pragmas

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 20 14:18:14 PDT 2019


Author: ldionne
Date: Wed Mar 20 14:18:14 2019
New Revision: 356616

URL: http://llvm.org/viewvc/llvm-project?rev=356616&view=rev
Log:
[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

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/chrono
    libcxx/trunk/include/filesystem
    libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp
    libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp
    libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed Mar 20 14:18:14 2019
@@ -1311,7 +1311,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #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 __sanit
      __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 __sanit
 #  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.

Modified: libcxx/trunk/include/chrono
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/chrono?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/include/chrono (original)
+++ libcxx/trunk/include/chrono Wed Mar 20 14:18:14 2019
@@ -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 {

Modified: libcxx/trunk/include/filesystem
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/filesystem?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/include/filesystem (original)
+++ libcxx/trunk/include/filesystem Wed Mar 20 14:18:14 2019
@@ -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 op
   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&)
   return recursive_directory_iterator();
 }
 
+_LIBCPP_AVAILABILITY_FILESYSTEM_POP
+
 _LIBCPP_END_NAMESPACE_FILESYSTEM
 
 #endif // !_LIBCPP_CXX03_LANG

Modified: libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp Wed Mar 20 14:18:14 2019
@@ -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

Modified: libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp Wed Mar 20 14:18:14 2019
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// XFAIL: dylib-has-no-filesystem
 
 // <chrono>
 

Modified: libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp?rev=356616&r1=356615&r2=356616&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp Wed Mar 20 14:18:14 2019
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// XFAIL: dylib-has-no-filesystem
 
 // <chrono>
 




More information about the libcxx-commits mailing list