[clang] [HIP] fix HIP detection for /usr (PR #80190)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 12:17:37 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

Skip checking HIP version file under parent directory for /usr/local since /usr will be checked after /usr/local.

Fixes: https://github.com/llvm/llvm-project/issues/78344

---
Full diff: https://github.com/llvm/llvm-project/pull/80190.diff


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+9-4) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index b3c9d5908654f..e207a9d784d5a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -486,10 +486,15 @@ void RocmInstallationDetector::detectHIPRuntime() {
       return newpath;
     };
     // If HIP version file can be found and parsed, use HIP version from there.
-    for (const auto &VersionFilePath :
-         {Append(SharePath, "hip", "version"),
-          Append(ParentSharePath, "hip", "version"),
-          Append(BinPath, ".hipVersion")}) {
+    std::vector<SmallString<0>> VersionFilePaths = {
+        Append(SharePath, "hip", "version"),
+        InstallPath != "/usr/local" ? Append(ParentSharePath, "hip", "version")
+                                    : SmallString<0>(),
+        Append(BinPath, ".hipVersion")};
+
+    for (const auto &VersionFilePath : VersionFilePaths) {
+      if (VersionFilePath.empty())
+        continue;
       llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
           FS.getBufferForFile(VersionFilePath);
       if (!VersionFile)

``````````

</details>


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


More information about the cfe-commits mailing list