Skip to content

Commit 7dce12d

Browse files
[AArch64] Suggest b.nfrst if the user tries b.nfirst.
Differential Revision: https://reviews.llvm.org/D119453 Co-authored-by: George Steed <george.steed@arm.com>
1 parent c807aa5 commit 7dce12d

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class AArch64AsmParser : public MCTargetAsmParser {
157157

158158
bool parseSysAlias(StringRef Name, SMLoc NameLoc, OperandVector &Operands);
159159
void createSysAlias(uint16_t Encoding, OperandVector &Operands, SMLoc S);
160-
AArch64CC::CondCode parseCondCodeString(StringRef Cond);
160+
AArch64CC::CondCode parseCondCodeString(StringRef Cond,
161+
std::string &Suggestion);
161162
bool parseCondCode(OperandVector &Operands, bool invertCondCode);
162163
unsigned matchRegisterNameAlias(StringRef Name, RegKind Kind);
163164
bool parseRegister(OperandVector &Operands);
@@ -3029,8 +3030,10 @@ AArch64AsmParser::tryParseImmWithOptionalShift(OperandVector &Operands) {
30293030
return MatchOperand_Success;
30303031
}
30313032

3032-
/// parseCondCodeString - Parse a Condition Code string.
3033-
AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
3033+
/// parseCondCodeString - Parse a Condition Code string, optionally returning a
3034+
/// suggestion to help common typos.
3035+
AArch64CC::CondCode
3036+
AArch64AsmParser::parseCondCodeString(StringRef Cond, std::string &Suggestion) {
30343037
AArch64CC::CondCode CC = StringSwitch<AArch64CC::CondCode>(Cond.lower())
30353038
.Case("eq", AArch64CC::EQ)
30363039
.Case("ne", AArch64CC::NE)
@@ -3053,7 +3056,7 @@ AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
30533056
.Default(AArch64CC::Invalid);
30543057

30553058
if (CC == AArch64CC::Invalid &&
3056-
getSTI().getFeatureBits()[AArch64::FeatureSVE])
3059+
getSTI().getFeatureBits()[AArch64::FeatureSVE]) {
30573060
CC = StringSwitch<AArch64CC::CondCode>(Cond.lower())
30583061
.Case("none", AArch64CC::EQ)
30593062
.Case("any", AArch64CC::NE)
@@ -3067,6 +3070,9 @@ AArch64CC::CondCode AArch64AsmParser::parseCondCodeString(StringRef Cond) {
30673070
.Case("tstop", AArch64CC::LT)
30683071
.Default(AArch64CC::Invalid);
30693072

3073+
if (CC == AArch64CC::Invalid && Cond.lower() == "nfirst")
3074+
Suggestion = "nfrst";
3075+
}
30703076
return CC;
30713077
}
30723078

@@ -3078,9 +3084,14 @@ bool AArch64AsmParser::parseCondCode(OperandVector &Operands,
30783084
assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
30793085

30803086
StringRef Cond = Tok.getString();
3081-
AArch64CC::CondCode CC = parseCondCodeString(Cond);
3082-
if (CC == AArch64CC::Invalid)
3083-
return TokError("invalid condition code");
3087+
std::string Suggestion;
3088+
AArch64CC::CondCode CC = parseCondCodeString(Cond, Suggestion);
3089+
if (CC == AArch64CC::Invalid) {
3090+
std::string Msg = "invalid condition code";
3091+
if (!Suggestion.empty())
3092+
Msg += ", did you mean " + Suggestion + "?";
3093+
return TokError(Msg);
3094+
}
30843095
Lex(); // Eat identifier token.
30853096

30863097
if (invertCondCode) {
@@ -4545,9 +4556,14 @@ bool AArch64AsmParser::ParseInstruction(ParseInstructionInfo &Info,
45454556

45464557
SMLoc SuffixLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
45474558
(Head.data() - Name.data()));
4548-
AArch64CC::CondCode CC = parseCondCodeString(Head);
4549-
if (CC == AArch64CC::Invalid)
4550-
return Error(SuffixLoc, "invalid condition code");
4559+
std::string Suggestion;
4560+
AArch64CC::CondCode CC = parseCondCodeString(Head, Suggestion);
4561+
if (CC == AArch64CC::Invalid) {
4562+
std::string Msg = "invalid condition code";
4563+
if (!Suggestion.empty())
4564+
Msg += ", did you mean " + Suggestion + "?";
4565+
return Error(SuffixLoc, Msg);
4566+
}
45514567
Operands.push_back(AArch64Operand::CreateToken(".", SuffixLoc, getContext(),
45524568
/*IsSuffix=*/true));
45534569
Operands.push_back(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not llvm-mc -triple aarch64 -show-encoding -mattr=+sve < %s 2>&1 | FileCheck %s
2+
3+
//------------------------------------------------------------------------------
4+
// Condition code diagnostics for SVE
5+
//------------------------------------------------------------------------------
6+
7+
b.nfirst lbl
8+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid condition code, did you mean nfrst?
9+
// CHECK-NEXT: b.nfirst lbl

0 commit comments

Comments
 (0)