From a9a05945da24b9ded567adcb3d81822463c82920 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Mon, 20 Apr 1998 16:42:50 +0000 Subject: [PATCH] * flow.c (sbitmap_vector_alloc): Ensure sbitmaps properly aligned. From-SVN: r19347 --- gcc/ChangeLog | 4 ++++ gcc/flow.c | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fbac26bdaf3..871f04dfbf1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +Mon Apr 20 12:43:09 1998 Doug Evans + + * flow.c (sbitmap_vector_alloc): Ensure sbitmaps properly aligned. + Mon Apr 20 15:04:14 1998 John Wehle (john@feith.com) * i386.md (movsf_push, movdf_push, movxf_push): Allow memory diff --git a/gcc/flow.c b/gcc/flow.c index 8e4da8ce166..d9cd7615f2f 100644 --- a/gcc/flow.c +++ b/gcc/flow.c @@ -3492,20 +3492,31 @@ sbitmap * sbitmap_vector_alloc (n_vecs, n_elms) int n_vecs, n_elms; { - int i, bytes, offset, elm_bytes, size, amt; + int i, bytes, offset, elm_bytes, size, amt, vector_bytes; sbitmap *bitmap_vector; size = SBITMAP_SET_SIZE (n_elms); bytes = size * sizeof (SBITMAP_ELT_TYPE); elm_bytes = (sizeof (struct simple_bitmap_def) + bytes - sizeof (SBITMAP_ELT_TYPE)); - amt = (n_vecs * sizeof (sbitmap *)) + (n_vecs * elm_bytes); + vector_bytes = n_vecs * sizeof (sbitmap *); + + /* Round up `vector_bytes' to account for the alignment requirements + of an sbitmap. One could allocate the vector-table and set of sbitmaps + separately, but that requires maintaining two pointers or creating + a cover struct to hold both pointers (so our result is still just + one pointer). Neither is a bad idea, but this is simpler for now. */ + { + /* Based on DEFAULT_ALIGNMENT computation in obstack.c. */ + struct { char x; SBITMAP_ELT_TYPE y; } align; + int alignment = (char *) & align.y - & align.x; + vector_bytes = (vector_bytes + alignment - 1) & ~ (alignment - 1); + } + + amt = vector_bytes + (n_vecs * elm_bytes); bitmap_vector = (sbitmap *) xmalloc (amt); - /* ??? There may be alignment problems, `offset' should be rounded up - each time to account for alignment. Later [if ever]. */ - - for (i = 0, offset = n_vecs * sizeof (sbitmap *); + for (i = 0, offset = vector_bytes; i < n_vecs; i++, offset += elm_bytes) {