[llvm-branch-commits] [clang] release/22.x: Make sure that driver-provided __CUDA_ARCH_LIST__ can be overridden by user-supplied arguments. (#176301) (PR #176487)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 16 14:40:43 PST 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/176487

Backport 8dd848e7ae8774c64368934e2a821a2a7adc823c

Requested by: @Artem-B

>From 82a785d402d6f3e6036abb68c66ccdb70c7577b0 Mon Sep 17 00:00:00 2001
From: Artem Belevich <tra at google.com>
Date: Fri, 16 Jan 2026 09:32:47 -0800
Subject: [PATCH] Make sure that driver-provided __CUDA_ARCH_LIST__ can be
 overridden by user-supplied arguments. (#176301)

(cherry picked from commit 8dd848e7ae8774c64368934e2a821a2a7adc823c)
---
 clang/lib/Driver/ToolChains/Clang.cpp |  8 ++++----
 clang/test/Driver/cuda-arch-list.cu   | 14 ++++++++++++++
 2 files changed, 18 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
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"



More information about the llvm-branch-commits mailing list