[HIP] Fix --hip-version flag with 0 as component

Allow the usage of minor version 0, for hip versions
such as 4.0. Change the default values when performing
version checks.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D104062
This commit is contained in:
Aaron En Ye Shi 2021-06-10 21:24:38 +00:00
parent 5ef5177145
commit f2cc0427b1
2 changed files with 15 additions and 3 deletions

View File

@ -316,8 +316,8 @@ RocmInstallationDetector::RocmInstallationDetector(
HIPPathArg = Args.getLastArgValue(clang::driver::options::OPT_hip_path_EQ);
if (auto *A = Args.getLastArg(clang::driver::options::OPT_hip_version_EQ)) {
HIPVersionArg = A->getValue();
unsigned Major = 0;
unsigned Minor = 0;
unsigned Major = ~0U;
unsigned Minor = ~0U;
SmallVector<StringRef, 3> Parts;
HIPVersionArg.split(Parts, '.');
if (Parts.size())
@ -328,7 +328,9 @@ RocmInstallationDetector::RocmInstallationDetector(
VersionPatch = Parts[2].str();
if (VersionPatch.empty())
VersionPatch = "0";
if (Major == 0 || Minor == 0)
if (Major != ~0U && Minor == ~0U)
Minor = 0;
if (Major == ~0U || Minor == ~0U)
D.Diag(diag::err_drv_invalid_value)
<< A->getAsString(Args) << HIPVersionArg;

View File

@ -36,6 +36,16 @@
// SPECIFIED2: Found HIP installation: {{.*Driver}}, version 3.7.0
// RUN: %clang -v --rocm-path=%S --hip-version=4.0.21025 2>&1 \
// RUN: | FileCheck -check-prefixes=SPECIFIED3 %s
// SPECIFIED3: Found HIP installation: {{.*Driver}}, version 4.0.21025
// RUN: %clang -v --rocm-path=%S --hip-version=4 2>&1 \
// RUN: | FileCheck -check-prefixes=SPECIFIED4 %s
// SPECIFIED4: Found HIP installation: {{.*Driver}}, version 4.0.0
// RUN: not %clang -v --rocm-path=%S --hip-version=x.y 2>&1 \
// RUN: | FileCheck -check-prefixes=INVALID %s