[llvm] [X86] Fix COFF _fltused early return skipping __morestack_addr emission (PR #204569)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 22:54:38 PDT 2026


https://github.com/ayrai-gb updated https://github.com/llvm/llvm-project/pull/204569

>From a3d14ae8e72ef181cf879814421caa1458487281 Mon Sep 17 00:00:00 2001
From: Ayush Rai <your-email at amd.com>
Date: Thu, 18 Jun 2026 17:44:37 +0530
Subject: [PATCH] [X86] Fix COFF _fltused early return skipping
 __morestack_addr

---
 llvm/lib/Target/X86/X86AsmPrinter.cpp         |  1 -
 .../X86/coff-fltused-morestack-largecode.ll   | 27 +++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/X86/coff-fltused-morestack-largecode.ll

diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 6d213b8c213aa..40efe9250c09c 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -1117,7 +1117,6 @@ void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
           (TT.getArch() == Triple::x86) ? "__fltused" : "_fltused";
       MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
       OutStreamer->emitSymbolAttribute(S, MCSA_Global);
-      return;
     }
   } else if (TT.isOSBinFormatELF()) {
     FM.serializeToFaultMapSection();
diff --git a/llvm/test/CodeGen/X86/coff-fltused-morestack-largecode.ll b/llvm/test/CodeGen/X86/coff-fltused-morestack-largecode.ll
new file mode 100644
index 0000000000000..09068c2ca01a8
--- /dev/null
+++ b/llvm/test/CodeGen/X86/coff-fltused-morestack-largecode.ll
@@ -0,0 +1,27 @@
+; RUN: llc -mtriple=x86_64-pc-windows-msvc -code-model=large < %s | FileCheck %s
+
+;; On a COFF/MSVC target built with the large code model and split stacks, the
+;; prologue calls __morestack indirectly through the __morestack_addr data slot,
+;; whose definition is emitted at the end of the file by
+;; X86AsmPrinter::emitEndOfAsmFile. When the program also uses floating point,
+;; the same routine emits the _fltused marker. emitEndOfAsmFile used to `return`
+;; right after emitting _fltused, which skipped the trailing __morestack_addr
+;; definition -- leaving the indirect call referencing an undefined symbol.
+;;
+;; Both the _fltused marker and the __morestack_addr definition must be emitted.
+
+; CHECK: callq *__morestack_addr(%rip)
+; CHECK: .globl{{.*}}_fltused
+; CHECK: __morestack_addr:
+; CHECK-NEXT: .quad{{.*}}__morestack
+
+declare void @use(ptr)
+
+define double @f(double %a, double %b) #0 {
+  %buf = alloca [4096 x i8]
+  call void @use(ptr %buf)
+  %r = fadd double %a, %b
+  ret double %r
+}
+
+attributes #0 = { "split-stack" }



More information about the llvm-commits mailing list