[llvm] 7dce12d - [AArch64] Suggest b.nfrst if the user tries b.nfirst.
Matt Devereau via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 15 07:06:16 PST 2022
Author: Matt Devereau
Date: 2022-02-15T15:06:04Z
New Revision: 7dce12de68880fe7fb124afaf5bcf7671229cfc0
URL: https://github.com/llvm/llvm-project/commit/7dce12de68880fe7fb124afaf5bcf7671229cfc0
DIFF: https://github.com/llvm/llvm-project/commit/7dce12de68880fe7fb124afaf5bcf7671229cfc0.diff
LOG: [AArch64] Suggest b.nfrst if the user tries b.nfirst.
Differential Revision: https://reviews.llvm.org/D119453
Co-authored-by: George Steed <george.steed at arm.com>
Added:
llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s
Modified:
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 33ed7ae9780e6..a764e8c16348a 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -157,7 +157,8 @@ class AArch64AsmParser : public MCTargetAsmParser {
bool parseSysAlias(StringRef Name, SMLoc NameLoc, OperandVector &Operands);
void createSysAlias(uint16_t Encoding, OperandVector &Operands, SMLoc S);
- AArch64CC::CondCode parseCondCodeString(StringRef Cond);
+ AArch64CC::CondCode parseCondCodeString(StringRef Cond,
+ std::string &Suggestion);
bool parseCondCode(OperandVector &Operands, bool invertCondCode);
unsigned matchRegisterNameAlias(StringRef Name, RegKind Kind);
bool parseRegister(OperandVector &Operands);
@@ -3029,8 +3030,10 @@ AArch64AsmParser::tryParseImmWithOptionalShift(OperandVector &Operands) {
return MatchOperand_Success;
}
-/// parseCondCodeString - Parse a Condition Code string.
-AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
+/// parseCondCodeString - Parse a Condition Code string, optionally returning a
+/// suggestion to help common typos.
+AArch64CC::CondCode
+AArch64AsmParser::parseCondCodeString(StringRef Cond, std::string &Suggestion) {
AArch64CC::CondCode CC = StringSwitch<AArch64CC::CondCode>(Cond.lower())
.Case("eq", AArch64CC::EQ)
.Case("ne", AArch64CC::NE)
@@ -3053,7 +3056,7 @@ AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
.Default(AArch64CC::Invalid);
if (CC == AArch64CC::Invalid &&
- getSTI().getFeatureBits()[AArch64::FeatureSVE])
+ getSTI().getFeatureBits()[AArch64::FeatureSVE]) {
CC = StringSwitch<AArch64CC::CondCode>(Cond.lower())
.Case("none", AArch64CC::EQ)
.Case("any", AArch64CC::NE)
@@ -3067,6 +3070,9 @@ AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
.Case("tstop", AArch64CC::LT)
.Default(AArch64CC::Invalid);
+ if (CC == AArch64CC::Invalid && Cond.lower() == "nfirst")
+ Suggestion = "nfrst";
+ }
return CC;
}
@@ -3078,9 +3084,14 @@ bool AArch64AsmParser::parseCondCode(OperandVector &Operands,
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
StringRef Cond = Tok.getString();
- AArch64CC::CondCode CC = parseCondCodeString(Cond);
- if (CC == AArch64CC::Invalid)
- return TokError("invalid condition code");
+ std::string Suggestion;
+ AArch64CC::CondCode CC = parseCondCodeString(Cond, Suggestion);
+ if (CC == AArch64CC::Invalid) {
+ std::string Msg = "invalid condition code";
+ if (!Suggestion.empty())
+ Msg += ", did you mean " + Suggestion + "?";
+ return TokError(Msg);
+ }
Lex(); // Eat identifier token.
if (invertCondCode) {
@@ -4545,9 +4556,14 @@ bool AArch64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
(Head.data() - Name.data()));
- AArch64CC::CondCode CC = parseCondCodeString(Head);
- if (CC == AArch64CC::Invalid)
- return Error(SuffixLoc, "invalid condition code");
+ std::string Suggestion;
+ AArch64CC::CondCode CC = parseCondCodeString(Head, Suggestion);
+ if (CC == AArch64CC::Invalid) {
+ std::string Msg = "invalid condition code";
+ if (!Suggestion.empty())
+ Msg += ", did you mean " + Suggestion + "?";
+ return Error(SuffixLoc, Msg);
+ }
Operands.push_back(AArch64Operand::CreateToken(".", SuffixLoc, getContext(),
/*IsSuffix=*/true));
Operands.push_back(
diff --git a/llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s b/llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s
new file mode 100644
index 0000000000000..52c56a7d12f81
--- /dev/null
+++ b/llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s
@@ -0,0 +1,9 @@
+// RUN: not llvm-mc -triple aarch64 -show-encoding -mattr=+sve < %s 2>&1 | FileCheck %s
+
+//------------------------------------------------------------------------------
+// Condition code diagnostics for SVE
+//------------------------------------------------------------------------------
+
+ b.nfirst lbl
+// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid condition code, did you mean nfrst?
+// CHECK-NEXT: b.nfirst lbl
More information about the llvm-commits
mailing list