This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] Fix unformatted_backspace
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: fortran at gcc dot gnu dot org
- Date: Fri, 8 Apr 2005 20:44:38 +0200
- Subject: [PATCH] Fix unformatted_backspace
Hi,
unformatted_backspace cannot work on strict alignment machines:
gfc_offset *p, new;
int length;
length = sizeof (gfc_offset);
p = (gfc_offset *) salloc_r_at (current_unit->s, &length,
file_position (current_unit->s) - length);
if (p == NULL)
goto io_error;
new = file_position (current_unit->s) - *p - 2*length;
AFAICS nothing guarantees that p will be sufficient aligned to be dereferenced
as a gfc_offset* pointer. The code must, therefore, go through the same
hoops as next_record_w.
Tested x86_64-suse-linux, sparc64-sun-solaris2.9 and sparc-sun-solaris2.[5678]
where it fixes:
FAIL: gfortran.dg/backspace.f -O0 execution test
FAIL: gfortran.dg/backspace.f -O1 execution test
FAIL: gfortran.dg/backspace.f -O2 execution test
FAIL: gfortran.dg/backspace.f -O3 -fomit-frame-pointer execution test
FAIL: gfortran.dg/backspace.f -O3 -fomit-frame-pointer -funroll-loops
execution test
FAIL: gfortran.dg/backspace.f -O3 -fomit-frame-pointer -funroll-all-loops
-finline-functions execution test
FAIL: gfortran.dg/backspace.f -O3 -g execution test
FAIL: gfortran.dg/backspace.f -Os execution test
OK for mainline and 4.0 branch?
2005-04-08 Eric Botcazou <ebotcazou@libertysurf.fr>
* io/backspace.c (unformatted_backspace): Do not dereference
the pointer to the stream.
--
Eric Botcazou
Index: io/backspace.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/backspace.c,v
retrieving revision 1.9.12.1
diff -u -p -r1.9.12.1 backspace.c
--- io/backspace.c 3 Apr 2005 08:04:03 -0000 1.9.12.1
+++ io/backspace.c 8 Apr 2005 18:21:17 -0000
@@ -28,6 +28,7 @@ the Free Software Foundation, 59 Temple
Boston, MA 02111-1307, USA. */
#include "config.h"
+#include <string.h>
#include "libgfortran.h"
#include "io.h"
@@ -101,17 +102,19 @@ formatted_backspace (void)
static void
unformatted_backspace (void)
{
- gfc_offset *p, new;
+ gfc_offset m, new;
int length;
+ char *p;
length = sizeof (gfc_offset);
- p = (gfc_offset *) salloc_r_at (current_unit->s, &length,
- file_position (current_unit->s) - length);
+ p = salloc_r_at (current_unit->s, &length,
+ file_position (current_unit->s) - length);
if (p == NULL)
goto io_error;
- new = file_position (current_unit->s) - *p - 2*length;
+ memcpy (&m, p, sizeof (gfc_offset));
+ new = file_position (current_unit->s) - m - 2*length;
if (sseek (current_unit->s, new) == FAILURE)
goto io_error;