[Mlir-commits] [mlir] ee7f51a - Fix recursive DI variant part (#225373)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Sep 22 07:02:08 PDT 2026


Author: purnima shrivastava
Date: 2026-09-22T16:02:02+02:00
New Revision: ee7f51a7d00f05662716d20e451c9c25c0fe79ee

URL: https://github.com/llvm/llvm-project/commit/ee7f51a7d00f05662716d20e451c9c25c0fe79ee
DIFF: https://github.com/llvm/llvm-project/commit/ee7f51a7d00f05662716d20e451c9c25c0fe79ee.diff

LOG: Fix recursive DI variant part (#225373)

`mlir::translateModuleToLLVMIR` could leave recursive `DICompositeType`
metadata unresolved when the composite used `DW_TAG_variant_part`.

`DW_TAG_variant_part` was not emitted as a distinct `DICompositeType`,
unlike other recursive composite type tags. This change adds it to the
distinct path and adds a regression test covering the recursive
variant-part case.

Testing:

* `mlir/test/Target/LLVMIR/llvmir-debug.mlir`
* `ninja -C build check-mlir`

Fixes: #225151

Co-authored-by: Purnima Shrivastava <purnimashrivastava05 at .com>

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/DebugTranslation.cpp
    mlir/test/Target/LLVMIR/llvmir-debug.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 3ac2ccd506df3..87e00976c0f6c 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -245,6 +245,7 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
   case llvm::dwarf::DW_TAG_enumeration_type:
   case llvm::dwarf::DW_TAG_structure_type:
   case llvm::dwarf::DW_TAG_union_type:
+  case llvm::dwarf::DW_TAG_variant_part:
     isDistinct = true;
   }
 

diff  --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 27858cc008956..8b8124ccd1c81 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -942,3 +942,25 @@ llvm.func @variant_part_emission(%arg0: i32) {
   llvm.intr.dbg.value #di_local = %arg0 : i32 loc(#loc)
   llvm.return loc(#loc)
 } loc(#loc)
+
+// -----
+
+// CHECK-LABEL: define void @recursive_variant_part
+// CHECK: ![[VARIANT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_variant_part, elements: ![[ELEMENTS:[0-9]+]])
+// CHECK: ![[ELEMENTS]] = !{![[MEMBER:[0-9]+]]}
+// CHECK: ![[MEMBER]] = !DIDerivedType(tag: DW_TAG_member, scope: ![[VARIANT]], baseType: null)
+
+#recursive_variant_file = #llvm.di_file<"a.rs" in "">
+#recursive_variant_self = #llvm.di_composite_type<recId = distinct[106]<>, isRecSelf = true>
+#recursive_variant_member = #llvm.di_derived_type<tag = DW_TAG_member, scope = #recursive_variant_self>
+#recursive_variant_type = #llvm.di_composite_type<recId = distinct[106]<>, tag = DW_TAG_variant_part, elements = #recursive_variant_member>
+#recursive_variant_subroutine = #llvm.di_subroutine_type<types = #recursive_variant_type>
+#recursive_variant_cu = #llvm.di_compile_unit<id = distinct[107]<>, sourceLanguage = DW_LANG_C, file = #recursive_variant_file, emissionKind = Full>
+#recursive_variant_sp = #llvm.di_subprogram<id = distinct[108]<>, compileUnit = #recursive_variant_cu, file = #recursive_variant_file, subprogramFlags = "Definition", type = #recursive_variant_subroutine>
+#recursive_variant_loc = loc(fused<#recursive_variant_sp>[unknown])
+
+module {
+  llvm.func @recursive_variant_part() {
+    llvm.return
+  } loc(#recursive_variant_loc)
+}


        


More information about the Mlir-commits mailing list