Skip to content

Commit 1edb6b0

Browse files
committed
[RISCV] Fix crash in parseZcmpStackAdj if token is not an integer.
1 parent c57b9c2 commit 1edb6b0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,11 @@ ParseStatus RISCVAsmParser::parseZcmpStackAdj(OperandVector &Operands,
26762676
bool Negative = parseOptionalToken(AsmToken::Minus);
26772677

26782678
SMLoc S = getLoc();
2679-
int64_t StackAdjustment = getLexer().getTok().getIntVal();
2679+
2680+
if (getTok().isNot(AsmToken::Integer))
2681+
return ParseStatus::NoMatch;
2682+
2683+
int64_t StackAdjustment = getTok().getIntVal();
26802684
unsigned RlistVal = static_cast<RISCVOperand *>(Operands[1].get())->Rlist.Val;
26812685

26822686
assert(RlistVal != RISCVZC::INVALID_RLIST);
@@ -2697,7 +2701,7 @@ ParseStatus RISCVAsmParser::parseZcmpStackAdj(OperandVector &Operands,
26972701

26982702
unsigned Spimm = (StackAdjustment - StackAdjBase) / 16;
26992703
Operands.push_back(RISCVOperand::createSpimm(Spimm << 4, S));
2700-
getLexer().Lex();
2704+
Lex();
27012705
return ParseStatus::Success;
27022706
}
27032707

llvm/test/MC/RISCV/rv64zcmp-invalid.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ cm.pop {ra, x8-x9, x18-x17}, -40
4848

4949
# CHECK-ERROR: :[[@LINE+1]]:16: error: invalid register
5050
cm.pop {ra, x8-f8, x18-x17}, -40
51+
52+
# CHECK-ERROR: :[[@LINE+1]]:15: error: stack adjustment is invalid for this instruction and register list
53+
cm.pop {ra}, -x1
54+
55+
# CHECK-ERROR: :[[@LINE+1]]:15: error: stack adjustment is invalid for this instruction and register list
56+
cm.push {ra}, x1

0 commit comments

Comments
 (0)