User account creation filtered due to spam.

Bug 22244 - dimension information is lost for multi-dimension array
Summary: dimension information is lost for multi-dimension array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: wrong-debug
Depends on:
Blocks: 24546 19292
  Show dependency treegraph
 
Reported: 2005-06-30 06:37 UTC by Wu Zhou
Modified: 2007-12-09 22:53 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-12 10:50:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wu Zhou 2005-06-30 06:37:33 UTC
Please have a look at the following source, variable "a" is a two-dimension 
array (5 X 5):

       program array2
       integer a(5, 5)

       do i = 1, 5
         do j = 1, 5
           a(i, j) = i * j
           write (*, *) a(i, j)
         end do
       end do

       end program

After using gfortran to compile it, use "readelf -wi array2" to see the 
outputed debuginfo:

 <2><89>: Abbrev Number: 3 (DW_TAG_variable)
     DW_AT_name        : a
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 2
     DW_AT_type        : <be>
     DW_AT_location    : 3 byte block: 75 94 7f         (DW_OP_breg5: -108)

 ...
 <1><be>: Abbrev Number: 7 (DW_TAG_array_type)
     DW_AT_type        : <b6>
 <2><c3>: Abbrev Number: 8 (DW_TAG_subrange_type)
     DW_AT_type        : <b6>
     DW_AT_lower_bound : 0
     DW_AT_upper_bound : 24
     
From the above, we can see that two-dimension array a(5, 5) is flatten to
a one-dimension array with 25 elements (0 - 24).  This will hinder GDB from 
correctly inteprete "a". 

This might also has some other negative impacts.  Feng Wang ever said that (I 
put him in the CC list): 

It's not only gdb problem, but also affects performance and optimization on the
tree-level. We lose the dimension infomation and can not get correct data
dependency. This limits many optimizations like loop interchange and loop
distribution, etc.
Comment 1 Wu Zhou 2005-06-30 06:39:38 UTC
This is Feng's comment:

http://gcc.gnu.org/ml/fortran/2005-06/msg00479.html

Just FYI.  Thanks. 
Comment 2 Thomas Koenig 2005-06-30 08:42:44 UTC
Confirmed.
Comment 3 Andrew Pinski 2005-06-30 12:20:24 UTC
Confirmed, Paul B. said he was going to do this (IIRC).
Comment 4 Thomas Koenig 2005-06-30 13:29:33 UTC
g77 gets this right:

