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

Kristina Bessonova via flang-commits flang-commits at lists.llvm.org
Thu Jul 2 07:37:00 PDT 2026


================
@@ -3236,9 +3240,57 @@ void CodeViewDebug::emitDebugInfoForUDTs(
   }
 }
 
+void CodeViewDebug::collectGlobalOrStaticLocalVariableInfo(
+    const DIGlobalVariableExpression *GVE) {
+  const DIGlobalVariable *DIGV = GVE->getVariable();
+  const DIExpression *DIE = GVE->getExpression();
+  // Don't emit string literals in CodeView, as the only useful parts are
+  // generally the filename and line number, which isn't possible to output
+  // in CodeView. String literals should be the only unnamed GlobalVariable
+  // with debug info.
+  if (DIGV->getName().empty())
+    return;
+
+  if ((DIE->getNumElements() == 2) &&
+      (DIE->getElement(0) == dwarf::DW_OP_plus_uconst))
+    // Record the constant offset for the variable.
+    //
+    // A Fortran common block uses this idiom to encode the offset
+    // of a variable from the common block's starting address.
+    CVGlobalVariableOffsets.insert(std::make_pair(DIGV, DIE->getElement(1)));
+
+  // Emit constant global variables in a global symbol section.
+  if (GlobalMap.count(GVE) == 0 && DIE->isConstant()) {
----------------
chbessonova wrote:

```
if (!GlobalMap.count(GVE) && DIE->isConstant())
  GlobalVariables.emplace_back(CVGlobalVariable{DIGV, DIE});
```

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


More information about the flang-commits mailing list