Skip to content

Commit d7398a3

Browse files
committed
[MC] Use reportError for .uleb128/.sleb128 diagnostic
User errors should use reportError. reportError allows us to continue parsing the file and collect more diagnostics. MC/ELF/leb128-err.s is adapted from MC/RISCV/riscv64-64b-pcrel.s
1 parent 2b5b2bf commit d7398a3

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,11 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
10091009
uint64_t OldSize = LF.getContents().size();
10101010
int64_t Value;
10111011
bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout);
1012-
if (!Abs)
1013-
report_fatal_error("sleb128 and uleb128 expressions must be absolute");
1012+
if (!Abs) {
1013+
getContext().reportError(LF.getValue().getLoc(),
1014+
Twine(LF.isSigned() ? ".s" : ".u") +
1015+
"leb128 expression is not absolute");
1016+
}
10141017
SmallString<8> &Data = LF.getContents();
10151018
Data.clear();
10161019
raw_svector_ostream OSE(Data);

llvm/test/MC/ELF/leb128-err.s

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
2+
3+
.section .alloc_w,"aw",@progbits; w:
4+
# CHECK: :[[#@LINE+1]]:16: error: .uleb128 expression is not absolute
5+
.uleb128 extern-w # extern is undefined
6+
# CHECK: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
7+
.uleb128 w-extern
8+
# CHECK: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute
9+
.uleb128 x-w # x is later defined in another section
10+
.uleb128 w1-w # w1 is later defined in the same section
11+
w1:
12+
13+
.section .alloc_x,"aw",@progbits; x:
14+
# CHECK: :[[#@LINE+1]]:11: error: .sleb128 expression is not absolute
15+
.sleb128 y-x
16+
.section .alloc_y,"aw",@progbits; y:
17+
# CHECK: :[[#@LINE+1]]:11: error: .sleb128 expression is not absolute
18+
.sleb128 x-y
19+
20+
.section .nonalloc_x; nx:
21+
# CHECK: :[[#@LINE+1]]:12: error: .sleb128 expression is not absolute
22+
.sleb128 ny-nx
23+
.section .nonalloc_y; ny:
24+
# CHECK: :[[#@LINE+1]]:12: error: .sleb128 expression is not absolute
25+
.sleb128 nx-ny

llvm/test/MC/X86/invalid-sleb.s

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)