[Mlir-commits] [clang] [compiler-rt] [flang] [llvm] [mlir] [DebugMetadata][DwarfDebug][CodeView] Support function-local static variables in lexical block scopes (6/7) (PR #187927)

Vladislav Dzhidzhoev llvmlistbot at llvm.org
Tue Apr 28 09:10:27 PDT 2026


dzhidzhoev wrote:

> At first glance, it seems like breaking the cycle using DISubprogramAttr is good enough. It is expected that some attributes are traversed multiple times until one of the self recursive attributes is seen a second time. To make this somewhat efficient, there is cache that makes sure the second translation is just a lookup:
> 
> ```
> DINodeAttr DebugImporter::translate(llvm::DINode *node) {
>   if (!node)
>     return nullptr;
> 
>   // Check for a cached instance.
>   auto cacheEntry = cache.lookupOrInit(node);
>   if (std::optional<DINodeAttr> result = cacheEntry.get())
>     return *result;
> ```
> 
> This will not work in case of the DIGlobalVariableExpression since it is not derived from DINodeAttr. However, I would still expect that things are functional (albeit not optimal). The uniquing seems to work in your example since the pointer for the DIGlobalVariableExpression objects are the same.

I've modified DebugImportant locally, so that, as I believe, it should be able to cache DIGlobalVariableExpressions (it's here https://github.com/dzhidzhoev/llvm-project/commits/debuginfo/rfc-krisb/6/rebased/). Then I ran the test from the gist mentioned above (https://gist.github.com/dzhidzhoev/34364710e5478a30ab1023239026e04d). I get the following output: https://gist.github.com/dzhidzhoev/4da6642e9a02817a2ca738d38d55bd65. di_global_variable_expression's and di_global_variable's for "a" and "b" are duplicated.

If I run the same test on the current code of this PR (branch dzhidzhoev:debuginfo/rfc-krisb/6/base), and the output is the same.

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


More information about the Mlir-commits mailing list