[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
Thu May 22 07:23:28 PDT 2025
dzhidzhoev wrote:
> I suppose what this is encoding is a (subtle?) assumption about how definition-subprograms are modelled: they're created once and are immutable. Wheras declaration-functions can be forwarded declared and then have extra information added to them when a definition is emitted.
It is possible.
By the way, I've noticed that (declaration) SPs created with the `DIBuilder::CreateMethod` call in `CGDebugInfo::CreateCXXMemberFunction` are not finalized anywhere in clang (at least it's true for `get_a`/`get_b` in `clang/test/CodeGenCXX/debug-info-local-types.cpp` from https://github.com/llvm/llvm-project/pull/119001). I think clang expected DIBuilder to finalize everything before https://reviews.llvm.org/D33704, where it turned out that clang needed some subprograms to be finalized before the finalization of the whole CGDebugInfo instance. It seems to me that manual finalizeSubprogram() calls were added sporadically, not followed by declaration-vs-definition logic.
> If there's no performance cost as a result of this patch, then it seems fine to go in to me.
Performance cost in terms of compilation time?
> but is there a functional reason in a later patch that makes it necessary?
I've touched it briefly here https://github.com/llvm/llvm-project/pull/119001#discussion_r2089196943. I've noticed that the mentioned PR doesn't call `finalizeSubprogram()` for the created declaration SP. With the call added, the test output changes: declaration DISubprograms have their DICompositeTypes in the `retainedNodes` field.
We can't just add `finalizeSubprogram` right after `CreateSubprogram()`, as we return from the function before the local types are created. And we can't attach a declaration subprogram to the corresponding Clang AST declaration, as it may not exist.
We could start tracking these declarations in CGDebugInfo class, but I'm curious why not to do that on DIBuilder's level globally :)
https://github.com/llvm/llvm-project/pull/139914
More information about the cfe-commits
mailing list