[MLton] cast-increases-required-alignment warnings

Matthew Fluet fluet@cs.cornell.edu
Tue, 16 May 2006 07:44:45 -0400 (EDT)


>  gc/generational.c:156: warning: cast increases required alignment of target type
>
>  s->generationalMaps.crossMap =
>    (GC_crossMapElem*)((pointer)s->generationalMaps.cardMap + cardMapSize);

I believe that this line could be safely rewritten to:

   s->generationalMaps.crossMap =
     s->generationalMaps.cardMap + (cardMapSize / CARD_MAP_ELEM_SIZE);

The cast to (pointer) is there to ensure that cardMapSize is interpreted 
as a byte offset.

>  gc/generational.c:180: warning: cast increases required alignment of target type
>  gc/generational.c:180: warning: cast increases required alignment of target type
>
>    GC_memcpy ((pointer)oldCrossMap, (pointer)s->generationalMaps.crossMap,
>               min (s->generationalMaps.crossMapLength * CROSS_MAP_ELEM_SIZE,
>                    oldCrossMapSize));

I don't see any simple solution here; we could change the prototype on 
GC_memcpy, though that code asserts that the pointers are aligned to 
sizeof(unsigned int).  Another option besides a union type would be to 
change the typedefs for GC_cardMapElem to be:

   typedef uint8_t GC_cardMapElem __attribute__ ((aligned (4)));

>  basis/Real/modf.c:10: warning: cast increases required alignment of target type

This could be solved with code similar to Real64_fetch and Real64_store 
from include/c-chunk.h.  This is precisely a situation where we might have 
misaligned doubles.

>  gc/int-inf.c:360: warning: cast increases required alignment of target type
>
>  setFrontier (&gcState, (pointer)(&sp->chars[size]), bytes);

>  gc/int-inf.c:364: warning: cast increases required alignment of target type
>
>  return pointerToObjptr ((pointer)&sp->chars, gcState.heap.start);

No good ideas here.