Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -461,9 +461,14 @@ 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"); + // 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(ParentSharePath) + "/hip/version", std::string(BinPath) + "/.hipVersion"}) { llvm::ErrorOr> VersionFile = FS.getBufferForFile(VersionFilePath); Index: clang/test/Driver/hip-version.hip =================================================================== --- clang/test/Driver/hip-version.hip +++ 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