[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
Sun Jan 21 16:31:13 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 1/2] [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

>From c212ae797aca7e876d91d6e34a8c1a0bee50740e Mon Sep 17 00:00:00 2001
From: Dmitri Gribenko <gribozavr at gmail.com>
Date: Mon, 22 Jan 2024 01:30:32 +0100
Subject: [PATCH 2/2] Expand the comment, we are still expecting a change in
 the CUDA SDK

---
 libcxx/include/__config | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index f4fe042c969b38..276de23d671d68 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1211,6 +1211,9 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
 // when compiling for CUDA we use the non-underscored version of the noinline
 // attribute.
 //
+// This is a temporary workaround and we still expect the CUDA SDK team to solve
+// this issue properly in the SDK headers.
+//
 // See https://github.com/llvm/llvm-project/pull/73838 for more details.
 #    define _LIBCPP_NOINLINE __attribute__((noinline))
 #  elif __has_attribute(__noinline__)



More information about the libcxx-commits mailing list