Skip to content

Commit 9c3475a

Browse files
authored
[MLIR][LLVM] Fix recursive DI type export memory leak (#88122)
Followup to discussion #87295 (comment). The export cache should not cache temporary nodes.
1 parent a9d7ad2 commit 9c3475a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
352352
DISubroutineTypeAttr>(
353353
[&](auto attr) { return translateImpl(attr); });
354354

355-
attrToNode.insert({attr, node});
355+
if (node && !node->isTemporary())
356+
attrToNode.insert({attr, node});
356357
return node;
357358
}
358359

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,16 @@ llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression}
442442
#di_subprogram = #llvm.di_subprogram<scope = #di_file, file = #di_file, subprogramFlags = Optimized, type = #di_subroutine_type>
443443
#di_composite_type = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[0]<>, scope = #di_subprogram>
444444

445-
#di_global_variable = #llvm.di_global_variable<file = #di_file, line = 1, type = #di_composite_type>
445+
// Use the inner type standalone outside too. Ensures it's not cached wrong.
446+
#di_var_type = #llvm.di_subroutine_type<types = #di_composite_type, #di_composite_type_inner>
447+
#di_global_variable = #llvm.di_global_variable<file = #di_file, line = 1, type = #di_var_type>
446448
#di_global_variable_expression = #llvm.di_global_variable_expression<var = #di_global_variable>
447449

448450
llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression} : !llvm.struct<()>
449451

450-
// CHECK: distinct !DIGlobalVariable({{.*}}type: ![[COMP:[0-9]+]],
452+
// CHECK: distinct !DIGlobalVariable({{.*}}type: ![[VAR:[0-9]+]],
453+
// CHECK: ![[VAR]] = !DISubroutineType(types: ![[COMPS:[0-9]+]])
454+
// CHECK: ![[COMPS]] = !{![[COMP:[0-9]+]],
451455
// CHECK: ![[COMP]] = distinct !DICompositeType({{.*}}scope: ![[SCOPE:[0-9]+]],
452456
// CHECK: ![[SCOPE]] = !DISubprogram({{.*}}type: ![[SUBROUTINE:[0-9]+]],
453457
// CHECK: ![[SUBROUTINE]] = !DISubroutineType(types: ![[SR_TYPES:[0-9]+]])

0 commit comments

Comments
 (0)