diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/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 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; diff --git a/llvm/test/MC/RISCV/invalid-attribute.s b/llvm/test/MC/RISCV/invalid-attribute.s --- a/llvm/test/MC/RISCV/invalid-attribute.s +++ b/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}