Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC? - Mailing list pgsql-ports

From Tom Lane
Subject Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?
Date
Msg-id 3168.1121697358@sss.pgh.pa.us
Whole thread Raw
In response to building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?  (Andrew Morrow <andrew.c.morrow@gmail.com>)
List pgsql-ports
Andrew Morrow <andrew.c.morrow@gmail.com> writes:
> I am no language laywer, so I don't know for certain what is going on
> here, but it does seem to be that one of the following must be true:
> 1) There is something illegal/undefined about the address argument to
> memset in the original version, due to the int32 * and char * casts.

I think you are absolutely right --- the cast to int32* allows the
compiler to assume that the pointer is word-aligned, and even casting
it back to char * or void * at the memset call wouldn't really undo
the damage.  So really, correct coding of the macro should be along
the lines of

{               void   *_vstart = (void *)(start); \
                int     _val = (val); \
                Size    _len = (len); \
\
                if ((((long) _vstart) & INT_ALIGN_MASK) == 0 && \
                        (_len & INT_ALIGN_MASK) == 0 && \
                        _val == 0 && \
                        _len <= MEMSET_LOOP_LIMIT) \
                { \
                        int32 * _start = (int32 *) (_vstart); \
                        int32 * _stop = (int32 *) ((char *) _start + _len); \
                        while (_start < _stop) \
                                *_start++ = 0; \
                } \
                else \
                        memset(_vstart, _val, _len); \
        } while (0)

Interesting that we have not seen this before.

            regards, tom lane

pgsql-ports by date:

Previous
From: Andrew Morrow
Date:
Subject: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?
Next
From: Tom Lane
Date:
Subject: Re: building pg 8.0.1 with gcc-4.0.1: MemSet problems on SPARC?