Page MenuHomePhabricator

[DebugInfo] Emit DW_TAG_namelist and DW_TAG_namelist_item for fortran namelist variable
ClosedPublic

Authored by bhuvanendrakumarn on Aug 23 2021, 6:40 AM.

Details

Summary

This patch emits DW_TAG_namelist and DW_TAG_namelist_item for fortran namelist variables. Namelist in fortran is basically group of variables. Already Metadata is created for each of the namelist items or variables, we just need to create MDList of these items and use the DICompositeType (with TAG: DW_TAG_namelist). Gfortran supports this fortran feature already. Flang is enhanced to support this feature and GDB also enhanced to support this. Both flang and GDB changes will up streamed soon.

Sample fortran program, IR, dwarf info are shared below.

Sample program :

program main

integer :: a, b
namelist /nml/ a, b
 
a = 10
b = 20
Write(*,nml)

end program main

LLVM IR:

!20 = !DILocalVariable(scope: !15, name: "a", file: !3, line: 6, type: !19)
. . .
!22 = !DILocalVariable(scope: !15, name: "b", file: !3, line: 7, type: !19)
. . .
!24 = !{ !20, !22 }
!25 = !DICompositeType(tag: DW_TAG_namelist, file: !3, scope: !15, name: "nml", elements: !24)

dwarfdump :

. . .
0x000000b4: DW_TAG_variable [10]

DW_AT_name [DW_FORM_string]   ("a")
DW_AT_decl_file [DW_FORM_data1]       ("/dir/namelist.f90")
DW_AT_decl_line [DW_FORM_data1]       (20)
DW_AT_type [DW_FORM_ref4]     (cu + 0x006d => {0x0000006d} "integer(kind=4)")
DW_AT_declaration [DW_FORM_flag_present]      (true)
DW_AT_location [DW_FORM_exprloc]      (DW_OP_fbreg -20)

0x000000c0: DW_TAG_variable [10]

DW_AT_name [DW_FORM_string]   ("b")
DW_AT_decl_file [DW_FORM_data1]       ("/dir/namelist.f90")
DW_AT_decl_line [DW_FORM_data1]       (20)
DW_AT_type [DW_FORM_ref4]     (cu + 0x006d => {0x0000006d} "integer(kind=4)")
DW_AT_declaration [DW_FORM_flag_present]      (true)
DW_AT_location [DW_FORM_exprloc]      (DW_OP_fbreg -24)

. . .
0x000000dd: DW_TAG_namelist [12] *

DW_AT_name [DW_FORM_string]   ("nml")

0x000000e2: DW_TAG_namelist_item [9]

DW_AT_namelist_item [DW_FORM_ref4]  (cu + 0x00b4 => {0x000000b4})

0x000000e7: DW_TAG_namelist_item [9]

DW_AT_namelist_item [DW_FORM_ref4]  (cu + 0x00c0 => {0x000000c0})

0x000000ec: NULL

Diff Detail

Event Timeline

bhuvanendrakumarn requested review of this revision.Aug 23 2021, 6:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2021, 6:41 AM

updated the test cases

aprantl accepted this revision.Aug 27 2021, 12:42 PM

Looks reasonable.

This revision is now accepted and ready to land.Aug 27 2021, 12:42 PM
quinnp added a subscriber: quinnp.Aug 30 2021, 12:16 PM

Hi, this patch is breaking some of our PowerPC bots. For example: clang-ppc64le-linux-lnt.

Hi, this patch is breaking some of our PowerPC bots. For example: clang-ppc64le-linux-lnt.

@quinnp Please revert the patch since the author has neglected to respond to your ping or the build bot notifications. We need to get the bots back to green.

@bhuvanendrakumarn It would appear that the failing test case should have -O0 to prevent variable b from being optimized out. However, since I am not sure that is the desired fix, we'll revert the patch and you can feel free to fix it that way or whatever way is more appropriate.

@nemanjai @quinnp will update the tests accordingly and resubmit

@nemanjai @quinnp

could you please review the testcase (namelist1.ll) once, i have added -O0 now.

quinnp added a comment.EditedSep 1 2021, 1:04 PM

Hey @bhuvanendrakumarn, thanks so much for providing the fix! I tested the patch, looks good to me. When you recommit the patch keep an eye on the buildbots but I don't think there will be any issues.

Hey @bhuvanendrakumarn, thanks so much for providing the fix! I tested the patch, looks good to me. When you recommit the patch keep an eye on the buildbots but I don't think there will be any issues.

@nemanjai @quinnp

thanks for the confirmation, i have recommitted the same fix now, with the required test case changes