Patch for libgfortran PR 18891

Steve Ellcey sje@cup.hp.com
Fri Dec 10 17:38:00 GMT 2004


Here is a patch for PR 18891.  This was causing fortran programs which
had a write with no open to core dump on IA64 (which has
STRICT_ALIGNMENT) because libgfortran was doing an assignment of a long
into an unaligned buffer.  This patch changes the code to use memcpy
instead of an assignment.

Tested on ia64-hp-hpux11.23 with no regressions.  Ok to check in?

Steve Ellcey
sje@cup.hp.com

2004-12-10  Steve Ellcey  <sje@cup.hp.com>

	* libgfortran/io/transfer.c (us_write): Use memcpy instead 
	of assignment to fill unaligned buffer.
	(next_record_w): Ditto.


*** gcc.orig/libgfortran/io/transfer.c	Fri Dec 10 08:57:51 2004
--- gcc/libgfortran/io/transfer.c	Fri Dec 10 08:57:34 2004
*************** us_read (void)
*** 841,851 ****
  static void
  us_write (void)
  {
!   gfc_offset *p;
    int length;
  
    length = sizeof (gfc_offset);
!   p = (gfc_offset *) salloc_w (current_unit->s, &length);
  
    if (p == NULL)
      {
--- 841,852 ----
  static void
  us_write (void)
  {
!   char *p;
!   gfc_offset zero = 0;
    int length;
  
    length = sizeof (gfc_offset);
!   p = salloc_w (current_unit->s, &length);
  
    if (p == NULL)
      {
*************** us_write (void)
*** 853,859 ****
        return;
      }
  
!   *p = 0;			/* Bogus value for now.  */
    if (sfree (current_unit->s) == FAILURE)
      generate_error (ERROR_OS, NULL);
  
--- 854,860 ----
        return;
      }
  
!   memcpy (p, &zero, sizeof (gfc_offset));	/* Bogus value for now.  */
    if (sfree (current_unit->s) == FAILURE)
      generate_error (ERROR_OS, NULL);
  
*************** next_record_w (int done)
*** 1281,1287 ****
        if (p == NULL)
  	goto io_error;
  
!       *((gfc_offset *) p) = m;
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
--- 1282,1288 ----
        if (p == NULL)
  	goto io_error;
  
!       memcpy (p, &m, sizeof (gfc_offset));
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
*************** next_record_w (int done)
*** 1292,1298 ****
        if (p == NULL)
  	generate_error (ERROR_OS, NULL);
  
!       *((gfc_offset *) p) = m;
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
--- 1293,1299 ----
        if (p == NULL)
  	generate_error (ERROR_OS, NULL);
  
!       memcpy (p, &m, sizeof (gfc_offset));
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  



More information about the Fortran mailing list