This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4] Fix PR fortran/17180
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 1 Sep 2004 09:25:48 +0200
- Subject: [3.4] Fix PR fortran/17180
This PR records the gazillion of failures in the F77 testsuite that appeared
in mid-July on SPARC 32-bit.
[Mark, sorry for not fixing them earlier, F77 was accidentally disabled in my
latest builds and then I went on vacation...]
The patch http://gcc.gnu.org/ml/gcc-patches/2004-07/msg01136.html introduced
2 problems:
- a mix of sizeof(mallocArea_ *) and sizeof(mallocArea_) in the pointer
arithmetics (with no actual consequence),
- the loss of the alignment properties of the pointer returned by the system
malloc, which leads to bus errors at runtime when the code attempts to store
a 8-byte value to an unaligned address.
Bootstrapped/regtested (3.4 branch, C and F77) on x86, sparc32 and sparc64,
approved by Mark, applied to 3.4 branch.
2004-09-01 Eric Botcazou <ebotcazou@libertysurf.fr>
PR fortran/17180
* malloc.c (MALLOC_ALIGNMENT): New constant.
(ROUNDED_AREA_SIZE): Likewise.
(malloc_kill_area_): Use ROUNDED_AREA_SIZE.
(malloc_find_inpool_): Likewise.
(malloc_new_inpool_): Likewise.
(malloc_resize_inpool_): Likewise.
--
Eric Botcazou
Index: malloc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/f/Attic/malloc.c,v
retrieving revision 1.12.14.1
diff -u -p -r1.12.14.1 malloc.c
--- malloc.c 12 Jul 2004 17:58:36 -0000 1.12.14.1
+++ malloc.c 31 Aug 2004 17:31:49 -0000
@@ -83,6 +83,9 @@ static void malloc_verify_area_ (mallocP
/* Internal macros. */
+#define MALLOC_ALIGNMENT (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
+#define ROUNDED_AREA_SIZE (MALLOC_ALIGNMENT * ((sizeof(mallocArea_) + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT))
+
#if MALLOC_DEBUG
#define malloc_kill_(ptr,s) do {memset((ptr),127,(s));free((ptr));} while(0)
#else
@@ -101,7 +104,7 @@ malloc_kill_area_ (mallocPool pool UNUSE
#if MALLOC_DEBUG
assert (strcmp (a->name, ((char *) (a->where)) + a->size) == 0);
#endif
- malloc_kill_ (a->where - sizeof(mallocArea_*), a->size);
+ malloc_kill_ (a->where - ROUNDED_AREA_SIZE, a->size);
a->next->previous = a->previous;
a->previous->next = a->next;
#if MALLOC_DEBUG
@@ -302,10 +305,10 @@ malloc_display_ (mallocArea_ a UNUSED)
Search for object in list of mallocArea_s, die if not found. */
mallocArea_
-malloc_find_inpool_ (mallocPool pool, void *ptr)
+malloc_find_inpool_ (mallocPool pool UNUSED, void *ptr)
{
mallocArea_ *t;
- t = (mallocArea_ *) (ptr - sizeof(mallocArea_));
+ t = (mallocArea_ *) (ptr - ROUNDED_AREA_SIZE);
return *t;
}
@@ -387,14 +390,14 @@ malloc_new_inpool_ (mallocPool pool, mal
|| malloc_pool_find_ (pool, malloc_pool_image ()));
#endif
- ptr = malloc_new_ (sizeof(mallocArea_*) + s + (i = (MALLOC_DEBUG ? strlen (name) + 1 : 0)));
+ ptr = malloc_new_ (ROUNDED_AREA_SIZE + s + (i = (MALLOC_DEBUG ? strlen (name) + 1 : 0)));
#if MALLOC_DEBUG
strcpy (((char *) (ptr)) + s, name);
#endif
a = malloc_new_ (offsetof (struct _malloc_area_, name) + i);
temp = (mallocArea_ *) ptr;
*temp = a;
- ptr = ptr + sizeof(mallocArea_*);
+ ptr = ptr + ROUNDED_AREA_SIZE;
switch (type)
{ /* A little optimization to speed up killing
of non-permanent stuff. */
@@ -487,10 +490,10 @@ malloc_resize_inpool_ (mallocPool pool,
assert (a->size == os);
assert (strcmp (a->name, ((char *) (ptr)) + os) == 0);
#endif
- ptr = malloc_resize_ (ptr - sizeof(mallocArea_*), sizeof(mallocArea_*) + ns + (MALLOC_DEBUG ? strlen (a->name) + 1: 0));
+ ptr = malloc_resize_ (ptr - ROUNDED_AREA_SIZE, ROUNDED_AREA_SIZE + ns + (MALLOC_DEBUG ? strlen (a->name) + 1: 0));
temp = (mallocArea_ *) ptr;
*temp = a;
- ptr = ptr + sizeof(mallocArea_*);
+ ptr = ptr + ROUNDED_AREA_SIZE;
a->where = ptr;
#if MALLOC_DEBUG
a->size = ns;