[PATCH] D119453: [AArch64] Suggest b.nfrst if the user tries b.nfirst.
Matt Devereau via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 09:17:59 PST 2022
MattDevereau created this revision.
MattDevereau added reviewers: peterwaller-arm, paulwalker-arm, bsmith, DavidTruby, david-arm, georges.
Herald added subscribers: hiraditya, kristof.beyls.
MattDevereau requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119453
Files:
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s
Index: llvm/test/MC/AArch64/SVE/condtion-code-diagnostics.s
===================================================================
--- /dev/null
+++ 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, you probably meant nfrst
+// CHECK-NEXT: b.nfirst lbl
Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===================================================================
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -157,7 +157,8 @@
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 @@
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 @@
.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 @@
.Case("tstop", AArch64CC::LT)
.Default(AArch64CC::Invalid);
+ if (CC == AArch64CC::Invalid && Cond.lower() == "nfirst")
+ Suggestion = "nfrst";
+ }
return CC;
}
@@ -3078,9 +3084,14 @@
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 += ", you probably meant " + Suggestion;
+ return TokError(Msg);
+ }
Lex(); // Eat identifier token.
if (invertCondCode) {
@@ -4545,9 +4556,14 @@
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 += ", you probably meant " + Suggestion;
+ return Error(SuffixLoc, Msg);
+ }
Operands.push_back(AArch64Operand::CreateToken(".", SuffixLoc, getContext(),
/*IsSuffix=*/true));
Operands.push_back(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119453.407567.patch
Type: text/x-patch
Size: 4103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220210/31ab9a55/attachment.bin>
More information about the llvm-commits
mailing list