Skip to content

Commit

Permalink
[RISCV] Don't persist invalid feature state on .option arch error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrtc27 committed Jun 6, 2023
1 parent 4426827 commit db1d72b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion llvm/test/MC/RISCV/option-invalid.s
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit db1d72b

Please sign in to comment.