diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -461,10 +461,21 @@ SharePath = InstallPath; llvm::sys::path::append(SharePath, "share"); + // Get parent of InstallPath and append "share" + SmallString<0> ParentSharePath = llvm::sys::path::parent_path(InstallPath); + llvm::sys::path::append(ParentSharePath, "share"); + + auto Append = [](SmallString<0> &path, const Twine &a, const Twine &b = "", + const Twine &c = "", const Twine &d = "") { + SmallString<0> newpath = path; + llvm::sys::path::append(newpath, a, b, c, d); + return newpath; + }; // If HIP version file can be found and parsed, use HIP version from there. for (const auto &VersionFilePath : - {std::string(SharePath) + "/hip/version", - std::string(BinPath) + "/.hipVersion"}) { + {Append(SharePath, "hip", "version"), + Append(ParentSharePath, "hip", "version"), + Append(BinPath, ".hipVersion")}) { llvm::ErrorOr> VersionFile = FS.getBufferForFile(VersionFilePath); if (!VersionFile) diff --git a/clang/test/Driver/hip-version.hip b/clang/test/Driver/hip-version.hip --- a/clang/test/Driver/hip-version.hip +++ b/clang/test/Driver/hip-version.hip @@ -22,11 +22,17 @@ // RUN: mkdir -p %t/Inputs // RUN: cp -r %S/Inputs/rocm %t/Inputs // RUN: mkdir -p %t/Inputs/rocm/share/hip +// RUN: mkdir -p %t/Inputs/rocm/hip // RUN: mv %t/Inputs/rocm/bin/.hipVersion %t/Inputs/rocm/share/hip/version // RUN: %clang -v --rocm-path=%t/Inputs/rocm 2>&1 \ // RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: %clang -v --hip-path=%t/Inputs/rocm 2>&1 \ +// RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: %clang -v --hip-path=%t/Inputs/rocm/hip 2>&1 \ +// RUN: | FileCheck -check-prefixes=HIP-PATH %s // FOUND: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd +// HIP-PATH: Found HIP installation: {{.*Inputs.*rocm.*hip}}, version 3.6.20214-a2917cd // When --rocm-path is set and .hipVersion is not found, use default version