[llvm] 70f5b22 - [TableGen][AsmMatcher] Fix the range check on 'MatchClassKind'

Michael Liao via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 08:26:05 PST 2024


Author: Michael Liao
Date: 2024-01-29T11:25:50-05:00
New Revision: 70f5b220509cafb3dc4e876e4feecb3dcca78dec

URL: https://github.com/llvm/llvm-project/commit/70f5b220509cafb3dc4e876e4feecb3dcca78dec
DIFF: https://github.com/llvm/llvm-project/commit/70f5b220509cafb3dc4e876e4feecb3dcca78dec.diff

LOG: [TableGen][AsmMatcher] Fix the range check on 'MatchClassKind'

- When selecting the minimal type for 'MatchClassKind' during the
  emission of 'MatchEntry' and 'OperandMatchEntry', two pre-defined
  kinds 'InvalidMatchClass' and 'OptionalMatchClass' are not taken into
  account.

Added: 
    

Modified: 
    llvm/utils/TableGen/AsmMatcherEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 73724e662f9e87..011d96a48d61da 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2863,8 +2863,11 @@ emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
                << " Mnemonic;\n";
   OS << "    " << getMinimalTypeForRange(MaxMask)
                << " OperandMask;\n";
-  OS << "    " << getMinimalTypeForRange(std::distance(
-                      Info.Classes.begin(), Info.Classes.end())) << " Class;\n";
+  OS << "    "
+     << getMinimalTypeForRange(
+            std::distance(Info.Classes.begin(), Info.Classes.end()) +
+            2 /* Include 'InvalidMatchClass' and 'OptionalMatchClass' */)
+     << " Class;\n";
   OS << "    " << getMinimalTypeForRange(MaxFeaturesIndex)
                << " RequiredFeaturesIdx;\n\n";
   OS << "    StringRef getMnemonic() const {\n";
@@ -3480,8 +3483,10 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
                << " ConvertFn;\n";
   OS << "    " << getMinimalTypeForRange(FeatureBitsets.size())
                << " RequiredFeaturesIdx;\n";
-  OS << "    " << getMinimalTypeForRange(
-                      std::distance(Info.Classes.begin(), Info.Classes.end()))
+  OS << "    "
+     << getMinimalTypeForRange(
+            std::distance(Info.Classes.begin(), Info.Classes.end()) +
+            2 /* Include 'InvalidMatchClass' and 'OptionalMatchClass' */)
      << " Classes[" << MaxNumOperands << "];\n";
   OS << "    StringRef getMnemonic() const {\n";
   OS << "      return StringRef(MnemonicTable + Mnemonic + 1,\n";


        


More information about the llvm-commits mailing list