diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 3baff0e688b86..ad89ee347fa3c 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -2758,9 +2758,14 @@ bool RISCVAsmParser::parseDirectiveOption() { Args.emplace_back(Type, Ext->Key); if (Type == RISCVOptionArchArgType::Plus) { + FeatureBitset OldFeatureBits = STI->getFeatureBits(); + setFeatureBits(Ext->Value, Ext->Key); auto ParseResult = RISCVFeatures::parseFeatureBits(isRV64(), STI->getFeatureBits()); if (!ParseResult) { + copySTI().setFeatureBits(OldFeatureBits); + setAvailableFeatures(ComputeAvailableFeatures(OldFeatureBits)); + std::string Buffer; raw_string_ostream OutputErrMsg(Buffer); handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) { diff --git a/llvm/test/MC/RISCV/option-invalid.s b/llvm/test/MC/RISCV/option-invalid.s index 34d6adabbb093..683ebc4f5b992 100644 --- a/llvm/test/MC/RISCV/option-invalid.s +++ b/llvm/test/MC/RISCV/option-invalid.s @@ -1,5 +1,5 @@ # RUN: not llvm-mc -triple riscv32 < %s 2>&1 \ -# RUN: | FileCheck -check-prefixes=CHECK %s +# RUN: | FileCheck --implicit-check-not=error: %s # CHECK: :[[#@LINE+1]]:8: error: expected identifier .option @@ -47,6 +47,9 @@ # CHECK: :[[#@LINE+1]]:20: error: 'f' and 'zfinx' extensions are incompatible .option arch, +f, +zfinx +## Make sure the above error isn't sticky +.option arch, +f + # CHECK: :[[#@LINE+1]]:13: error: expected newline .option rvc foo