[llvm-branch-commits] [llvm] release/23.x: [AsmPrinter] Emit null pointer vector splats as zero bytes (#235980) (PR #238262)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 3 01:46:36 PST 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/238262
Backport fed20e0e68323be32cb0fe8af679b8cb34e72112
Requested by: @nikic
>From fb2f7a9cb9ae8b96a384a8ff5315efe4ec5e2963 Mon Sep 17 00:00:00 2001
From: zhouguangyuan0718 <zhouguangyuan.xian at gmail.com>
Date: Tue, 3 Nov 2026 04:11:06 -0500
Subject: [PATCH] [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)
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 ++
.../CodeGen/X86/null-pointer-vector-object.ll | 20 +++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 llvm/test/CodeGen/X86/null-pointer-vector-object.ll
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