[llvm] LoongArch: Register a null target streamer (PR #226497)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 06:47:19 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/226497

Emitting a TLS variable's debug location calls into the target streamer,
which was only registered for asm and object output. -filetype=null
therefore null dereferenced.

Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>

>From 09f627046887fd99b4784a6ecd73eef946ea166a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 25 Sep 2026 15:33:07 +0200
Subject: [PATCH] LoongArch: Register a null target streamer

Emitting a TLS variable's debug location calls into the target streamer,
which was only registered for asm and object output. -filetype=null
therefore null dereferenced.

Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>
---
 .../MCTargetDesc/LoongArchMCTargetDesc.cpp    |  6 ++++++
 llvm/test/CodeGen/LoongArch/null-streamer.ll  | 20 +++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 llvm/test/CodeGen/LoongArch/null-streamer.ll

diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp
index 741bc27eff386d..10b3ddafcbe9f8 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCTargetDesc.cpp
@@ -93,6 +93,10 @@ createLoongArchAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS,
   return new LoongArchTargetAsmStreamer(S, OS);
 }
 
+static MCTargetStreamer *createLoongArchNullTargetStreamer(MCStreamer &S) {
+  return new LoongArchTargetStreamer(S);
+}
+
 namespace {
 
 class LoongArchMCInstrAnalysis : public MCInstrAnalysis {
@@ -301,5 +305,7 @@ LLVMInitializeLoongArchTargetMC() {
         *T, createLoongArchObjectTargetStreamer);
     TargetRegistry::RegisterAsmTargetStreamer(*T,
                                               createLoongArchAsmTargetStreamer);
+    TargetRegistry::RegisterNullTargetStreamer(
+        *T, createLoongArchNullTargetStreamer);
   }
 }
diff --git a/llvm/test/CodeGen/LoongArch/null-streamer.ll b/llvm/test/CodeGen/LoongArch/null-streamer.ll
new file mode 100644
index 00000000000000..0a1d65af0c33b3
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/null-streamer.ll
@@ -0,0 +1,20 @@
+; Check the MCNullStreamer operates correctly. The TLS debug
+; expression below reaches the target streamer
+;
+; RUN: llc -O0 -mtriple=loongarch32 -filetype=null %s
+; RUN: llc -O0 -mtriple=loongarch64 -filetype=null %s
+
+ at x = thread_local global i32 5, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "tls.c", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 2, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}



More information about the llvm-commits mailing list