Skip to content

Commit dec8f13

Browse files
authored
[llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (llvm#139914)
DIBuilder began tracking definition subprograms and finalizing them in `DIBuilder::finalize()` in eb1bb4e. Currently, `finalizeSubprogram()` attaches local variables, imported entities, and labels to the `retainedNodes:` field of a corresponding subprogram. After 75819ae, 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 40a3fcb). DIBuilder clients may also want to attach DILocalVariables to declaration subprograms, for example, in 58bdf8f. 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.
1 parent b26baf1 commit dec8f13

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,7 +4767,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
47674767

47684768
// Preserve btf_decl_tag attributes for parameters of extern functions
47694769
// for BPF target. The parameters created in this loop are attached as
4770-
// DISubprogram's retainedNodes in the subsequent finalizeSubprogram call.
4770+
// DISubprogram's retainedNodes in the DIBuilder::finalize() call.
47714771
if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
47724772
if (auto *FD = dyn_cast<FunctionDecl>(D)) {
47734773
llvm::DITypeRefArray ParamTypes = STy->getTypeArray();
@@ -4784,8 +4784,6 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
47844784

47854785
if (IsDeclForCallSite)
47864786
Fn->setSubprogram(SP);
4787-
4788-
DBuilder.finalizeSubprogram(SP);
47894787
}
47904788

47914789
void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,

llvm/lib/IR/DIBuilder.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,7 @@ DISubprogram *DIBuilder::createFunction(
943943
SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr,
944944
ThrownTypes, Annotations, TargetFuncName);
945945

946-
if (IsDefinition)
947-
AllSubprograms.push_back(Node);
946+
AllSubprograms.push_back(Node);
948947
trackIfUnresolved(Node);
949948
return Node;
950949
}
@@ -981,8 +980,7 @@ DISubprogram *DIBuilder::createMethod(
981980
Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr,
982981
nullptr, ThrownTypes);
983982

984-
if (IsDefinition)
985-
AllSubprograms.push_back(SP);
983+
AllSubprograms.push_back(SP);
986984
trackIfUnresolved(SP);
987985
return SP;
988986
}

0 commit comments

Comments
 (0)