Author: Vladislav Dzhidzhoev Date: 2025-06-02T15:22:53+02:00 New Revision: dec8f1314fbf77a2b557f12275b1a5e7c7a70f32
URL: https://github.com/llvm/llvm-project/commit/dec8f1314fbf77a2b557f12275b1a5e7c7a70f32 DIFF: https://github.com/llvm/llvm-project/commit/dec8f1314fbf77a2b557f12275b1a5e7c7a70f32.diff LOG: [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. Added: Modified: clang/lib/CodeGen/CGDebugInfo.cpp llvm/lib/IR/DIBuilder.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 5772c07154144..7cb52597d9a00 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -4767,7 +4767,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, // Preserve btf_decl_tag attributes for parameters of extern functions // for BPF target. The parameters created in this loop are attached as - // DISubprogram's retainedNodes in the subsequent finalizeSubprogram call. + // DISubprogram's retainedNodes in the DIBuilder::finalize() call. if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) { if (auto *FD = dyn_cast<FunctionDecl>(D)) { llvm::DITypeRefArray ParamTypes = STy->getTypeArray(); @@ -4784,8 +4784,6 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, if (IsDeclForCallSite) Fn->setSubprogram(SP); - - DBuilder.finalizeSubprogram(SP); } void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 7d611506e18e0..5e5ff22132e99 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits