Re: fix for strict-alias warnings - Mailing list pgsql-patches

From Tom Lane
Subject Re: fix for strict-alias warnings
Date
Msg-id 11885.1066159891@sss.pgh.pa.us
Whole thread Raw
In response to Re: fix for strict-alias warnings  (Manfred Spraul <manfred@colorfullife.com>)
Responses Re: fix for strict-alias warnings  (Bruce Momjian <pgman@candle.pha.pa.us>)
Re: fix for strict-alias warnings  (Peter Eisentraut <peter_e@gmx.net>)
Re: fix for strict-alias warnings  (Manfred Spraul <manfred@colorfullife.com>)
List pgsql-patches
Manfred Spraul <manfred@colorfullife.com> writes:
> I've asked the question on the gcc devel list. The first reply was that
> MemSet violates strict aliasing rules:

No doubt it does, but that is not really the issue here; the issue IMHO
is whether there is any real risk involved.  Remember that the macro is
really of the form

    if (blah blah)
    {
        // unsafe code is here
    }
    else
    {
        memset(...);
    }

Given that gcc is smart enough not to move any code across the memset()
call, I doubt that it would be moving anything across the whole if()
construct.  Now if the if-condition were such that the memset code path
could be optimized away, then we'd have a problem, but in practice I do
not believe gcc is smart enough to realize that the alignment check is
always true.

We do have to be wary of MemSetAligned and MemSetLoop, but these are
only used in constrained places (routines that do nothing else with
the memory in question) so I think they are not a problem.

> I think we must either add -fno-strict-aliasing, or switch to the c
> compiler memset functions for gcc.

We will not be doing the latter, for certain.

            regards, tom lane

pgsql-patches by date:

Previous
From: Neil Conway
Date:
Subject: Re: fix for strict-alias warnings
Next
From: Bruce Momjian
Date:
Subject: Re: fix for strict-alias warnings