Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo] Flang should generate correct IR for assumed size array #925

Closed
wants to merge 6 commits into from

Conversation

alokkrsharma
Copy link
Collaborator

This is to support debugging of assumed size array.
It needs below LLVM patch.
https://reviews.llvm.org/D87500 ([DebugInfo] DISubrange support for fortran assumed size array)

Dependency: #901, #902, #913

Note: This modification makes use of recent upgrade to DISubrange
    https://reviews.llvm.org/rGd20bf5a7258d4b6a7f017a81b125275dac1aa166

Currently flang generates 0 sized DISubrange metadata for assumed sahpe arrays.

---------
test case
---------
subroutine sub(assume,n1,n2)
  dimension assume(n1,n2)
end subroutine sub
-------
LLVM IR
-------
!29 = !DILocalVariable(name: "assume", arg: 1, scope: !26, file: !3, type: !30)
!30 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 32, align: 32, elements: !31)
!31 = !{!32, !32}
!32 = !DISubrange(count: 0, lowerBound: 1)
-------
This is fixed by upgrading DISubrange as it is upgraded in LLVM to be able to
dump proper DISubrange for assumed shape array.
-------
!29 = !DILocalVariable(name: "assume", arg: 1, scope: !26, file: !3, type: !30)
!30 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 32, align: 32, elements: !31)
!31 = !{!32, !36}
!32 = !DISubrange(lowerBound: 1, upperBound: !33)
!33 = distinct !DILocalVariable(scope: !34, file: !3, type: !35, flags: DIFlagArtificial)
!36 = !DISubrange(lowerBound: 1, upperBound: !37)
!37 = distinct !DILocalVariable(scope: !34, file: !3, type: !35, flags: DIFlagArtificial)
-------
…n debugger

Note: This modification makes use of recent upgrade to DISubrange
https://reviews.llvm.org/rGd20bf5a7258d4b6a7f017a81b125275dac1aa166

Now, below testcase gives desired results with debugger.
--------------
program main
  integer, allocatable  :: arr(:)
  allocate (arr(2:10))
  arr(3) = 9
end program main
--------------
(gdb) pt arr
type = integer (2:10)
(gdb) p arr
$1 = (0, 9, 0, 0, 0, 0, 0, 0, 0)
--------------
And below case works as well
--------------
program main
type dt
  integer :: var1
  integer :: var2
  integer, allocatable :: arr1 (:,:)
  integer :: var3
end type dt
type(dt) :: dvar1
dvar1%var1 = 21
dvar1%var2 = 22
dvar1%var3 = 23
allocate (dvar1%arr1(2:9, 3:11))
dvar1%arr1(5,4) = 11
end program main
--------------
(gdb) pt dvar1
type = Type dt
integer :: var1
integer :: var2
integer :: arr1(2:9,3:11)
integer :: var3
End Type dt
(gdb) p dvar1%arr1
$2 = (( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 11, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0, 0, 0, 0) )
---------------
    This patch makes use of commited llvm patch
      [DebugInfo] Support for DW_AT_associated and DW_AT_allocated.
      https://reviews.llvm.org/rG2d10258a31a6d05368dfd4442c4aaa7b54614f1e

    This fix is needed for allocatable/pointer arrays.

    for pointer array (before allocation/association)
    Before fix
    ------
    (gdb) pt ptr
    type = integer (140737345375288:140737354129776)
    (gdb) p ptr
    value requires 35017956 bytes, which is more than max-value-size
    ------
    After fix
    ------
    (gdb) pt ptr
    type = integer (:)
    (gdb) p ptr
    $1 = <not associated>
    ------
    for allocatable array (before allocation)
    Before fix
    ------
    (gdb) pt arr
    type = integer (140737345375288:140737354129776)
    (gdb) p arr
    value requires 35017956 bytes, which is more than max-value-size
    ------
    After fix
    ------
    (gdb) pt arr
    type = integer, allocatable (:)
    (gdb) p arr
    $1 = <not allocated>
    ------

Testing:
    - check-flang
@alokkrsharma
Copy link
Collaborator Author

Superset PR #952 is up for review. hence closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant