Skip to content

Commit 548bcf4

Browse files
committed
[flang][debug] Support ClassType.
This PR adds the handling of ClassType. It is treated as pointer to the underlying type. Note that ClassType when passed to the function have double indirection so it is represented as pointer to type (and not type as a RecordType will be for example). If ClassType wraps a pointer or allocatable then we take care to avoid double indirection. This is how it looks like in the debugger. subroutine test_proc (this) class(test_type), intent (inout) :: this allocate (this%b (3, 2)) call fill_array_2d (this%b) print *, this%a end (gdb) p this $6 = (PTR TO -> ( Type test_type )) 0x2052a0 (gdb) p this%a $7 = 0 (gdb) p this%b $8 = ((1, 2, 3) (4, 5, 6)) (gdb)
1 parent 15d1560 commit 548bcf4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,20 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
668668
return convertRecordType(recTy, fileAttr, scope, declOp);
669669
} else if (auto tupleTy = mlir::dyn_cast_if_present<mlir::TupleType>(Ty)) {
670670
return convertTupleType(tupleTy, fileAttr, scope, declOp);
671+
} else if (auto classTy = mlir::dyn_cast_if_present<fir::ClassType>(Ty)) {
672+
// ClassType when passed to the function have double indirection so it
673+
// is represented as pointer to type (and not type as a RecordType will be
674+
// for example). If ClassType wraps a pointer or allocatable then we get
675+
// the real underlying type to avoid translating the Ty to
676+
// Ptr -> Ptr -> type.
677+
mlir::Type elTy = classTy.getEleTy();
678+
if (auto ptrTy = mlir::dyn_cast_if_present<fir::PointerType>(elTy))
679+
elTy = ptrTy.getElementType();
680+
else if (auto heapTy = mlir::dyn_cast_if_present<fir::HeapType>(elTy))
681+
elTy = heapTy.getElementType();
682+
return convertPointerLikeType(elTy, fileAttr, scope, declOp,
683+
/*genAllocated=*/false,
684+
/*genAssociated=*/false);
671685
} else if (auto refTy = mlir::dyn_cast_if_present<fir::ReferenceType>(Ty)) {
672686
auto elTy = refTy.getEleTy();
673687
return convertPointerLikeType(elTy, fileAttr, scope, declOp,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
2+
3+
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
4+
fir.type_info @_QTtest_type nofinal : !fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}> dispatch_table {
5+
fir.dt_entry "test_proc", @_QPtest_proc
6+
} loc(#loc1)
7+
func.func private @_QPtest_proc(%arg0: !fir.class<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>)
8+
9+
func.func @test() {
10+
%0 = fir.address_of(@_QFEx) : !fir.ref<!fir.class<!fir.heap<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>
11+
%1 = fircg.ext_declare %0 {uniq_name = "_QFEx"} : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>) -> !fir.ref<!fir.class<!fir.heap<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>> loc(#loc3)
12+
%2 = fir.address_of(@_QFEy) : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>
13+
%3 = fircg.ext_declare %2 {uniq_name = "_QFEy"} : (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>) -> !fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>> loc(#loc4)
14+
return
15+
} loc(#loc2)
16+
}
17+
18+
#loc1 = loc("./simple.f90":2:1)
19+
#loc2 = loc("./simple.f90":10:1)
20+
#loc3 = loc("./simple.f90":15:1)
21+
#loc4 = loc("./simple.f90":22:1)
22+
23+
// CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<{{.*}}name = "test_type"{{.*}}>
24+
// CHECK-DAG: #[[TY2:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, name = "", baseType = #[[TY1]]{{.*}}>
25+
// CHECK-DAG: #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_null_type, #[[TY2]]>
26+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "x"{{.*}}type = #[[TY2]]>
27+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "y"{{.*}}type = #[[TY2]]>

0 commit comments

Comments
 (0)