[llvm] db1d72b - [RISCV] Don't persist invalid feature state on .option arch error

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 12:15:30 PDT 2023


Author: Jessica Clarke
Date: 2023-06-06T20:15:12+01:00
New Revision: db1d72b155c65df26980f6113cb5961c3c706a81

URL: https://github.com/llvm/llvm-project/commit/db1d72b155c65df26980f6113cb5961c3c706a81
DIFF: https://github.com/llvm/llvm-project/commit/db1d72b155c65df26980f6113cb5961c3c706a81.diff

LOG: [RISCV] Don't persist invalid feature state on .option arch error

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

Added: 
    

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

Removed: 
    


################################################################################
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
 


        


More information about the llvm-commits mailing list