Re: fix for strict-alias warnings

From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: "PG Patches" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: fix for strict-alias warnings
Date: 2003-10-11 18:41:22
Message-ID: 013101c39027$44dd6470$6401a8c0@DUNSLANE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


----- Original Message -----
From: "Bruce Momjian" <pgman(at)candle(dot)pha(dot)pa(dot)us>
>
> I have backed out the patch.
>
> Looking at the case in tablecmds.c and proc.c, the first was assigning a
> struct with a NodeTag pointer as its first element to another struct
> with NodeTag as its first element. In fact, we do this all over the
> place, having different structure pointers with a start element of
> NodeTag.

Right - and it is what would have to change if you really want to obey the
ISO C rules, I believe. This is handled easily in other languages using
variant records, but C is kinda primitive here :-)

As I understand it, instead of

struct foo {
int tag
foostuff f;
}

struct bar {
int tag;
barstuff b;
}

you would need to do something like

struct foo {
foostuff f;
};

struct bar {
barstuff b;
};

struct foobar {
int tag;
union {
struct foo foo;
struct bar bar;
} v;
};

> The proc.c cases were using MemSet, which was checking if the
> int* as aligned for int* access. In fact, we could change MemSet to
> always take a void *, and do the int* casting when we access it after
> testing for alignment.
>

Since MemSet is generic, that is probably a good idea.

> The big question in my mind is whether there there is other struct *
> passing that could be masked right now by void* casting, and if so, do
> they have different first elements? This determined whether we do
> -fstrict-aliasing for gcc, or fix just these few cases.

Just analysing this is a non-trivial piece of work, I think.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2003-10-11 19:55:22 Re: fix for strict-alias warnings
Previous Message Bruce Momjian 2003-10-11 18:10:03 Re: fix for strict-alias warnings

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2003-10-11 19:55:22 Re: fix for strict-alias warnings
Previous Message Bruce Momjian 2003-10-11 18:10:03 Re: fix for strict-alias warnings