This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug debug/37738] New: Fortran DW_TAG_common_block has incorrect placement/scope


gfortran:
(1) Merges all common blocks into a single one.
(2) Places this single common block into the first subroutine where it was
used.

Fix:
(1) The scope of the common block is only the subroutine where it is present.
    Each subroutine should have its own DW_TAG_common_block.
    Accessing variable imported by a common block in different subroutine does
    not access the common block - it creates a local variable there.
(2) (Placing the common block directly under CU not discussed - IMO wrong.)

Intel Fortran compiler IMO does it right.


subroutine a
  INTEGER*4 a_i
  common /block/a_i
  a_i = 1
end subroutine a
subroutine b
  INTEGER*4 b_i
  common /block/b_i
  a_i = 3
  b_i = 2
end subroutine b
subroutine c
  INTEGER*4 a_i
  common /block/a_i
  if (a_i .ne. 2) call abort
end subroutine c
program abc
  call a
  call b
  call c
end program abc


/opt/intel/fce/10.1.008/bin/ifort

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
 <1><68>: Abbrev Number: 3 (DW_TAG_subprogram)
  <2><8a>: Abbrev Number: 4 (DW_TAG_common_block)
   <3><a0>: Abbrev Number: 5 (DW_TAG_variable)
 <1><c8>: Abbrev Number: 3 (DW_TAG_subprogram)
  <2><ea>: Abbrev Number: 6 (DW_TAG_variable)
  <2><fa>: Abbrev Number: 4 (DW_TAG_common_block)
   <3><110>: Abbrev Number: 5 (DW_TAG_variable)
 <1><135>: Abbrev Number: 3 (DW_TAG_subprogram)
  <2><157>: Abbrev Number: 4 (DW_TAG_common_block)
   <3><16d>: Abbrev Number: 5 (DW_TAG_variable)
 <1><187>: Abbrev Number: 7 (DW_TAG_subprogram)

The section .debug_info contains:
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_language    : 14     (Fortran 95)
     DW_AT_name        : abc.f90
     DW_AT_producer    : Intel (R) Fortran Compiler Fixes RangesRelative
 <1><68>: Abbrev Number: 3 (DW_TAG_subprogram)
     DW_AT_name        : a
 <2><8a>: Abbrev Number: 4 (DW_TAG_common_block)
     DW_AT_name        : block_
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <3><a0>: Abbrev Number: 5 (DW_TAG_variable)
     DW_AT_name        : a_i
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <1><c8>: Abbrev Number: 3 (DW_TAG_subprogram)
     DW_AT_name        : b
 <2><ea>: Abbrev Number: 6 (DW_TAG_variable)
     DW_AT_name        : a_i
     DW_AT_location    : 2 byte block: 76 70    (DW_OP_breg6: -16)
 <2><fa>: Abbrev Number: 4 (DW_TAG_common_block)
     DW_AT_name        : block_
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <3><110>: Abbrev Number: 5 (DW_TAG_variable)
     DW_AT_name        : b_i
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <1><135>: Abbrev Number: 3 (DW_TAG_subprogram)
     DW_AT_name        : c
 <2><157>: Abbrev Number: 4 (DW_TAG_common_block)
     DW_AT_name        : block_
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <3><16d>: Abbrev Number: 5 (DW_TAG_variable)
     DW_AT_name        : a_i
     DW_AT_location    : 9 byte block: 3 70 45 68 0 0 0 0 0     (DW_OP_addr:
684570)
 <1><187>: Abbrev Number: 7 (DW_TAG_subprogram)
     DW_AT_calling_convention: 2        (program)
     DW_AT_name        : abc


GNU Fortran (GCC) version 4.4.0 20081005 (experimental)
(x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.4.0 20081005 (experimental), GMP version
4.2.2, MPFR version 2.3.1.

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
  <2><4b>: Abbrev Number: 3 (DW_TAG_common_block)
   <3><5c>: Abbrev Number: 4 (DW_TAG_variable)
   <3><72>: Abbrev Number: 4 (DW_TAG_variable)
   <3><88>: Abbrev Number: 4 (DW_TAG_variable)
 <1><a7>: Abbrev Number: 2 (DW_TAG_subprogram)
  <2><c5>: Abbrev Number: 6 (DW_TAG_variable)
 <1><db>: Abbrev Number: 7 (DW_TAG_subprogram)

The section .debug_info contains:
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    < c>   DW_AT_producer    : (indirect string, offset: 0x1e): GNU Fortran
4.4.0 20081005 (experimental)
    <10>   DW_AT_language    : 14       (Fortran 95)
    <11>   DW_AT_name        : (indirect string, offset: 0x0): abc.f90
 <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <2f>   DW_AT_name        : a
 <2><4b>: Abbrev Number: 3 (DW_TAG_common_block)
    <4c>   DW_AT_name        : (indirect string, offset: 0x8): block
    <52>   DW_AT_location    : 9 byte block: 3 0 c 60 0 0 0 0 0        
(DW_OP_addr: 600c00)
 <3><5c>: Abbrev Number: 4 (DW_TAG_variable)
    <5d>   DW_AT_name        : a_i
    <68>   DW_AT_location    : 9 byte block: 3 0 c 60 0 0 0 0 0        
(DW_OP_addr: 600c00)
 <3><72>: Abbrev Number: 4 (DW_TAG_variable)
    <73>   DW_AT_name        : b_i
    <7e>   DW_AT_location    : 9 byte block: 3 0 c 60 0 0 0 0 0        
(DW_OP_addr: 600c00)
 <3><88>: Abbrev Number: 4 (DW_TAG_variable)
    <89>   DW_AT_name        : a_i
    <94>   DW_AT_location    : 9 byte block: 3 0 c 60 0 0 0 0 0        
(DW_OP_addr: 600c00)
 <1><a7>: Abbrev Number: 2 (DW_TAG_subprogram)
    <a9>   DW_AT_name        : b
 <2><c5>: Abbrev Number: 6 (DW_TAG_variable)
    <c6>   DW_AT_name        : a_i
    <d0>   DW_AT_location    : 2 byte block: 91 6c      (DW_OP_fbreg: -20)
 <1><db>: Abbrev Number: 7 (DW_TAG_subprogram)
    <dd>   DW_AT_name        : c
 <1><f5>: Abbrev Number: 8 (DW_TAG_subprogram)
    <f7>   DW_AT_name        : abc
    <111>   DW_AT_calling_convention: 2 (program)


-- 
           Summary: Fortran DW_TAG_common_block has incorrect
                    placement/scope
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jan dot kratochvil at redhat dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37738


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]