[llvm] [AsmParser][NFCI] Restructure DiagnosticPredicate (PR #126653)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 11:02:49 PST 2025


================
@@ -198,21 +192,36 @@ enum class DiagnosticPredicateTy {
 // This is a light-weight alternative to the 'NearMissInfo' approach
 // below which collects *all* possible diagnostics. This alternative
 // is optional and fully backward compatible with existing
-// PredicateMethods that return a 'bool' (match or no match).
-struct DiagnosticPredicate {
-  DiagnosticPredicateTy Type;
-
-  explicit DiagnosticPredicate(bool Match)
-      : Type(Match ? DiagnosticPredicateTy::Match
-                   : DiagnosticPredicateTy::NearMatch) {}
-  DiagnosticPredicate(DiagnosticPredicateTy T) : Type(T) {}
-  DiagnosticPredicate(const DiagnosticPredicate &) = default;
+// PredicateMethods that return a 'bool' (match or near match).
+class DiagnosticPredicate {
+  enum class PredicateTy {
+    Match,     // Matches
+    NearMatch, // Close Match: use Specific Diagnostic
+    NoMatch,   // No Match: use `InvalidOperand`
+  } Predicate;
+
+public:
+#if __cplusplus >= 202002L
+  using enum PredicateTy;
+#else
+  static constexpr PredicateTy Match = PredicateTy::Match;
+  static constexpr PredicateTy NearMatch = PredicateTy::NearMatch;
+  static constexpr PredicateTy NoMatch = PredicateTy::NoMatch;
+#endif
----------------
lenary wrote:

A conversion from the enum value to a bool for the boolean constructor.

Anyway, I pushed an update to use an unscoped enum, and ran quite a few of the AArch64 tests (some require `llc` which I didn't wait to fully build), and once I fixed the divergence of behaviour caused by https://github.com/llvm/llvm-project/pull/126653/commits/a2d9088b9bb5cebbc4b96f74232f12432ae4e67a they're doing exactly what they were before.

I think the reality is those diagnostics have bugs, but I want this patch to remain NFC and then i will fix those diagnostics and tests.

https://github.com/llvm/llvm-project/pull/126653


More information about the llvm-commits mailing list