[flang-commits] [flang] [flang][debug] Add fake use ops for dynamic array dimension variables (PR #200061)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Jun 1 07:00:10 PDT 2026


================
@@ -331,6 +331,60 @@ void AddDebugInfoPass::handleLocalVariable(Op declOp, llvm::StringRef name,
   auto tyAttr =
       typeGen.convertType(typeToConvert, fileAttr, scopeAttr, typeGenDeclOp);
 
+  // Check if tyAttr represents a dynamic Fortran array. If so, create
+  // FakeUseOps to preserve the automatic variables that represent the lower
+  // bound, count, and stride.
+  if (emitFakeUseForDebugVars) {
+    if (auto arrayTy =
+            mlir::dyn_cast<mlir::LLVM::DICompositeTypeAttr>(tyAttr)) {
+      if (arrayTy.getTag() == llvm::dwarf::DW_TAG_array_type) {
+        bool isDynamic = llvm::any_of(
----------------
abidh wrote:

```suggestion
      bool isDynamic =
          llvm::any_of(declOp.getShape(),
                       [](mlir::Value v) { return !fir::getIntIfConstant(v); }) ||
          llvm::any_of(declOp.getShift(),
                       [](mlir::Value v) { return !fir::getIntIfConstant(v); });
```
Do you think something like this will work better? It asks declOp directly if it has non constant shape or size and does not depend on the translated type. Also I don't think we generate an artificial variable for stride so the stride check in your patch was probably redundant.

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


More information about the flang-commits mailing list