This is the mail archive of the gcc-patches@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]

[gfortran] Fix bug for size of array allocation


The size for array allocation is wrong. 
gfc_array_init_size (trans-array.c) already calculate 
the total size for the allocation array, but 
gfc_array_allocate duplicately multiply the array 
element size. This is one of the reason why gfortran 
failed to pass 191.fma3d of SPEC CFP2000.


Canqun Yang


2004-01-02  Canqun Yang  <canqun@nudt.edu.cn>

	* trans-array.c (gfc_array_allocate): Fix bug 
for array allocation
	size.
	(gfc_array_init_size): Correct the comment. 
The return value is the
	total size of the array.

! The allocation size for MOTION(1:174762) should be 
174762*48,
! instead of 174762*48*48.

PROGRAM alloc
   TYPE :: 
motion_type                                             
  
      REAL(KIND(0D0))  Px
      REAL(KIND(0D0))  Py
      REAL(KIND(0D0))  Pz
      REAL(KIND(0D0))  Ux
      REAL(KIND(0D0))  Uy
      REAL(KIND(0D0))  Uz
   END TYPE

   TYPE (motion_type), DIMENSION(:), ALLOCATABLE :: 
MOTION
   ALLOCATE (MOTION(1:174762), STAT=IFLAG)
END

diff -c fortran.save/ChangeLog ./fortran/ChangeLog
*** fortran.save/ChangeLog	2004-01-02 15:28:41.000000000 +0800
--- ./fortran/ChangeLog	2004-01-02 15:38:56.000000000 +0800
***************
*** 1,3 ****
--- 1,10 ----
+ 2004-01-02  Canqun Yang  <canqun@nudt.edu.cn>
+ 
+ 	* trans-array.c (gfc_array_allocate): Fix bug for array allocation
+ 	size.
+ 	(gfc_array_init_size): Correct the comment. The return value is the
+ 	total size of the array.
+ 
  2004-01-01  Steve Kargl  <sgk@troutmask.apl.washington.edu>
  
  	* match.c (gfc_match_pause): Fix spelling.
Common subdirectories: fortran.save/CVS and ./fortran/CVS
diff -c fortran.save/trans-array.c ./fortran/trans-array.c
*** fortran.save/trans-array.c	2004-01-02 15:28:41.000000000 +0800
--- ./fortran/trans-array.c	2004-01-02 15:38:41.000000000 +0800
***************
*** 2407,2413 ****
  
  /* Fills in an array descriptor, and returns the size of the array.  The size
     will be a simple_val, ie a variable or a constant.  Also calculates the
!    offset of the base.  Returns the number of elements in the arrary.
     {
      stride = 1;
      offset = 0;
--- 2407,2413 ----
  
  /* Fills in an array descriptor, and returns the size of the array.  The size
     will be a simple_val, ie a variable or a constant.  Also calculates the
!    offset of the base.
     {
      stride = 1;
      offset = 0;
***************
*** 2421,2427 ****
          size = ubound + size; //size = ubound + 1 - lbound
          stride = stride * size;
        }
!     return (stride);
     }  */
  /*GCC ARRAYS*/
  
--- 2421,2427 ----
          size = ubound + size; //size = ubound + 1 - lbound
          stride = stride * size;
        }
!     return (stride * element_size);
     }  */
  /*GCC ARRAYS*/
  
***************
*** 2582,2592 ****
    size = gfc_array_init_size (se->expr, ref->u.ar.as->rank, &offset,
  			      lower, upper, &se->pre, &len);
  
-   /* The size is the number of elements in the array, so multiply by the
-      size of an element to get the total size.  */
-   tmp = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (se->expr)));
-   size = fold (build (MULT_EXPR, gfc_array_index_type, size, tmp));
- 
    /* Allocate memory to store the data.  */
    tmp = gfc_conv_descriptor_data (se->expr);
    pointer = gfc_build_addr_expr (NULL, tmp);
--- 2582,2587 ----

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