[RISCV] Don't persist invalid feature state on .option arch error
authorJessica Clarke <jrtc27@jrtc27.com>
Tue, 6 Jun 2023 19:14:20 +0000 (20:14 +0100)
committerJessica Clarke <jrtc27@jrtc27.com>
Tue, 6 Jun 2023 19:15:12 +0000 (20:15 +0100)
Otherwise subsequent .option arch, +foo directives (but not -, since
those have their own separate validation) fail the parseFeatureBits
check, leading to cascading errors.

Reviewed By: luismarques, MaskRay

Differential Revision: https://reviews.llvm.org/D152273

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/test/MC/RISCV/option-invalid.s

index 3baff0e..ad89ee3 100644 (file)
@@ -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) {
index 34d6ada..683ebc4 100644 (file)
@@ -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