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

via flang-commits flang-commits at lists.llvm.org
Thu Jun 4 13:53:28 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(
----------------
timsmith78 wrote:

Good point -- my intent was to save execution time if there was nothing to do, but perhaps it is not worth the extra compile time.  I may need it, though, if I do indeed pull out the logic to create the fake use ops into a helper function, but I'll see if I can come up with an algorithm that does not require it. 

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


More information about the flang-commits mailing list