Skip to content

Commit dffb213

Browse files
committed
allow nested rec-decl
1 parent 11ba5d4 commit dffb213

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,15 @@ DebugTranslation::translateImpl(DIGlobalVariableAttr attr) {
216216
llvm::DIType *
217217
DebugTranslation::translateRecursive(DIRecursiveTypeAttrInterface attr) {
218218
DistinctAttr recursiveId = attr.getRecId();
219-
if (attr.isRecSelf()) {
220-
auto *iter = recursiveTypeMap.find(recursiveId);
221-
assert(iter != recursiveTypeMap.end() && "unbound DI recursive self type");
219+
if (auto *iter = recursiveTypeMap.find(recursiveId);
220+
iter != recursiveTypeMap.end()) {
222221
return iter->second;
222+
} else {
223+
assert(!attr.isRecSelf() && "unbound DI recursive self type");
223224
}
224225

225226
auto setRecursivePlaceholder = [&](llvm::DIType *placeholder) {
226-
[[maybe_unused]] auto [iter, inserted] =
227-
recursiveTypeMap.try_emplace(recursiveId, placeholder);
228-
(void)iter;
229-
(void)inserted;
230-
assert(inserted && "illegal reuse of recursive id");
227+
recursiveTypeMap.try_emplace(recursiveId, placeholder);
231228
};
232229

233230
llvm::DIType *result =

mlir/test/Target/LLVMIR/llvmir-debug.mlir

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,31 @@ llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression}
423423
// CHECK: ![[SCOPE]] = !DISubprogram({{.*}}type: ![[SUBROUTINE:[0-9]+]],
424424
// CHECK: ![[SUBROUTINE]] = !DISubroutineType(types: ![[SR_TYPES:[0-9]+]])
425425
// CHECK: ![[SR_TYPES]] = !{![[COMP]]}
426+
427+
// -----
428+
429+
// Ensures nested recursive decls work.
430+
// The output should be identical to if the inner composite type decl was
431+
// replaced with the recursive self reference.
432+
433+
#di_file = #llvm.di_file<"test.mlir" in "/">
434+
#di_composite_type_self = #llvm.di_composite_type<tag = DW_TAG_null, recId = distinct[0]<>>
435+
436+
#di_subroutine_type_inner = #llvm.di_subroutine_type<types = #di_composite_type_self>
437+
#di_subprogram_inner = #llvm.di_subprogram<scope = #di_file, file = #di_file, subprogramFlags = Optimized, type = #di_subroutine_type_inner>
438+
#di_composite_type_inner = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[0]<>, scope = #di_subprogram_inner>
439+
440+
#di_subroutine_type = #llvm.di_subroutine_type<types = #di_composite_type_inner>
441+
#di_subprogram = #llvm.di_subprogram<scope = #di_file, file = #di_file, subprogramFlags = Optimized, type = #di_subroutine_type>
442+
#di_composite_type = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[0]<>, scope = #di_subprogram>
443+
444+
#di_global_variable = #llvm.di_global_variable<file = #di_file, line = 1, type = #di_composite_type>
445+
#di_global_variable_expression = #llvm.di_global_variable_expression<var = #di_global_variable>
446+
447+
llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression} : !llvm.struct<()>
448+
449+
// CHECK: distinct !DIGlobalVariable({{.*}}type: ![[COMP:[0-9]+]],
450+
// CHECK: ![[COMP]] = distinct !DICompositeType({{.*}}scope: ![[SCOPE:[0-9]+]],
451+
// CHECK: ![[SCOPE]] = !DISubprogram({{.*}}type: ![[SUBROUTINE:[0-9]+]],
452+
// CHECK: ![[SUBROUTINE]] = !DISubroutineType(types: ![[SR_TYPES:[0-9]+]])
453+
// CHECK: ![[SR_TYPES]] = !{![[COMP]]}

0 commit comments

Comments
 (0)