https://github.com/Artem-B created https://github.com/llvm/llvm-project/pull/176301
None >From 73980ae6560da3e54053dcbf0bf07b3a0ab8d6b2 Mon Sep 17 00:00:00 2001 From: Artem Belevich <[email protected]> Date: Thu, 15 Jan 2026 18:11:50 -0800 Subject: [PATCH 1/2] Make sure driver defines __CUDA_ARCH_LIST before user flags are added. --- clang/lib/Driver/ToolChains/Clang.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4ca98600d6e93..18933cb8ad7c2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1065,10 +1065,6 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, A->render(Args, CmdArgs); } - Args.addAllArgs(CmdArgs, - {options::OPT_D, options::OPT_U, options::OPT_I_Group, - options::OPT_F, options::OPT_embed_dir_EQ}); - if (C.isOffloadingHostKind(Action::OFK_Cuda) || JA.isDeviceOffloading(Action::OFK_Cuda)) { // Collect all enabled NVPTX architectures. @@ -1091,6 +1087,10 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, } } + Args.addAllArgs(CmdArgs, + {options::OPT_D, options::OPT_U, options::OPT_I_Group, + options::OPT_F, options::OPT_embed_dir_EQ}); + // Add -Wp, and -Xpreprocessor if using the preprocessor. // FIXME: There is a very unfortunate problem here, some troubled >From ed2a7b255d9d36c6894e46d74b535b2583ebb428 Mon Sep 17 00:00:00 2001 From: Artem Belevich <[email protected]> Date: Fri, 16 Jan 2026 02:33:00 +0000 Subject: [PATCH 2/2] Added a test case --- clang/test/Driver/cuda-arch-list.cu | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clang/test/Driver/cuda-arch-list.cu b/clang/test/Driver/cuda-arch-list.cu index 84efeb1499708..d4825f202d733 100644 --- a/clang/test/Driver/cuda-arch-list.cu +++ b/clang/test/Driver/cuda-arch-list.cu @@ -23,6 +23,11 @@ // RUN: --offload-arch=sm_60 --offload-arch=sm_70 --no-offload-arch=sm_60 %s 2>&1 \ // RUN: | FileCheck -check-prefixes=DEVICE70-ONLY,HOST70-ONLY %s +// Verify that user-specified -D__CUDA_ARCH_LIST__ overrides the driver-generated one +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nocudainc -nocudalib \ +// RUN: --offload-arch=sm_60 -D__CUDA_ARCH_LIST__=999 %s 2>&1 \ +// RUN: | FileCheck -check-prefixes=DEVICE-OVERRIDE,HOST-OVERRIDE %s + // DEVICE60: "-cc1" "-triple" "nvptx64-nvidia-cuda" // DEVICE60-SAME: "-target-cpu" "sm_60" // DEVICE60-SAME: "-D__CUDA_ARCH_LIST__=600" @@ -54,3 +59,12 @@ // HOST70-ONLY: "-cc1" "-triple" "x86_64-unknown-linux-gnu" // HOST70-ONLY-SAME: "-D__CUDA_ARCH_LIST__=700" + +// DEVICE-OVERRIDE: "-cc1" "-triple" "nvptx64-nvidia-cuda" +// DEVICE-OVERRIDE-SAME: "-target-cpu" "sm_60" +// DEVICE-OVERRIDE-SAME: "-D__CUDA_ARCH_LIST__=600" +// DEVICE-OVERRIDE-SAME: "-D" "__CUDA_ARCH_LIST__=999" + +// HOST-OVERRIDE: "-cc1" "-triple" "x86_64-unknown-linux-gnu" +// HOST-OVERRIDE-SAME: "-D__CUDA_ARCH_LIST__=600" +// HOST-OVERRIDE-SAME: "-D" "__CUDA_ARCH_LIST__=999" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