$ g77 -g array2.f
$ gdb ./a.out
GNU gdb Red Hat Linux (6.3.0.0-0.30.1rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "ia64-redhat-linux-gnu"...Using host libthread_db 
library "/lib/tls/libthread_db.so.1".

(gdb) b array2.f:8
Breakpoint 1 at 0x4000000000000db2: file array2.f, line 8.
(gdb) r
Starting program: /home/zfkts/Krempel/a.out

Breakpoint 1, MAIN__ () at array2.f:8
8                  write (*, *) a(i, j)
Current language:  auto; currently fortran
(gdb) p a
$1 = (( 1, 0, 65598, 0, -1357861061) ( -597610038, 65544, 0, -2147483648, -
169227304) ( 65513, 0, 0, -2019811328, 65515) ( 0, 448693, 0, 65598, 0) ( 0, 0, 
0, 0, 0) )
(gdb) p a(1,1)
$2 = 1
Comment 5 Andrew Pinski 2006-01-09 23:31:05 UTC
Also this causes us to lose information lowering in the middle-end that what the size of the arrays were.
Comment 6 Tom Horsley 2006-08-03 13:45:19 UTC
I'd add that this isn't a problem just for multi-dimension arrays. If you
declare different arrays like "integer a1(5)" "integer a2(1:5)" "integer a3(2:6)"
they all show up with incorrect lower bound of 0 and upper bound of 4, making
it impossible to actually reference the correct array element in a subscript
expression in a debugger.
Comment 7 Jakub Jelinek 2007-08-28 16:09:17 UTC
Subject: Bug 22244

Author: jakub
Date: Tue Aug 28 16:08:57 2007
New Revision: 127864

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127864
Log:
	PR fortran/22244
	* Make-lang.in (fortran/trans-types.o): Depend on $(FLAGS_H).
	* trans-types.c: Include flags.h.
	(gfc_get_nodesc_array_type): Add TYPE_DECL TYPE_NAME with
	correct bounds and dimensions for packed arrays.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/Make-lang.in
    trunk/gcc/fortran/trans-types.c

Comment 8 Jakub Jelinek 2007-09-25 09:32:54 UTC
Subject: Bug 22244

Author: jakub
Date: Tue Sep 25 09:32:44 2007
New Revision: 128747

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128747
Log:
	PR fortran/22244
	* Make-lang.in (fortran/trans-types.o): Depend on $(FLAGS_H).
	* trans-types.c: Include flags.h.
	(gfc_get_nodesc_array_type): Add TYPE_DECL TYPE_NAME with
	correct bounds and dimensions for packed arrays.

Modified:
    branches/redhat/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/redhat/gcc-4_1-branch/gcc/fortran/Make-lang.in
    branches/redhat/gcc-4_1-branch/gcc/fortran/trans-types.c

Comment 9 Tobias Schlüter 2007-10-04 21:46:49 UTC
Can this be closed?
Comment 10 Francois-Xavier Coudert 2007-11-02 18:26:21 UTC
I think there are other issues with array information, so I think this PR shouldn't be closed yet.
Comment 11 Jakub Jelinek 2007-11-12 10:50:45 UTC
Attempt to deal with assumed shape, allocated etc. arrays:
http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00612.html
Does not yet implement the DW_AT_associated and DW_AT_allocated attributes.
For those, guess for ALLOCATABLE, but non-POINTER, DW_AT_allocated could be just
a test whether varx.data != NULL.  For POINTER I have no idea yet.
Any help would be appreciated.
Comment 12 Tobias Burnus 2007-11-27 09:56:42 UTC
I think the patch also fixes PR 17905.
Current patch links:
  http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00888.html
  http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00903.html

Comment 13 Jakub Jelinek 2007-12-09 17:08:20 UTC
Subject: Bug 22244

Author: jakub
Date: Sun Dec  9 17:08:06 2007
New Revision: 130724

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130724
Log:
	PR fortran/22244
	* langhooks-def.h (LANG_HOOKS_GET_ARRAY_DESCR_INFO): Define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add it.
	* langhooks.h (struct array_descr_info): Forward declaration.
	(struct lang_hooks_for_types): Add get_array_descr_info field.
	* dwarf2.h (DW_AT_bit_stride, DW_AT_byte_stride): New.
	(DW_AT_stride_size, DW_AT_stride): Keep around for Dwarf2
	compatibility.
	* dwarf2out.h (struct array_descr_info): New type.
	* dwarf2out.c (dwarf_attr_name): Rename DW_AT_stride to
	DW_AT_byte_stride and DW_AT_stride_size to DW_AT_bit_size.
	(descr_info_loc, add_descr_info_field, gen_descr_array_type_die):
	New functions.
	(gen_type_die_with_usage): Call lang_hooks.types.get_array_descr_info
	and gen_descr_array_type_die.

	* trans.h (struct array_descr_info): Forward declaration.
	(gfc_get_array_descr_info): New prototype.
	(enum gfc_array_kind): New type.
	(struct lang_type): Add akind field.
	(GFC_TYPE_ARRAY_AKIND): Define.
	* trans-types.c: Include dwarf2out.h.
	(gfc_build_array_type): Add akind argument.  Adjust
	gfc_get_array_type_bounds call.
	(gfc_get_nodesc_array_type): Include proper debug info even for
	assumed-size arrays.
	(gfc_get_array_type_bounds): Add akind argument, set
	GFC_TYPE_ARRAY_AKIND to it.
	(gfc_sym_type, gfc_get_derived_type): Adjust gfc_build_array_type
	callers.
	(gfc_get_array_descr_info): New function.
	* trans-array.c (gfc_trans_create_temp_array,
	gfc_conv_expr_descriptor): Adjust gfc_get_array_type_bounds
	callers.
	* trans-stmt.c (gfc_trans_pointer_assign_need_temp): Likewise.
	* trans-types.h (gfc_get_array_type_bounds): Adjust prototype.
	* Make-lang.in (fortran/trans-types.o): Depend on dwarf2out.h.
	* f95-lang.c (LANG_HOOKS_GET_ARRAY_DESCR_INFO): Define.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2.h
    trunk/gcc/dwarf2out.c
    trunk/gcc/dwarf2out.h
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/Make-lang.in
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans-types.h
    trunk/gcc/fortran/trans.h
    trunk/gcc/langhooks-def.h
    trunk/gcc/langhooks.h

Comment 14 Tobias Burnus 2007-12-09 22:53:30 UTC
Close as FIXED (on the trunk/4.3.0). Note, for debugging multi-dimensional arrays one also needs the following gdb patch:
  http://sourceware.org/ml/gdb-patches/2007-11/msg00438.html