From dec8f1314fbf77a2b557f12275b1a5e7c7a70f32 Mon Sep 17 00:00:00 2001 From: Vladislav Dzhidzhoev Date: Mon, 2 Jun 2025 15:22:53 +0200 Subject: [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (#139914) DIBuilder began tracking definition subprograms and finalizing them in `DIBuilder::finalize()` in eb1bb4e419. Currently, `finalizeSubprogram()` attaches local variables, imported entities, and labels to the `retainedNodes:` field of a corresponding subprogram. After 75819aedf, the definition and some declaration subprograms are finalized in `DIBuilder::finalize()`: `AllSubprograms` holds references to definition subprograms. `AllRetainTypes` holds references to declaration subprograms. For DISubprogram elements of both variables, `finalizeSubprogram()` was called there. However, `retainTypes()` is not necessarily called for every declaration subprogram (as in 40a3fcb0). DIBuilder clients may also want to attach DILocalVariables to declaration subprograms, for example, in 58bdf8f9a8. Thus, the `finalizeSubprogram()` function is called for all definition subprograms in `DIBuilder::finalize()` because they are stored in the `AllSubprograms` by the `CreateFunction(isDefinition: true)` call. But for the declaration subprograms, it should be called manually. With this commit, `AllSubprograms` is used for holding and finalizing all DISubprograms. --- llvm/lib/IR/DIBuilder.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'llvm/lib/IR/DIBuilder.cpp') diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 7d61150..5e5ff22 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -943,8 +943,7 @@ DISubprogram *DIBuilder::createFunction( SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr, ThrownTypes, Annotations, TargetFuncName); - if (IsDefinition) - AllSubprograms.push_back(Node); + AllSubprograms.push_back(Node); trackIfUnresolved(Node); return Node; } @@ -981,8 +980,7 @@ DISubprogram *DIBuilder::createMethod( Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr, nullptr, ThrownTypes); - if (IsDefinition) - AllSubprograms.push_back(SP); + AllSubprograms.push_back(SP); trackIfUnresolved(SP); return SP; } -- cgit v1.1