Skip to content

[flang][debug] Incorrect module variable scope when applying "use, only" #120307

@jiel-nv

Description

@jiel-nv

Code example,

module mod1
  integer :: a = 1
  integer :: b = 2
end module

subroutine sub1()
  use mod1, only : a
end subroutine

When using debugger to inspect variable from inside sub1, only a should be visible, but currently flang is giving the whole module imported to sub1.

!2 = !DIModule(scope: !4, name: "mod1", file: !3, line: 1)
!11 = distinct !DISubprogram(name: "sub1", linkageName: "sub1_", scope: !3, file: !3, line: 6, type: !12, scopeLine: 6, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !4, retainedNodes: !14)
!15 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !11, entity: !2, file: !3, line: 1)

The solution should be straight forward,
(1) change the tag: field of DIImportedEntity from DW_TAG_imported_module to DW_TAG_imported_declaration;
(2) change the entity: field of DIImportedEntity from referencing the module to refencing the variable;

!1 = distinct !DIGlobalVariable(name: "a", linkageName: "_QMmod1Ea", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
!2 = !DIModule(scope: !4, name: "mod1", file: !3, line: 1)
!11 = distinct !DISubprogram(name: "sub1", linkageName: "sub1_", scope: !3, file: !3, line: 6, type: !12, scopeLine: 6, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !4, retainedNodes: !14)
!15 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !11, entity: !1, file: !3, line: 1)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions