[flang-commits] [flang] e27b8b2 - [flang][debug] Improve handling of cyclic derived types with classes. (#129588)

via flang-commits flang-commits at lists.llvm.org
Tue Mar 4 02:27:28 PST 2025


Author: Abid Qadeer
Date: 2025-03-04T10:27:24Z
New Revision: e27b8b2eda767eb59d3d605d288e733b154a48c5

URL: https://github.com/llvm/llvm-project/commit/e27b8b2eda767eb59d3d605d288e733b154a48c5
DIFF: https://github.com/llvm/llvm-project/commit/e27b8b2eda767eb59d3d605d288e733b154a48c5.diff

LOG: [flang][debug] Improve handling of cyclic derived types with classes. (#129588)

While checking if a type should be cached or not, we use
`getDerivedType` to peel outer layers and get to the base type. This
function did not peel the `fir.class` which caused the algorithm to
fail.

Fixes #128606.

Added: 
    flang/test/Integration/debug-cyclic-derived-type-4.f90

Modified: 
    flang/lib/Optimizer/Dialect/FIRType.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 719cb1b9d75aa..f8fd55c79be12 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -210,7 +210,8 @@ mlir::Type getDerivedType(mlir::Type ty) {
           return seq.getEleTy();
         return p.getEleTy();
       })
-      .Case<fir::BoxType>([](auto p) { return getDerivedType(p.getEleTy()); })
+      .Case<fir::BaseBoxType>(
+          [](auto p) { return getDerivedType(p.getEleTy()); })
       .Default([](mlir::Type t) { return t; });
 }
 

diff  --git a/flang/test/Integration/debug-cyclic-derived-type-4.f90 b/flang/test/Integration/debug-cyclic-derived-type-4.f90
new file mode 100644
index 0000000000000..783412e08ba7b
--- /dev/null
+++ b/flang/test/Integration/debug-cyclic-derived-type-4.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck  %s
+
+! Same as debug-cyclic-derived-type-2.f90 but using class instead of type.
+module m
+ type t2
+   class(t1), pointer :: p1
+ end type
+ type t1
+   class(t2), pointer :: p2
+   integer abc
+ end type
+ type(t1) :: tee1
+end module
+
+program test
+  use m
+  type(t2) :: lc2
+  print *, lc2%p1%abc
+end program test
+
+! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t1"{{.*}})
+! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t2"{{.*}})


        


More information about the flang-commits mailing list