[libcxx-commits] [libcxx] [libcxx] Make terminal check always false for `print` on GPU (PR #99259)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 16 16:53:32 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

This check must be handled in order to compile. The GPU cannot easily
determine if a given `FILE *` is a terminal because the `stdio`
interface is actually a wrapper over the system's `FILE *`, so we can't
really detect it easily. An RPC call could be made to `isatty` if we
really need to support this in the future.


---
Full diff: https://github.com/llvm/llvm-project/pull/99259.diff


4 Files Affected:

- (modified) libcxx/include/__config (+5) 
- (modified) libcxx/include/print (+1-1) 
- (modified) libcxx/src/chrono.cpp (+3-1) 
- (modified) libcxx/src/filesystem/filesystem_clock.cpp (+2-1) 


``````````diff
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 108f700823cbf..2a45077cdf4f6 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1223,6 +1223,11 @@ typedef __char32_t char32_t;
 #    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
 #  endif
 
+// Clang supports targeting GPU architectures.
+#  if (defined(__AMDGPU__) || defined(__NVPTX__)) && defined(_LIBCPP_COMPILER_CLANG_BASED)
+#    define _LIBCPP_TARGETING_GPU
+#endif
+
 #endif // __cplusplus
 
 #endif // _LIBCPP___CONFIG
diff --git a/libcxx/include/print b/libcxx/include/print
index 1a579daff270f..45aad7eaaaf3a 100644
--- a/libcxx/include/print
+++ b/libcxx/include/print
@@ -199,7 +199,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_terminal([[maybe_unused]] FILE* __stream)
   // the behavior in the test. This is not part of the public API.
 #  ifdef _LIBCPP_TESTING_PRINT_IS_TERMINAL
   return _LIBCPP_TESTING_PRINT_IS_TERMINAL(__stream);
-#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0
+#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0 || defined(_LIBCPP_TARGETING_GPU)
   return false;
 #  elif defined(_LIBCPP_WIN32API)
   return std::__is_windows_terminal(__stream);
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 83e8a64504ae0..e8080cdc9ed86 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -12,6 +12,7 @@
 #  define _LARGE_TIME_API
 #endif
 
+#include <__config>
 #include <__system_error/system_error.h>
 #include <cerrno> // errno
 #include <chrono>
@@ -33,7 +34,8 @@
 
 // OpenBSD does not have a fully conformant suite of POSIX timers, but
 // it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
-#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(_LIBCPP_TARGETING_GPU) ||           \
+    (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
 #  define _LIBCPP_HAS_CLOCK_GETTIME
 #endif
 
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index e13b2853e367c..4af35165f8853 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -29,7 +29,8 @@
 #  include <sys/time.h> // for gettimeofday and timeval
 #endif
 
-#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(_LIBCPP_TARGETING_GPU) ||                                   \
+    (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
 #  define _LIBCPP_HAS_CLOCK_GETTIME
 #endif
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/99259


More information about the libcxx-commits mailing list