[clang] [llvm] [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (PR #139914)
Vladislav Dzhidzhoev via cfe-commits
cfe-commits at lists.llvm.org
Wed May 14 07:47:03 PDT 2025
https://github.com/dzhidzhoev created https://github.com/llvm/llvm-project/pull/139914
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.
>From 261890db08127247b6ea0e436b630d59d016443d Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 13 May 2025 12:40:42 +0200
Subject: [PATCH] [llvm][DebugInfo][clang] Finalize all declaration subprograms
in DIBuilder::finalize()
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 were
finalized in DIBuilder::finalize():
`AllSubprograms` held references to definition subprograms.
`RetainValues` held references to declaration subprograms.
For DISubprogram elements of both members, 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 definition 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.
---
clang/lib/CodeGen/CGDebugInfo.cpp | 4 +---
llvm/lib/IR/DIBuilder.cpp | 6 ++----
2 files changed, 3 insertions(+), 7 deletions(-)
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;
}
More information about the cfe-commits
mailing list