Skip to content

Commit 919b1ec

Browse files
authored
[flang][debug] Support pointer type. (#96153)
The handling of `PointerType` is similar to `HeapType`. The only difference is that allocated flag is generated for `HeapType` and associated flag for `PointerType`. The tests for pointer to allocatable strings are disabled for now. I will enable them once #95906 is merged. The debugging in GDB looks like this: integer, pointer :: par2(:) integer, target, allocatable :: ar2(:) integer, target :: sc integer, pointer :: psc allocate(ar2(4)) par2 => ar2 psc => sc 19 par2 => ar2 (gdb) p par2 $3 = <not associated> (gdb) n 20 do i=1,5 (gdb) p par2 $4 = (0, 0, 0, 0) (gdb) ptype par2 type = integer (4) (gdb) p sc $5 = 3 (gdb) p psc $6 = (PTR TO -> ( integer )) 0x7fffffffda24 (gdb) p *psc $7 = 3
1 parent 0bd9c49 commit 919b1ec

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
310310
return convertPointerLikeType(heapTy.getElementType(), fileAttr, scope,
311311
loc, /*genAllocated=*/true,
312312
/*genAssociated=*/false);
313+
if (auto ptrTy = mlir::dyn_cast_or_null<fir::PointerType>(elTy))
314+
return convertPointerLikeType(ptrTy.getElementType(), fileAttr, scope,
315+
loc, /*genAllocated=*/false,
316+
/*genAssociated=*/true);
313317
return genPlaceholderType(context);
314318
} else {
315319
// FIXME: These types are currently unhandled. We are generating a
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
subroutine ff(n, m)
4+
implicit none
5+
integer i, j, m, n
6+
real(4), pointer :: par(:, :)
7+
integer, pointer :: psc
8+
integer, pointer :: par2(:)
9+
character(len=16), pointer :: pstr
10+
real(4), target :: ar(4, 5)
11+
integer, target :: sc
12+
integer, target, allocatable :: ar2(:)
13+
character(len=:), target, allocatable :: str
14+
15+
str = 'Hello'
16+
pstr => str
17+
allocate(ar2(4))
18+
par2 => ar2
19+
do i=1,5
20+
do j=1,4
21+
ar(j,i) = 0.1
22+
par2(j) = j
23+
end do
24+
end do
25+
sc = 3
26+
psc => sc
27+
par => ar
28+
29+
print *, sc
30+
print *, ar
31+
print *, ar2
32+
print *, str
33+
print *, psc
34+
print *, par
35+
print *, par2
36+
print *, pstr
37+
end subroutine ff
38+
39+
40+
! CHECK-DAG: ![[INT_TY:[0-9]+]] = !DIBasicType(name: "integer"{{.*}})
41+
! CHECK-DAG: ![[ELEMS1:[0-9]+]] = !{!{{[0-9]+}}}
42+
! CHECK-DAG: !DILocalVariable(name: "par"{{.*}}type: ![[ARR_TY1:[0-9]+]])
43+
! CHECK-DAG: ![[ARR_TY1]] = !DICompositeType(tag: DW_TAG_array_type{{.*}}elements: ![[ELEMS2:[0-9]+]], dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref), associated: !DIExpression(DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne))
44+
! CHECK-DAG: ![[ELEMS2]] = !{!{{[0-9]+}}, !{{[0-9]+}}}
45+
! CHECK-DAG: !DILocalVariable(name: "par2"{{.*}}type: ![[ARR_TY2:[0-9]+]])
46+
! CHECK-DAG: ![[ARR_TY2]] = !DICompositeType(tag: DW_TAG_array_type{{.*}}, elements: ![[ELEMS1]], dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref), associated: !DIExpression(DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne))
47+
! CHECK-DAG: !DILocalVariable(name: "psc"{{.*}}type: ![[PTR_TY:[0-9]+]])
48+
! CHECK-DAG: ![[PTR_TY]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[INT_TY]]{{.*}})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.global @_QMhelperEpar : !fir.box<!fir.ptr<!fir.array<?x?xf32>>> {
5+
%0 = fir.zero_bits !fir.ptr<!fir.array<?x?xf32>>
6+
%c0 = arith.constant 0 : index
7+
%1 = fir.shape %c0, %c0 : (index, index) -> !fir.shape<2>
8+
%2 = fir.embox %0(%1) : (!fir.ptr<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
9+
fir.has_value %2 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
10+
} loc(#loc1)
11+
fir.global @_QMhelperEpar2 : !fir.box<!fir.ptr<!fir.array<?xi32>>> {
12+
%0 = fir.zero_bits !fir.ptr<!fir.array<?xi32>>
13+
%c0 = arith.constant 0 : index
14+
%1 = fir.shape %c0 : (index) -> !fir.shape<1>
15+
%2 = fir.embox %0(%1) : (!fir.ptr<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xi32>>>
16+
fir.has_value %2 : !fir.box<!fir.ptr<!fir.array<?xi32>>>
17+
} loc(#loc2)
18+
fir.global @_QMhelperEpsc : !fir.box<!fir.ptr<i32>> {
19+
%0 = fir.zero_bits !fir.ptr<i32>
20+
%1 = fir.embox %0 : (!fir.ptr<i32>) -> !fir.box<!fir.ptr<i32>>
21+
fir.has_value %1 : !fir.box<!fir.ptr<i32>>
22+
} loc(#loc3)
23+
fir.global @_QMmEpstr : !fir.box<!fir.ptr<!fir.char<1,16>>> {
24+
%0 = fir.zero_bits !fir.ptr<!fir.char<1,16>>
25+
%1 = fir.embox %0 : (!fir.ptr<!fir.char<1,16>>) -> !fir.box<!fir.ptr<!fir.char<1,16>>>
26+
fir.has_value %1 : !fir.box<!fir.ptr<!fir.char<1,16>>>
27+
} loc(#loc4)
28+
}
29+
#loc1 = loc("test.f90":5:1)
30+
#loc2 = loc("test.f90":6:1)
31+
#loc3 = loc("test.f90":7:1)
32+
#loc4 = loc("test.f90":8:1)
33+
34+
// CHECK-DAG: #[[INT_TY:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer"{{.*}}>
35+
// CHECK-DAG: #[[ARR1_TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<lowerBound = #llvm.di_expression{{.*}}, upperBound = #llvm.di_expression{{.*}}>, #llvm.di_subrange<lowerBound = #llvm.di_expression{{.*}}, upperBound = #llvm.di_expression{{.*}}>, dataLocation = {{.*}}, associated = <[DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne]>>
36+
// CHECK-DAG: #[[ARR2_TY:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<lowerBound = #llvm.di_expression{{.*}}, upperBound = #llvm.di_expression{{.*}}>, dataLocation = {{.*}}, associated = <[DW_OP_push_object_address, DW_OP_deref, DW_OP_lit0, DW_OP_ne]>>
37+
// CHECK-DAG: #[[PTR_TY:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type{{.*}}baseType = #[[INT_TY]]{{.*}}>
38+
// CHECK-DAG: #llvm.di_global_variable<{{.*}}name = "par"{{.*}}type = #[[ARR1_TY]]{{.*}}>
39+
// CHECK-DAG: #llvm.di_global_variable<{{.*}}name = "par2"{{.*}}type = #[[ARR2_TY]]{{.*}}>
40+
// CHECK-DAG: #llvm.di_global_variable<{{.*}}name = "psc"{{.*}}type = #[[PTR_TY]]{{.*}}>

0 commit comments

Comments
 (0)