[flang-commits] [flang] [flang][debug] Support assumed shape arrays. (PR #94644)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Fri Jun 7 10:00:55 PDT 2024


================
@@ -22,6 +26,60 @@ namespace fir {
 DebugTypeGenerator::DebugTypeGenerator(mlir::ModuleOp m)
     : module(m), kindMapping(getKindMapping(m)) {
   LLVM_DEBUG(llvm::dbgs() << "DITypeAttr generator\n");
+
+  std::optional<mlir::DataLayout> dl =
+      fir::support::getOrSetDataLayout(module, /*allowDefaultLayout=*/true);
+  if (!dl)
+    mlir::emitError(module.getLoc(), "Missing data layout attribute in module");
+
+  mlir::MLIRContext *context = module.getContext();
+
+  // The debug information requires the offset of certain fields in the
+  // descriptors like lower_bound and extent for each dimension. The code
+  // below uses getDescFieldTypeModel to get the type representing each field
+  // and then use data layout to get its size. It adds the size to get the
+  // offset.
+  // As has been mentioned in DescriptorModel.h that code may be confusing
+  // host for the target in calculating the type of the descriptor fields. But
+  // debug info is using similar logic to what codegen is doing so it will
+  // atleast be representing the generated code correctly.
+  // My testing for a 32-bit shows that base_addr* is correctly given as a
+  // 32-bit entity. The index types are 64-bit so I am a bit uncertain how
+  // the alignment will effect the calculation of offsets in that case.
+
----------------
abidh wrote:

As @jeanPerier commented, the risk has been pushed to getDescFieldTypeModel<> and not in my code. So I have removed the comments.

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


More information about the flang-commits mailing list