[clang] [llvm] [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (PR #139914)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 14 07:47:34 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-debuginfo
Author: Vladislav Dzhidzhoev (dzhidzhoev)
<details>
<summary>Changes</summary>
DIBuilder began tracking definition subprograms and finalizing them in `DIBuilder::finalize()` in eb1bb4e419.
Currently, `finalizeSubprogram()` attaches local variables 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.
`RetainValues` 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` during the `CreateFunction(isDefinition: true)` call. But for the declaration subprograms, it should be called manually.
I think this feature of the DIBuilder interface is somewhat unclear, and `AllSubprograms` could just be used for holding and finalizing all DISubprograms.
---
Full diff: https://github.com/llvm/llvm-project/pull/139914.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+1-3)
- (modified) llvm/lib/IR/DIBuilder.cpp (+2-4)
``````````diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 2a11eebf1b682..bac113289f507 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4611,7 +4611,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();
@@ -4628,8 +4628,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 90da9f3acfe57..35e61caf9a241 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -940,8 +940,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;
}
@@ -978,8 +977,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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/139914
More information about the cfe-commits
mailing list