From 20f0c0c98356c314d322dec4c74158e40e4f5f08 Mon Sep 17 00:00:00 2001 From: Abid Qadeer Date: Mon, 3 Mar 2025 20:16:12 +0000 Subject: [PATCH] [flang][debug] Improve handling of cyclic derived types with classes. While checking if a type should be cached or not, we use getDerivedType to peel outer layers to get to the base type. This function did not peel the `fir.class` which caused the algorithm to fail. Fixes #128606. --- flang/lib/Optimizer/Dialect/FIRType.cpp | 3 ++- .../debug-cyclic-derived-type-4.f90 | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 flang/test/Integration/debug-cyclic-derived-type-4.f90 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([](auto p) { return getDerivedType(p.getEleTy()); }) + .Case( + [](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"{{.*}})