[llvm] acf81a8 - [MC] Flush pending errors when layout stops early due to relaxOnce error (#226028)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 23:07:41 PDT 2026


Author: Fangrui Song
Date: 2026-09-23T23:07:35-07:00
New Revision: acf81a81386f88305b346798ef36b4e276c74f82

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

LOG: [MC] Flush pending errors when layout stops early due to relaxOnce error (#226028)

When relaxOnce returns nonzero after an error has been reported,
layout() returns without flushing the errors recorded by the last
relaxation pass, and Finish() fails `assert(PendingErrors.empty())`.

Fixes #225036

Added: 
    

Modified: 
    llvm/lib/MC/MCAssembler.cpp
    llvm/test/MC/ELF/leb128-err.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index fcdcdbc96426f..db4aa48138e04 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -701,9 +701,12 @@ void MCAssembler::layout() {
   for (MCSection &Sec : *this)
     layoutSection(Sec);
   unsigned FirstStable = Sections.size();
-  while ((FirstStable = relaxOnce(FirstStable)) > 0)
-    if (getContext().hadError())
+  while ((FirstStable = relaxOnce(FirstStable)) > 0) {
+    if (getContext().hadError()) {
+      flushPendingErrors();
       return;
+    }
+  }
 
   // Some targets might want to adjust fragment offsets. If so, perform another
   // layout iteration.

diff  --git a/llvm/test/MC/ELF/leb128-err.s b/llvm/test/MC/ELF/leb128-err.s
index e6a7329372a95..41200c2f864f5 100644
--- a/llvm/test/MC/ELF/leb128-err.s
+++ b/llvm/test/MC/ELF/leb128-err.s
@@ -23,3 +23,8 @@ w1:
 .section .nonalloc_y; ny:
 # CHECK: :[[#@LINE+1]]:12: error: .sleb128 expression is not absolute
 .sleb128 nx-ny
+
+## We also report errors from non-LEB128 fragments.
+.data
+# CHECK: :[[#@LINE+1]]:8: error: expected assembly-time absolute expression
+.space extern


        


More information about the llvm-commits mailing list