From 8e55aea6ee2ca353eedf2311aad7d92f58264ed9 Mon Sep 17 00:00:00 2001 From: Samuel Ainsworth Date: Tue, 10 Mar 2026 20:33:31 -0400 Subject: [PATCH] cuda_nvcc: fix host_defines.h __noinline__ conflict under clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit host_defines.h redefines __noinline__ as __attribute__((noinline)). When clang compiles CUDA code against libstdc++ >=12, which uses __attribute__((__noinline__)), the macro causes the invalid expansion __attribute__((__attribute__((noinline)))). Clang natively understands __noinline__ as an attribute, so the macro is unnecessary — skip it when clang is the compiler. --- .../development/cuda-modules/packages/cuda_nvcc.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/development/cuda-modules/packages/cuda_nvcc.nix b/pkgs/development/cuda-modules/packages/cuda_nvcc.nix index 07fe457cc53f..404811ffa2f5 100644 --- a/pkgs/development/cuda-modules/packages/cuda_nvcc.nix +++ b/pkgs/development/cuda-modules/packages/cuda_nvcc.nix @@ -213,6 +213,19 @@ buildRedist (finalAttrs: { "__func__(float cospif(const float a))" \ "__func__(float cospif(const float a) throw())" '' + # Fix clang CUDA compilation: host_defines.h redefines __noinline__ as + # __attribute__((noinline)), which conflicts with libstdc++ >=12 using + # __attribute__((__noinline__)) — the macro expands to + # __attribute__((__attribute__((noinline)))) which is invalid. + # Clang natively understands __noinline__ as an attribute so the macro + # is unnecessary. Skip it when clang is the compiler. + + lib.optionalString (cudaOlder "13.0") '' + nixLog "Patching host_defines.h to skip __noinline__ macro under clang" + substituteInPlace "''${!outputInclude:?}/include/crt/host_defines.h" \ + --replace-fail \ + '#if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)' \ + '#if (defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)) && !defined(__clang__)' + '' ); brokenAssertions = [