[llvm-branch-commits] [llvm] ee2b7a2 - [AsmPrinter] Emit null pointer vector splats as zero bytes (#235980)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 8 06:42:51 PST 2026


Author: zhouguangyuan0718
Date: 2026-11-08T15:42:11+01:00
New Revision: ee2b7a24769e5ede2784c71dff3f40d8486a758e

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

LOG: [AsmPrinter] Emit null pointer vector splats as zero bytes (#235980)

Emitting a global such as `@x = global <2 x ptr> zeroinitializer` with
`llc -data-sections -filetype=obj` asserts on 64-bit targets.
`ConstantPointerNull` can represent a vector splat since #195486, but
AsmPrinter passes the entire allocation size to
`MCStreamer::emitIntValue`, which accepts at most eight bytes.

Route pointer-vector splats through `emitGlobalConstantVector`, matching
the existing handling of integer and floating-point splats. Its
zero-value path emits the full allocation with `emitZeros`. Keep scalar
pointers on the existing `emitIntValue` path.

Fixes #235977

Assisted-by: OpenAI Codex
(cherry picked from commit fed20e0e68323be32cb0fe8af679b8cb34e72112)

Added: 
    llvm/test/CodeGen/X86/null-pointer-vector-object.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index f3ac25f25fcc14..1a9c3e7114fdb6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -4532,6 +4532,8 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
   }
 
   if (isa<ConstantPointerNull>(CV)) {
+    if (isa<VectorType>(CV->getType()))
+      return emitGlobalConstantVector(DL, CV, AP, AliasList);
     AP.OutStreamer->emitIntValue(0, Size);
     return;
   }

diff  --git a/llvm/test/CodeGen/X86/null-pointer-vector-object.ll b/llvm/test/CodeGen/X86/null-pointer-vector-object.ll
new file mode 100644
index 00000000000000..3e861cdc31b501
--- /dev/null
+++ b/llvm/test/CodeGen/X86/null-pointer-vector-object.ll
@@ -0,0 +1,20 @@
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -data-sections -filetype=obj %s -o %t.64
+; RUN: llvm-readobj --symbols %t.64 | FileCheck %s --check-prefixes=CHECK,ELF64
+; RUN: llc -mtriple=i686-unknown-linux-gnu -data-sections -filetype=obj %s -o %t.32
+; RUN: llvm-readobj --symbols %t.32 | FileCheck %s --check-prefixes=CHECK,ELF32
+; RUN: llc -mtriple=x86_64-pc-windows-msvc -data-sections -filetype=obj %s -o /dev/null
+
+; Both spellings of a null pointer vector use ConstantPointerNull. Its size
+; can exceed the eight-byte limit of MCStreamer::emitIntValue. Check successful
+; object emission for ELF and COFF, and symbol sizes and BSS placement for ELF.
+ at v2 = global <2 x ptr> zeroinitializer
+ at v4 = global <4 x ptr> splat (ptr null)
+
+; CHECK:      Name: v2
+; ELF64:      Size: 16
+; ELF32:      Size: 8
+; CHECK:      Section: .bss.v2
+; CHECK:      Name: v4
+; ELF64:      Size: 32
+; ELF32:      Size: 16
+; CHECK:      Section: .bss.v4


        


More information about the llvm-branch-commits mailing list