[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.
This commit is contained in:
Abid Qadeer 2025-03-04 10:27:24 +00:00 committed by GitHub
parent 77a8770d49
commit e27b8b2eda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -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; });
}

View File

@ -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"{{.*}})