[Mlir-commits] [mlir] 9c3475a - [MLIR][LLVM] Fix recursive DI type export memory leak (#88122)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Apr 14 19:17:24 PDT 2024
Author: Billy Zhu
Date: 2024-04-14T19:17:20-07:00
New Revision: 9c3475acc9b11d08f0e0b3e230429e9f552d5f80
URL: https://github.com/llvm/llvm-project/commit/9c3475acc9b11d08f0e0b3e230429e9f552d5f80
DIFF: https://github.com/llvm/llvm-project/commit/9c3475acc9b11d08f0e0b3e230429e9f552d5f80.diff
LOG: [MLIR][LLVM] Fix recursive DI type export memory leak (#88122)
Followup to discussion
https://github.com/llvm/llvm-project/pull/87295#discussion_r1556016667.
The export cache should not cache temporary nodes.
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 46e2e7f2ba5dc4..2de5e372d88c0e 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -352,7 +352,8 @@ llvm::DINode *DebugTranslation::translate(DINodeAttr attr) {
DISubroutineTypeAttr>(
[&](auto attr) { return translateImpl(attr); });
- attrToNode.insert({attr, node});
+ if (node && !node->isTemporary())
+ attrToNode.insert({attr, node});
return node;
}
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index f4c18bf6bd53c0..8ab1a1b290dad3 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -442,12 +442,16 @@ llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression}
#di_subprogram = #llvm.di_subprogram<scope = #di_file, file = #di_file, subprogramFlags = Optimized, type = #di_subroutine_type>
#di_composite_type = #llvm.di_composite_type<tag = DW_TAG_class_type, recId = distinct[0]<>, scope = #di_subprogram>
-#di_global_variable = #llvm.di_global_variable<file = #di_file, line = 1, type = #di_composite_type>
+// Use the inner type standalone outside too. Ensures it's not cached wrong.
+#di_var_type = #llvm.di_subroutine_type<types = #di_composite_type, #di_composite_type_inner>
+#di_global_variable = #llvm.di_global_variable<file = #di_file, line = 1, type = #di_var_type>
#di_global_variable_expression = #llvm.di_global_variable_expression<var = #di_global_variable>
llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression} : !llvm.struct<()>
-// CHECK: distinct !DIGlobalVariable({{.*}}type: ![[COMP:[0-9]+]],
+// CHECK: distinct !DIGlobalVariable({{.*}}type: ![[VAR:[0-9]+]],
+// CHECK: ![[VAR]] = !DISubroutineType(types: ![[COMPS:[0-9]+]])
+// CHECK: ![[COMPS]] = !{![[COMP:[0-9]+]],
// CHECK: ![[COMP]] = distinct !DICompositeType({{.*}}scope: ![[SCOPE:[0-9]+]],
// CHECK: ![[SCOPE]] = !DISubprogram({{.*}}type: ![[SUBROUTINE:[0-9]+]],
// CHECK: ![[SUBROUTINE]] = !DISubroutineType(types: ![[SR_TYPES:[0-9]+]])
More information about the Mlir-commits
mailing list