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

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 6 07:47:49 PST 2026


================
@@ -614,20 +614,36 @@ void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
     return;
   }
 
-  CC1Args.push_back("-idirafter");
-  CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
-  SmallString<128> LibHipCxxPath(getIncludePath());
-  llvm::sys::path::append(LibHipCxxPath, "libhipcxx");
-  if (D.getVFS().exists(LibHipCxxPath)) {
-    CC1Args.push_back("-idirafter");
-    CC1Args.push_back(DriverArgs.MakeArgString(LibHipCxxPath));
-  }
+  // The ROCm toolkit include path (e.g. /opt/rocm/include) is added later
+  // by AddHIPIncludeArgsLate, which is called after C++ stdlib headers but
+  // before C system headers. This positional ordering ensures ROCm headers
+  // beat distro-installed HIP headers in /usr/include without breaking
+  // C++ #include_next chains.
   if (UsesRuntimeWrapper)
     CC1Args.append({"-include", "__clang_hip_runtime_wrapper.h"});
   if (HasHipStdPar)
     HandleHipStdPar();
 }
 
+void RocmInstallationDetector::AddHIPIncludeArgsLate(
----------------
yxsamliu wrote:

Could we update MSVC, MinGW, FreeBSD and Darwin too? They still call the early hook and do not implement the late hook, so host jobs now lose the HIP and libhipcxx include paths. Please add a host preprocessing test.

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


More information about the cfe-commits mailing list