https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/236089

>From b3b45e1f64332ecc8adebf1956007ad0bd42f4e8 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <[email protected]>
Date: Wed, 28 Oct 2026 11:48:30 -0500
Subject: [PATCH] [OpenMP] Switch the underlying type of VersionRange to
 unsigned

It was int before. The goal is to unify Version and VersionRange,
and Version stores the value as unsigned.
---
 clang/lib/Parse/ParseOpenMP.cpp                 |  2 +-
 flang/include/flang/Parser/openmp-utils.h       |  3 +--
 flang/lib/Parser/openmp-utils.cpp               |  3 +--
 flang/lib/Semantics/check-omp-syntax.cpp        |  3 +--
 llvm/include/llvm/Frontend/Directive/Spelling.h |  6 +++---
 llvm/include/llvm/TableGen/DirectiveEmitter.h   | 10 ++++++----
 llvm/lib/Frontend/Directive/Spelling.cpp        |  6 ++----
 7 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 1e3e400cc7d055..ff8b72a5d06a20 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -69,7 +69,7 @@ static OpenMPDirectiveKind checkOpenMPDirectiveName(Parser &P,
   assert(D == Kind && "Directive kind mismatch");
   // Ignore the case Version > VR.Max: In OpenMP 6.0 all prior spellings
   // are explicitly allowed.
-  if (static_cast<int>(Version) < VR.Min)
+  if (Version < VR.Min)
     P.Diag(Loc, diag::warn_omp_future_directive_spelling) << Name;
 
   return Kind;
diff --git a/flang/include/flang/Parser/openmp-utils.h 
b/flang/include/flang/Parser/openmp-utils.h
index 817ac1ce59d3f6..db91cfba5e24f9 100644
--- a/flang/include/flang/Parser/openmp-utils.h
+++ b/flang/include/flang/Parser/openmp-utils.h
@@ -88,8 +88,7 @@ llvm::directive::VersionRange GetVersionRangeForElement(
       maxVer = std::max(maxVer, v);
     }
   }
-  return llvm::directive::VersionRange{
-      static_cast<int>(minVer.value()), static_cast<int>(maxVer.value())};
+  return llvm::directive::VersionRange{minVer.value(), maxVer.value()};
 }
 
 llvm::directive::VersionRange GetVersionRangeForDirective(
diff --git a/flang/lib/Parser/openmp-utils.cpp 
b/flang/lib/Parser/openmp-utils.cpp
index a1b39b13cedd57..4bc4de86e9b0da 100644
--- a/flang/lib/Parser/openmp-utils.cpp
+++ b/flang/lib/Parser/openmp-utils.cpp
@@ -63,8 +63,7 @@ llvm::directive::VersionRange GetVersionRangeForDirective(
     minVer = std::min(minVer, v);
     maxVer = std::max(maxVer, v);
   }
-  return llvm::directive::VersionRange{
-      static_cast<int>(minVer.value()), static_cast<int>(maxVer.value())};
+  return llvm::directive::VersionRange{minVer.value(), maxVer.value()};
 }
 } // namespace descriptor
 
diff --git a/flang/lib/Semantics/check-omp-syntax.cpp 
b/flang/lib/Semantics/check-omp-syntax.cpp
index d1e90d0e08738c..7ce3910c3dceab 100644
--- a/flang/lib/Semantics/check-omp-syntax.cpp
+++ b/flang/lib/Semantics/check-omp-syntax.cpp
@@ -47,9 +47,8 @@ static llvm::omp::Properties GetProperties(
 static llvm::omp::Version GetClosestVersion(
     llvm::directive::VersionRange range, llvm::omp::Version version) {
   if (range.isValid()) {
-    int intVer{static_cast<int>(version.value())};
     return llvm::omp::Version(
-        intVer >= range.Min ? std::min(intVer, range.Max) : range.Min);
+        std::min(std::max(version.value(), range.Min), range.Max));
   }
   return llvm::omp::Version();
 }
diff --git a/llvm/include/llvm/Frontend/Directive/Spelling.h 
b/llvm/include/llvm/Frontend/Directive/Spelling.h
index 9c70210a68139b..31c2e51094c354 100644
--- a/llvm/include/llvm/Frontend/Directive/Spelling.h
+++ b/llvm/include/llvm/Frontend/Directive/Spelling.h
@@ -18,11 +18,11 @@
 namespace llvm::directive {
 
 struct VersionRange {
-  static constexpr int MaxValue = std::numeric_limits<int>::max();
+  static constexpr unsigned MaxValue = std::numeric_limits<int>::max();
   // The default "Version" value in get<Lang><Enum>Name() is 0, include that
   // in the maximum range.
-  int Min = 0;
-  int Max = MaxValue;
+  unsigned Min = 0;
+  unsigned Max = MaxValue;
 
   constexpr bool operator<(const VersionRange &R) const {
     return std::tie(Min, Max) < std::tie(R.Min, R.Max);
diff --git a/llvm/include/llvm/TableGen/DirectiveEmitter.h 
b/llvm/include/llvm/TableGen/DirectiveEmitter.h
index 8e7854da502527..c0f2102f877656 100644
--- a/llvm/include/llvm/TableGen/DirectiveEmitter.h
+++ b/llvm/include/llvm/TableGen/DirectiveEmitter.h
@@ -105,15 +105,17 @@ class DirectiveLanguage {
 
 class Versioned {
 public:
-  int getMinVersion(const Record *R) const {
+  unsigned getMinVersion(const Record *R) const {
     int64_t Min = R->getValueAsInt("minVersion");
-    assert(llvm::isInt<IntWidth>(Min) && "Value out of range of 'int'");
+    assert(Min >= 0 && llvm::isInt<IntWidth>(Min) &&
+           "Value out of range of non-negative 'int'");
     return Min;
   }
 
-  int getMaxVersion(const Record *R) const {
+  unsigned getMaxVersion(const Record *R) const {
     int64_t Max = R->getValueAsInt("maxVersion");
-    assert(llvm::isInt<IntWidth>(Max) && "Value out of range of 'int'");
+    assert(Max >= 0 && llvm::isInt<IntWidth>(Max) &&
+           "Value out of range of non-negative 'int'");
     return Max;
   }
 
diff --git a/llvm/lib/Frontend/Directive/Spelling.cpp 
b/llvm/lib/Frontend/Directive/Spelling.cpp
index 4992268f2e6778..c6bde6503ef32f 100644
--- a/llvm/lib/Frontend/Directive/Spelling.cpp
+++ b/llvm/lib/Frontend/Directive/Spelling.cpp
@@ -15,15 +15,13 @@
 
 using namespace llvm;
 
-static bool Contains(directive::VersionRange V, int P) {
+static bool Contains(directive::VersionRange V, unsigned P) {
   return V.Min <= P && P <= V.Max;
 }
 
 llvm::StringRef llvm::directive::FindName(
     llvm::iterator_range<const directive::Spelling *> Range, unsigned Version) 
{
-  assert(llvm::isInt<8 * sizeof(int)>(Version) && "Version value out of 
range");
-
-  int V = Version;
+  unsigned V = Version;
   // Do a linear search to find the first Spelling that contains Version.
   // The condition "contains(S, Version)" does not partition the list of
   // spellings, so std::[lower|upper]_bound cannot be used.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to