[PATCH] D154276: [RISCV] Use parseDirective returning ternary status
Sergei Barannikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 19:37:34 PDT 2023
barannikov88 updated this revision to Diff 536497.
barannikov88 edited the summary of this revision.
barannikov88 added a comment.
Fix parseDirectiveAttribute returning success after emitting an error
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154276/new/
https://reviews.llvm.org/D154276
Files:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/test/MC/RISCV/invalid-attribute.s
Index: llvm/test/MC/RISCV/invalid-attribute.s
===================================================================
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -1,4 +1,5 @@
## Negative tests:
+## - Unknown attribute name.
## - Feed integer value to string type attribute.
## - Feed string value to integer type attribute.
## - Invalid arch string.
@@ -6,6 +7,9 @@
# RUN: not llvm-mc %s -triple=riscv32 -filetype=asm 2>&1 | FileCheck %s
# RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
+.attribute unknown, "unknown"
+# CHECK: [[@LINE-1]]:12: error: attribute name not recognised: unknown
+
.attribute arch, "foo"
# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,e,g}
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===================================================================
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -116,7 +116,7 @@
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
SMLoc NameLoc, OperandVector &Operands) override;
- bool ParseDirective(AsmToken DirectiveID) override;
+ ParseStatus parseDirective(AsmToken DirectiveID) override;
bool parseVTypeToken(StringRef Identifier, VTypeState &State, unsigned &Sew,
unsigned &Lmul, bool &Fractional, bool &TailAgnostic,
@@ -2606,11 +2606,7 @@
return false;
}
-bool RISCVAsmParser::ParseDirective(AsmToken DirectiveID) {
- // This returns false if this function recognizes the directive
- // regardless of whether it is successfully handles or reports an
- // error. Otherwise it returns true to give the generic parser a
- // chance at recognizing it.
+ParseStatus RISCVAsmParser::parseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getString();
if (IDVal == ".option")
@@ -2622,7 +2618,7 @@
if (IDVal == ".variant_cc")
return parseDirectiveVariantCC();
- return true;
+ return ParseStatus::NoMatch;
}
bool RISCVAsmParser::resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
@@ -2864,10 +2860,8 @@
StringRef Name = Parser.getTok().getIdentifier();
std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, RISCVAttrs::getRISCVAttributeTags());
- if (!Ret) {
- Error(TagLoc, "attribute name not recognised: " + Name);
- return false;
- }
+ if (!Ret)
+ return Error(TagLoc, "attribute name not recognised: " + Name);
Tag = *Ret;
Parser.Lex();
} else {
@@ -2978,7 +2972,7 @@
if (getParser().parseIdentifier(Name))
return TokError("expected symbol name");
if (parseEOL())
- return false;
+ return true;
getTargetStreamer().emitDirectiveVariantCC(
*getContext().getOrCreateSymbol(Name));
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154276.536497.patch
Type: text/x-patch
Size: 2910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230701/cce0f83d/attachment.bin>
More information about the llvm-commits
mailing list