[clang] [HIP] Fix distro HIP headers shadowing ROCm includes (PR #238058)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 12:46:29 PST 2026


================
@@ -1183,6 +1183,14 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(P));
   }
 
+  // Add HIP toolkit include paths after C++ stdlib but before system headers.
+  // This ensures the selected ROCm headers beat distro-installed HIP headers
+  // in /usr/include without breaking C++ #include_next chains.
+  // Skip when using LLVM offloading (-foffload-via-llvm): that mode uses its
+  // own offload headers instead of vendor ROCm headers.
+  if (JA.isOffloading(Action::OFK_HIP) && !UsesLLVMOffloading)
+    getToolChain().AddHIPIncludeArgsLate(Args, CmdArgs);
----------------
yxsamliu wrote:

Nit: On MSVC, this makes the ROCm HIP headers win over headers found through `INCLUDE`. Is that intended? If so, could we add a test?

https://github.com/llvm/llvm-project/pull/238058


More information about the cfe-commits mailing list