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

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 16:57:32 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-directx

Author: Harald van Dijk (hvdijk)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/192573.diff


2 Files Affected:

- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+5-1) 
- (modified) llvm/test/tools/dxil-dis/debug-info.ll (+3-3) 


``````````diff
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:

``````````

</details>


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


More information about the llvm-commits mailing list