[libcxx-commits] [libcxx] f76c424 - [libc++] Improve the detection of whether the blocks runtime is available

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 24 04:02:31 PDT 2020


Author: Louis Dionne
Date: 2020-04-24T07:02:21-04:00
New Revision: f76c42416cf43b7027f41d6b3bc6ee7e5593a7fe

URL: https://github.com/llvm/llvm-project/commit/f76c42416cf43b7027f41d6b3bc6ee7e5593a7fe
DIFF: https://github.com/llvm/llvm-project/commit/f76c42416cf43b7027f41d6b3bc6ee7e5593a7fe.diff

LOG: [libc++] Improve the detection of whether the blocks runtime is available

The runtime for Blocks may not be available even though the Blocks
language extension _is_ available. Instead of potentially failing,
this commit is much more conservative and assumes the runtime for
Blocks is only provided on Apple platforms.

Differential Revision: https://reviews.llvm.org/D78757

Added: 
    

Modified: 
    libcxx/include/__config
    libcxx/include/functional
    libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 42f59ea99665..bfde9e9c9895 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -474,6 +474,10 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_HAS_EXTENSION_BLOCKS
 #endif
 
+#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
+#  define _LIBCPP_HAS_BLOCKS_RUNTIME
+#endif
+
 #if !(__has_feature(cxx_relaxed_constexpr))
 #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 #endif

diff  --git a/libcxx/include/functional b/libcxx/include/functional
index 360ca6e32005..62b7d097be63 100644
--- a/libcxx/include/functional
+++ b/libcxx/include/functional
@@ -508,7 +508,7 @@ POLICY:  For non-variadic implementations, the number of arguments is limited
 
 #include <__functional_base>
 
-#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
+#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
 #include <Block.h>
 #endif
 
@@ -2255,7 +2255,7 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
 #endif // _LIBCPP_NO_RTTI
 };
 
-#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && !defined(_LIBCPP_HAS_OBJC_ARC) && __has_include(<Block.h>)
+#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
 
 template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
 class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>

diff  --git a/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp b/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp
index 757b3f21689d..6f50f4c65dc9 100644
--- a/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp
+++ b/libcxx/test/libcxx/utilities/function.objects/func.blocks.sh.cpp
@@ -9,14 +9,15 @@
 // std::function support for the "blocks" extension
 
 // UNSUPPORTED: c++98, c++03
-// REQUIRES: has-fblocks
+
+// This test requires the Blocks runtime, which is (only?) available
+// on Darwin out-of-the-box.
+// REQUIRES: has-fblocks && darwin
 
 // FILE_DEPENDENCIES: %t.exe
 // RUN: %{build} -fblocks
 // RUN: %{run}
 
-#if __has_include(<Block.h>)
-
 #include <functional>
 #include <cstdlib>
 #include <cassert>
@@ -143,9 +144,3 @@ int main(int, char**)
 
     return 0;
 }
-
-#else
-
-int main() { }
-
-#endif


        


More information about the libcxx-commits mailing list