[llvm] [DirectX] Fix DILocalVariable (PR #192573)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 16:57:00 PDT 2026


https://github.com/hvdijk created https://github.com/llvm/llvm-project/pull/192573

LLVM 3.7 did not allow the DW_TAG_variable tag for them and had two custom tags instead.

>From f877117fc14ce46664ad2766f8069e7fe19e889b Mon Sep 17 00:00:00 2001
From: Harald van Dijk <hdijk at accesssoftek.com>
Date: Thu, 5 Mar 2026 19:40:01 +0000
Subject: [PATCH] [DirectX] Fix DILocalVariable

LLVM 3.7 did not allow the DW_TAG_variable tag for them and had two
custom tags instead.
---
 llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp | 6 +++++-
 llvm/test/tools/dxil-dis/debug-info.ll                   | 6 +++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 9220a8b163aaf..cc19335c70618 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -14,6 +14,7 @@
 #include "DXILValueEnumerator.h"
 #include "DirectXIRPasses/PointerTypeAnalysis.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Bitcode/BitcodeCommon.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
@@ -1657,8 +1658,11 @@ void DXILBitcodeWriter::writeDIGlobalVariable(const DIGlobalVariable *N,
 void DXILBitcodeWriter::writeDILocalVariable(const DILocalVariable *N,
                                              SmallVectorImpl<uint64_t> &Record,
                                              unsigned Abbrev) {
+  constexpr unsigned DW_TAG_auto_variable = 0x0100;
+  constexpr unsigned DW_TAG_arg_variable = 0x0101;
   Record.push_back(N->isDistinct());
-  Record.push_back(N->getTag());
+  assert(N->getTag() == dwarf::DW_TAG_variable);
+  Record.push_back(N->getArg() ? DW_TAG_arg_variable : DW_TAG_auto_variable);
   Record.push_back(VE.getMetadataOrNullID(N->getScope()));
   Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
   Record.push_back(VE.getMetadataOrNullID(N->getFile()));
diff --git a/llvm/test/tools/dxil-dis/debug-info.ll b/llvm/test/tools/dxil-dis/debug-info.ll
index f96edca223b20..4657c16f84d4c 100644
--- a/llvm/test/tools/dxil-dis/debug-info.ll
+++ b/llvm/test/tools/dxil-dis/debug-info.ll
@@ -35,9 +35,9 @@ attributes #0 = { norecurse nounwind readnone willreturn "hlsl.export" }
 ; CHECK:      !0 = distinct !DICompileUnit
 ; CHECK-NEXT: !1 = !DIFile(filename:
 ; CHECK:      [[Fn]] = distinct !DISubprogram(name: "fma",
-; CHECK:      [[VarX]] = !DILocalVariable(tag:
-; CHECK:      [[VarY]] = !DILocalVariable(tag:
-; CHECK:      [[VarZ]] = !DILocalVariable(tag:
+; CHECK:      [[VarX]] = !DILocalVariable(tag: DW_TAG_arg_variable
+; CHECK:      [[VarY]] = !DILocalVariable(tag: DW_TAG_arg_variable
+; CHECK:      [[VarZ]] = !DILocalVariable(tag: DW_TAG_arg_variable
 ; CHECK-NEXT: [[Expr]] = !DIExpression()
 ; CHECK-NEXT: [[Line1]] = !DILocation(line:
 ; CHECK-NEXT: [[Line2]] = !DILocation(line:



More information about the llvm-commits mailing list