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

From Andrew Dunstan
Subject Re: fix for strict-alias warnings
Date
Msg-id 013101c39027$44dd6470$6401a8c0@DUNSLANE
Whole thread Raw
In response to Re: fix for strict-alias warnings  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: fix for strict-alias warnings
Re: fix for strict-alias warnings
List pgsql-patches
----- Original Message -----
From: "Bruce Momjian" <pgman@candle.pha.pa.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


pgsql-patches by date:

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