Skip to content

Commit 70f5b22

Browse files
committed
[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.
1 parent ee08b99 commit 70f5b22

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,8 +2863,11 @@ emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
28632863
<< " Mnemonic;\n";
28642864
OS << " " << getMinimalTypeForRange(MaxMask)
28652865
<< " OperandMask;\n";
2866-
OS << " " << getMinimalTypeForRange(std::distance(
2867-
Info.Classes.begin(), Info.Classes.end())) << " Class;\n";
2866+
OS << " "
2867+
<< getMinimalTypeForRange(
2868+
std::distance(Info.Classes.begin(), Info.Classes.end()) +
2869+
2 /* Include 'InvalidMatchClass' and 'OptionalMatchClass' */)
2870+
<< " Class;\n";
28682871
OS << " " << getMinimalTypeForRange(MaxFeaturesIndex)
28692872
<< " RequiredFeaturesIdx;\n\n";
28702873
OS << " StringRef getMnemonic() const {\n";
@@ -3480,8 +3483,10 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
34803483
<< " ConvertFn;\n";
34813484
OS << " " << getMinimalTypeForRange(FeatureBitsets.size())
34823485
<< " RequiredFeaturesIdx;\n";
3483-
OS << " " << getMinimalTypeForRange(
3484-
std::distance(Info.Classes.begin(), Info.Classes.end()))
3486+
OS << " "
3487+
<< getMinimalTypeForRange(
3488+
std::distance(Info.Classes.begin(), Info.Classes.end()) +
3489+
2 /* Include 'InvalidMatchClass' and 'OptionalMatchClass' */)
34853490
<< " Classes[" << MaxNumOperands << "];\n";
34863491
OS << " StringRef getMnemonic() const {\n";
34873492
OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n";

0 commit comments

Comments
 (0)