This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
libgfortran patch for PR target/23556 (strict alignment fix)
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Aug 2005 14:17:13 -0700 (PDT)
- Subject: libgfortran patch for PR target/23556 (strict alignment fix)
- Reply-to: sje at cup dot hp dot com
PR target/23556 is a PA64 bug report but the problem can affect any
system that requires strict alignment. The buffer passed in to
convert_real is 'void *' and may not be aligned according to the
requirements of the various floating point types. This patch uses
temporary variables to hold the value and memcpy to put the value into
the buffer.
Tested on HPPA 32 and 64 bits and on IA64 HP-UX and Linux.
OK for checkin?
Steve Ellcey
sje@cup.hp.com
2005-08-30 Steve Ellcey <sje@cup.hp.com>
PR target/23556
* io/read.c (convert_real): Use memcpy to fill buffer.
*** gcc.orig/libgfortran/io/read.c Tue Aug 30 14:11:54 2005
--- gcc/libgfortran/io/read.c Tue Aug 30 14:12:03 2005
*************** convert_real (void *dest, const char *bu
*** 124,147 ****
switch (length)
{
case 4:
! *((GFC_REAL_4 *) dest) =
#if defined(HAVE_STRTOF)
! strtof (buffer, NULL);
#else
! (GFC_REAL_4) strtod (buffer, NULL);
#endif
break;
case 8:
! *((GFC_REAL_8 *) dest) = strtod (buffer, NULL);
break;
#if defined(HAVE_GFC_REAL_10) && defined (HAVE_STRTOLD)
case 10:
! *((GFC_REAL_10 *) dest) = strtold (buffer, NULL);
break;
#endif
#if defined(HAVE_GFC_REAL_16) && defined (HAVE_STRTOLD)
case 16:
! *((GFC_REAL_16 *) dest) = strtold (buffer, NULL);
break;
#endif
default:
--- 124,159 ----
switch (length)
{
case 4:
! {
! GFC_REAL_4 tmp =
#if defined(HAVE_STRTOF)
! strtof (buffer, NULL);
#else
! (GFC_REAL_4) strtod (buffer, NULL);
#endif
+ memcpy (dest, (void *) &tmp, length);
+ }
break;
case 8:
! {
! GFC_REAL_8 tmp = strtod (buffer, NULL);
! memcpy (dest, (void *) &tmp, length);
! }
break;
#if defined(HAVE_GFC_REAL_10) && defined (HAVE_STRTOLD)
case 10:
! {
! GFC_REAL_10 tmp = strtold (buffer, NULL);
! memcpy (dest, (void *) &tmp, length);
! }
break;
#endif
#if defined(HAVE_GFC_REAL_16) && defined (HAVE_STRTOLD)
case 16:
! {
! GFC_REAL_16 tmp = strtold (buffer, NULL);
! memcpy (dest, (void *) &tmp, length);
! }
break;
#endif
default: