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] Patch: Fix PR 13415


PR 13415 was a problem with array pointers in common blocks: we failed
when trying to calculate the array size, when in fact we should have
been storing the array descriptor.

Built and tested on i686-pc-linux. Since the original code had some
reminiscences of its origin in g95, there are whitespace changes in the
patch, I also changed the variable names to something more expressive.

trans-common.c is in fact full of trailing whitespace, which I will
remove in a follow-up patch, and, if people agree, I will change some
variable names to something more expressive also in other functions.
Since I won't be intermingling those changes with functional changes
those changes shouldn't hurt.

Anyway, patch below. I will also add a testcase to the testsuite.

- Tobi

204-07-09  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/13415
	* trans-common.c (calculate_length): Correctly handle arrays
	whose descriptor ends up in the common block.

Index: trans-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-common.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 trans-common.c
*** trans-common.c      29 Jun 2004 22:11:38 -0000      1.9
--- trans-common.c      9 Jul 2004 19:42:17 -0000
*************** find_segment_info (gfc_symbol *symbol)
*** 457,479 ****

  static HOST_WIDE_INT
  calculate_length (gfc_symbol *symbol)
! {
!   HOST_WIDE_INT j, element_size;
!   mpz_t elements;

    if (symbol->ts.type == BT_CHARACTER)
      gfc_conv_const_charlen (symbol->ts.cl);
    element_size = int_size_in_bytes (gfc_typenode_for_spec (&symbol->ts));
-   if (symbol->as == NULL)
-     return element_size;

!   /* Calculate the number of elements in the array */
!   if (spec_size (symbol->as, &elements) == FAILURE)
      gfc_internal_error ("calculate_length(): Unable to determine array
size");
!   j = mpz_get_ui (elements);
!   mpz_clear (elements);

!   return j*element_size;;
  }


--- 457,482 ----

  static HOST_WIDE_INT
  calculate_length (gfc_symbol *symbol)
! {
!   HOST_WIDE_INT n, element_size;
!   mpz_t num_elements;

    if (symbol->ts.type == BT_CHARACTER)
      gfc_conv_const_charlen (symbol->ts.cl);
+
+   if (symbol->as == NULL || !gfc_is_nodesc_array (symbol))
+     /* In the array case, we need the size of the array descriptor.  */
+     return int_size_in_bytes (gfc_sym_type (symbol));
+
+   /* Calculate the size of the array, which is
element_size*num_elements.  */
    element_size = int_size_in_bytes (gfc_typenode_for_spec (&symbol->ts));

!   if (spec_size (symbol->as, &num_elements) == FAILURE)
      gfc_internal_error ("calculate_length(): Unable to determine array
size");
!   n = mpz_get_ui (num_elements);
!   mpz_clear (num_elements);

!   return n*element_size;
  }



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