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 @@ -2758,9 +2758,14 @@ 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 --- a/llvm/test/MC/RISCV/option-invalid.s +++ b/llvm/test/MC/RISCV/option-invalid.s @@ -47,6 +47,10 @@ # CHECK: :[[#@LINE+1]]:20: error: 'f' and 'zfinx' extensions are incompatible .option arch, +f, +zfinx +## Make sure the above error isn't sticky +# CHECK-NOT: :[[#@LINE+1]]: +.option arch, +f + # CHECK: :[[#@LINE+1]]:13: error: expected newline .option rvc foo