[libcxx-commits] [libcxx] [libc++] Protect the libc++ implementation from CUDA SDK's `__noinline__` macro (PR #73838)

Dmitri Gribenko via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 20 15:00:27 PST 2024


https://github.com/gribozavr updated https://github.com/llvm/llvm-project/pull/73838

>From 7982d7d817bbaec961a2838a2b04452a5f6b1882 Mon Sep 17 00:00:00 2001
From: Dmitri Gribenko <gribozavr at gmail.com>
Date: Sat, 20 Jan 2024 23:58:55 +0100
Subject: [PATCH] [libc++] Protect the libc++ implementation from CUDA SDK's
 `__noinline__` macro

The CUDA SDK contains an unfortunate definition for the `__noinline__` macro.

I don't want to quote the CUDA header here, but you can find online plenty of
information about this macro definition being problematic and creating
conflicts for numerous other libraries, for example [on
StackOverflow](https://stackoverflow.com/questions/70301375/noinline-macro-conflict-between-glib-and-cuda).
---
 libcxx/include/__config | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index 90a4585938a13f..f4fe042c969b38 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1205,6 +1205,20 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
 #    define _LIBCPP_NOINLINE
 #  endif
 
+#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
+// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
+// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
+// when compiling for CUDA we use the non-underscored version of the noinline
+// attribute.
+//
+// See https://github.com/llvm/llvm-project/pull/73838 for more details.
+#    define _LIBCPP_NOINLINE __attribute__((noinline))
+#  elif __has_attribute(__noinline__)
+#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
+#  else
+#    define _LIBCPP_NOINLINE
+#  endif
+
 // We often repeat things just for handling wide characters in the library.
 // When wide characters are disabled, it can be useful to have a quick way of
 // disabling it without having to resort to #if-#endif, which has a larger



More information about the libcxx-commits mailing list