Re: fix for strict-alias warnings

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manfred Spraul <manfred(at)colorfullife(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: fix for strict-alias warnings
Date: 2003-10-14 19:31:31
Message-ID: 11885.1066159891@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Manfred Spraul <manfred(at)colorfullife(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-10-14 19:31:42 Re: pg_ctl reload - is it safe?
Previous Message Neil Conway 2003-10-14 19:19:50 Re: fix for strict-alias warnings

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2003-10-14 19:37:28 Re: fix for strict-alias warnings
Previous Message Neil Conway 2003-10-14 19:19:50 Re: fix for strict-alias warnings