[llvm] [DirectX] Replace DISubrangeType with DIBasicType (PR #197471)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Tue May 19 13:49:27 PDT 2026


https://github.com/hvdijk updated https://github.com/llvm/llvm-project/pull/197471

>From 21edbbbfadd0326c6a60201de852f39666ce4b80 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <hdijk at accesssoftek.com>
Date: Thu, 19 Mar 2026 02:26:23 +0000
Subject: [PATCH 1/2] [DirectX] Replace DISubrangeType with DIBasicType

DISubrangeType did not exist in LLVM 3.7.
---
 .../DirectX/DirectXIRPasses/DXILDebugInfo.cpp | 12 +++++++
 llvm/test/tools/dxil-dis/di-subrangetype.ll   | 34 +++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 llvm/test/tools/dxil-dis/di-subrangetype.ll

diff --git a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
index 923e2b531933a..b57aa65123c7f 100644
--- a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
@@ -71,5 +71,17 @@ DXILDebugInfoMap DXILDebugInfoPass::run(Module &M) {
     Res.MDExtra.insert({NewCU, SubprogramsMD});
   }
 
+  for (auto *T : DIF.types()) {
+    if (auto *SR = dyn_cast<DISubrangeType>(T)) {
+      auto *BT = SR->getBaseType();
+      if (!BT)
+        BT = DIBasicType::get(
+            SR->getContext(), dwarf::DW_TAG_base_type, SR->getName(),
+            SR->getSizeInBits(), SR->getAlignInBits(), dwarf::DW_ATE_unsigned,
+            SR->getNumExtraInhabitants(), /*DataSizeInBits=*/0, SR->getFlags());
+      Res.MDReplace.insert({T, BT});
+    }
+  }
+
   return Res;
 }
diff --git a/llvm/test/tools/dxil-dis/di-subrangetype.ll b/llvm/test/tools/dxil-dis/di-subrangetype.ll
new file mode 100644
index 0000000000000..8d4199d4ab28d
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/di-subrangetype.ll
@@ -0,0 +1,34 @@
+; RUN: llc --filetype=obj %s -o - | dxil-dis -o - | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-library"
+
+define void @sr() !dbg !7 {
+  unreachable
+}
+
+; CHECK-DAG: !llvm.dbg.cu = !{[[CU:![0-9]+]]}
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6}
+
+; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_Ada95, file: [[F:![0-9]+]], producer: "GNAT/LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: 1, retainedTypes: [[TS:![0-9]+]], subprograms: [[SPS:![0-9]+]])
+; CHECK-DAG: [[F]] = !DIFile(filename: "subrange_type.adb", directory: "/dir")
+; CHECK-DAG: [[TS]] = !{[[T:![0-9]+]]}
+; CHECK-DAG: [[T]] = !DIBasicType(name: "sr__Tint_rangeB", size: 32, encoding: DW_ATE_signed)
+; CHECK-DAG: [[SPS]] = !{[[SP:![0-9]+]]}
+; CHECK-DAG: [[SP]] = distinct !DISubprogram(name: "sr", scope: !1, file: !1, line: 1, type: [[ST:![0-9]+]], isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, function: void ()* @sr, variables: [[VS:![0-9]+]])
+; CHECK-DAG: [[ST]] = !DISubroutineType
+; CHECK-DAG: [[VS]] = !{[[V:![0-9]+]]}
+; CHECK-DAG: [[V]] = !DILocalVariable(tag: DW_TAG_auto_variable, name: "x", scope: [[SP]], file: [[F]], line: 3, type: [[T]])
+
+!0 = distinct !DICompileUnit(language: DW_LANG_Ada95, file: !1, producer: "GNAT/LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2)
+!1 = !DIFile(filename: "subrange_type.adb", directory: "/dir")
+!2 = !{!3}
+!3 = !DISubrangeType(name: "sr__int_range", file: !1, line: 2, size: 32, align: 32, baseType: !4, lowerBound: i64 -7, upperBound: i64 23)
+!4 = !DIBasicType(name: "sr__Tint_rangeB", size: 32, encoding: DW_ATE_signed)
+!5 = !{i32 2, !"Debug Info Version", i32 3}
+!6 = !{i32 2, !"Dwarf Version", i32 4}
+!7 = distinct !DISubprogram(name: "sr", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 3, type: !3, align: 32)

>From 4582d0deddd895e44b98cf44c48df24337c7da77 Mon Sep 17 00:00:00 2001
From: Harald van Dijk <harald at gigawatt.nl>
Date: Tue, 19 May 2026 21:49:17 +0100
Subject: [PATCH 2/2] Apply suggestion from @bogner

Co-authored-by: Justin Bogner <mail at justinbogner.com>
---
 llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
index b57aa65123c7f..bac1b22f400bc 100644
--- a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
@@ -71,9 +71,9 @@ DXILDebugInfoMap DXILDebugInfoPass::run(Module &M) {
     Res.MDExtra.insert({NewCU, SubprogramsMD});
   }
 
-  for (auto *T : DIF.types()) {
+  for (DIType *T : DIF.types()) {
     if (auto *SR = dyn_cast<DISubrangeType>(T)) {
-      auto *BT = SR->getBaseType();
+      DIType *BT = SR->getBaseType();
       if (!BT)
         BT = DIBasicType::get(
             SR->getContext(), dwarf::DW_TAG_base_type, SR->getName(),



More information about the llvm-commits mailing list