[HIP] Fix --hip-version flag with 0 as component
authorAaron En Ye Shi <enye.shi@gmail.com>
Thu, 10 Jun 2021 21:24:38 +0000 (21:24 +0000)
committerAaron En Ye Shi <enye.shi@gmail.com>
Fri, 11 Jun 2021 16:25:03 +0000 (16:25 +0000)
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

clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/test/Driver/hip-version.hip

index ea3a4b4a8fd1ee08146668596c957a335cfe4c87..2e92be51f69ef046b7da6d2343e491f30e367168 100644 (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;
 
index eb1295210cfc133cc359c0b844ceb0bc43aaa2fd..83b8dbddf228c21c14b3add207ed933b9f6ba8ec 100644 (file)
 
 // 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