diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 55ed1a285cd73..1cc408e11447e 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1009,8 +1009,11 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) { uint64_t OldSize = LF.getContents().size(); int64_t Value; bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout); - if (!Abs) - report_fatal_error("sleb128 and uleb128 expressions must be absolute"); + if (!Abs) { + getContext().reportError(LF.getValue().getLoc(), + Twine(LF.isSigned() ? ".s" : ".u") + + "leb128 expression is not absolute"); + } SmallString<8> &Data = LF.getContents(); Data.clear(); raw_svector_ostream OSE(Data); diff --git a/llvm/test/MC/ELF/leb128-err.s b/llvm/test/MC/ELF/leb128-err.s new file mode 100644 index 0000000000000..e6a7329372a95 --- /dev/null +++ b/llvm/test/MC/ELF/leb128-err.s @@ -0,0 +1,25 @@ +# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error: + +.section .alloc_w,"aw",@progbits; w: +# CHECK: :[[#@LINE+1]]:16: error: .uleb128 expression is not absolute +.uleb128 extern-w # extern is undefined +# CHECK: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute +.uleb128 w-extern +# CHECK: :[[#@LINE+1]]:11: error: .uleb128 expression is not absolute +.uleb128 x-w # x is later defined in another section +.uleb128 w1-w # w1 is later defined in the same section +w1: + +.section .alloc_x,"aw",@progbits; x: +# CHECK: :[[#@LINE+1]]:11: error: .sleb128 expression is not absolute +.sleb128 y-x +.section .alloc_y,"aw",@progbits; y: +# CHECK: :[[#@LINE+1]]:11: error: .sleb128 expression is not absolute +.sleb128 x-y + +.section .nonalloc_x; nx: +# CHECK: :[[#@LINE+1]]:12: error: .sleb128 expression is not absolute +.sleb128 ny-nx +.section .nonalloc_y; ny: +# CHECK: :[[#@LINE+1]]:12: error: .sleb128 expression is not absolute +.sleb128 nx-ny diff --git a/llvm/test/MC/X86/invalid-sleb.s b/llvm/test/MC/X86/invalid-sleb.s deleted file mode 100644 index 7d7df351ce4e2..0000000000000 --- a/llvm/test/MC/X86/invalid-sleb.s +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: not --crash llvm-mc -filetype=obj -triple x86_64-pc-linux %s -o %t 2>&1 | FileCheck %s - -// CHECK: sleb128 and uleb128 expressions must be absolute - - .sleb128 undefined