Skip to content

Commit e27b8b2

Browse files
authored
[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.
1 parent 77a8770 commit e27b8b2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ mlir::Type getDerivedType(mlir::Type ty) {
210210
return seq.getEleTy();
211211
return p.getEleTy();
212212
})
213-
.Case<fir::BoxType>([](auto p) { return getDerivedType(p.getEleTy()); })
213+
.Case<fir::BaseBoxType>(
214+
[](auto p) { return getDerivedType(p.getEleTy()); })
214215
.Default([](mlir::Type t) { return t; });
215216
}
216217

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
! Same as debug-cyclic-derived-type-2.f90 but using class instead of type.
4+
module m
5+
type t2
6+
class(t1), pointer :: p1
7+
end type
8+
type t1
9+
class(t2), pointer :: p2
10+
integer abc
11+
end type
12+
type(t1) :: tee1
13+
end module
14+
15+
program test
16+
use m
17+
type(t2) :: lc2
18+
print *, lc2%p1%abc
19+
end program test
20+
21+
! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t1"{{.*}})
22+
! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t2"{{.*}})

0 commit comments

Comments
 (0)