Skip to content

Commit 7982d7d

Browse files
committed
[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).
1 parent 11b3b10 commit 7982d7d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libcxx/include/__config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,20 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
12051205
# define _LIBCPP_NOINLINE
12061206
# endif
12071207

1208+
# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
1209+
// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
1210+
// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
1211+
// when compiling for CUDA we use the non-underscored version of the noinline
1212+
// attribute.
1213+
//
1214+
// See https://github.com/llvm/llvm-project/pull/73838 for more details.
1215+
# define _LIBCPP_NOINLINE __attribute__((noinline))
1216+
# elif __has_attribute(__noinline__)
1217+
# define _LIBCPP_NOINLINE __attribute__((__noinline__))
1218+
# else
1219+
# define _LIBCPP_NOINLINE
1220+
# endif
1221+
12081222
// We often repeat things just for handling wide characters in the library.
12091223
// When wide characters are disabled, it can be useful to have a quick way of
12101224
// disabling it without having to resort to #if-#endif, which has a larger

0 commit comments

Comments
 (0)