Skip to content

Commit e3d658b

Browse files
committed
PR13754: llvm-mc/x86 crashes on .cfi directives without the % prefix for registers.
gas accepts this and it seems to be common enough to be worth supporting. This doesn't affect the parsing of reg operands outside of .cfi directives. llvm-svn: 163390
1 parent c337b82 commit e3d658b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,13 @@ bool X86AsmParser::isDstOp(X86Operand &Op) {
521521
bool X86AsmParser::ParseRegister(unsigned &RegNo,
522522
SMLoc &StartLoc, SMLoc &EndLoc) {
523523
RegNo = 0;
524-
if (!isParsingIntelSyntax()) {
525-
const AsmToken &TokPercent = Parser.getTok();
526-
assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
527-
StartLoc = TokPercent.getLoc();
524+
const AsmToken &PercentTok = Parser.getTok();
525+
StartLoc = PercentTok.getLoc();
526+
527+
// If we encounter a %, ignore it. This code handles registers with and
528+
// without the prefix, unprefixed registers can occur in cfi directives.
529+
if (!isParsingIntelSyntax() && PercentTok.is(AsmToken::Percent))
528530
Parser.Lex(); // Eat percent token.
529-
}
530531

531532
const AsmToken &Tok = Parser.getTok();
532533
if (Tok.isNot(AsmToken::Identifier)) {

llvm/test/MC/ELF/cfi-reg.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: llvm-mc -triple x86_64-pc-linux-gnu %s -o - | FileCheck %s
2+
// PR13754
3+
4+
f:
5+
.cfi_startproc
6+
nop
7+
.cfi_offset 6, -16
8+
nop
9+
.cfi_offset %rsi, -16
10+
nop
11+
.cfi_offset rbx, -16
12+
nop
13+
.cfi_endproc
14+
15+
// CHECK: f:
16+
// CHECK: .cfi_offset %rbp, -16
17+
// CHECK: .cfi_offset %rsi, -16
18+
// CHECK: .cfi_offset %rbx, -16

0 commit comments

Comments
 (0)