[llvm] d7398a3 - [MC] Use reportError for .uleb128/.sleb128 diagnostic

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 17:32:13 PDT 2023


Author: Fangrui Song
Date: 2023-08-09T17:32:09-07:00
New Revision: d7398a355461b3a9f1685b0d2bf42c157b159e8f

URL: https://github.com/llvm/llvm-project/commit/d7398a355461b3a9f1685b0d2bf42c157b159e8f
DIFF: https://github.com/llvm/llvm-project/commit/d7398a355461b3a9f1685b0d2bf42c157b159e8f.diff

LOG: [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

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

Modified: 
    llvm/lib/MC/MCAssembler.cpp

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


################################################################################
diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 55ed1a285cd735..1cc408e11447e1 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 00000000000000..e6a7329372a95e
--- /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", at 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", at progbits; x:
+# CHECK: :[[#@LINE+1]]:11: error: .sleb128 expression is not absolute
+.sleb128 y-x
+.section .alloc_y,"aw", at 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 7d7df351ce4e24..00000000000000
--- 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


        


More information about the llvm-commits mailing list