[clang] [llvm] Reland "[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)" (PR #165032)

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 05:24:35 PST 2025


dzhidzhoev wrote:

Fixed a couple of extra issues with this patch, which I've found:

One problem is related to function cloning.
Many derived types, such as pointer types or qualified types, do not have scope information, although they can refer to local types.
If a function is cloned in CloneFunction, the function's local types are also cloned, but derived types are not remapped to refer to cloned local types, since CloneFunction (IdentityMDPredicate used by it, to be precise) treats scopeless derived types as non-local and prevents ValueMapper from remapping them. This may lead to a situation where local types are cloned, but pointer types from the cloned function still refer to the local types from the original subprogram rather than those from the cloned subprogram.
To solve that, I've updated CloneFunction's IdentityMDPredicate so that it ignores scopeless derived types. Thus, ValueMapper will remap such types if they refer to (cloned) local types.

Another issue relates to `CodeGenFunction::GenerateVarArgsThunk` in clang (for which changes were recently made in PR #167758).
It calls CloneFunction for an IR that is not finalized. Particularly, some DIType nodes may still be temporary when CloneFunction is called. ValueMapper can't handle temporary nodes. On the mainline, it's not a problem, since type nodes are never remapped (ValueMapper is prevented from remapping them by IdentityMDPredicate). However, local types and derived types are cloned/remapped with this patch, and ValueMapper may encounter temporary nodes (examples are given in `clang/test/CodeGenCXX/tmp-md-nodes3.cpp`).
CodeGenFunction::GenerateVarArgsThunk tackles a similar problem with DILocalVariables by calling `MDNode::resolve()` on them. It does not actually resolve any dependencies on temporaries, but forcefully marks DILocalVariables as resolved. I doubt the same trick would be good for local types, as it might prevent them from being correctly finalized later.
To solve this, for each DILocalVariable encountered in a base function, its DIType is mapped to itself. Adding the DIType to VMap prevents ValueMapper from inspecting the node. This should not affect debug information produced by CodeGenFunction::GenerateVarArgsThunk, compared to the current mainline, where local types are not remapped at all.


https://github.com/llvm/llvm-project/pull/165032


More information about the llvm-commits mailing list