Re: struct sockaddr_storage

2023-01-24 Thread Alex Colomar via Gcc
nion [[gnu::transparent_union]] sockaddr_ptr { struct sockaddr_storage *ss; struct sockaddr *sa; }; void old_api(struct sockaddr_storage *ss) { // Here libc uses the union, so it doesn't invoke UB. ss->sun.sa_family = AF_UNIX; //... } v

Re: struct sockaddr_storage

2023-01-24 Thread Alex Colomar via Gcc
Hi Rick, On 1/24/23 12:16, Rich Felker wrote: On Fri, Jan 20, 2023 at 12:06:50PM +0200, Stefan Puiu via Libc-alpha wrote: Hi Alex, On Thu, Jan 19, 2023 at 4:14 PM Alejandro Colomar wrote: Hi! I just received a report about struct sockaddr_storage in the man pages. It reminded me of some

Re: struct sockaddr_storage

2023-01-24 Thread Alex Colomar via Gcc
Hi Jakub, On 1/23/23 17:37, Jakub Jelinek wrote: Please see transparent_union documentation in GCC documentation. E.g. https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Type-Attributes.html#index-transparent_005funion-type-attribute transparent_union doesn't change anything regarding type pu

Re: struct sockaddr_storage

2023-01-24 Thread Alex Colomar via Gcc
Hi Richard, On 1/23/23 17:28, Richard Biener wrote: The common initial sequence of structures is only allowed if the structures form part of a union (which is why to avoid UB you need a union; and still, you need to make sure you don't invoke UB in a different way).

Re: struct sockaddr_storage

2023-01-24 Thread Rich Felker
On Fri, Jan 20, 2023 at 12:06:50PM +0200, Stefan Puiu via Libc-alpha wrote: > Hi Alex, > > On Thu, Jan 19, 2023 at 4:14 PM Alejandro Colomar > wrote: > > > > Hi! > > > > I just received a report about struct sockaddr_storage in the man pages. It > > r

Re: struct sockaddr_storage

2023-01-23 Thread Jakub Jelinek via Gcc
On Mon, Jan 23, 2023 at 05:03:00PM +0100, Alejandro Colomar via Gcc wrote: > Hi Stefan, > > On 1/23/23 08:40, Stefan Puiu wrote: > > > > > According to strict aliasing rules, if you declare a variable of type > > > > > 'struct > > > >

Re: struct sockaddr_storage

2023-01-23 Thread Richard Biener via Gcc
On Mon, Jan 23, 2023 at 5:04 PM Alejandro Colomar via Gcc wrote: > > Hi Stefan, > > On 1/23/23 08:40, Stefan Puiu wrote: > >>>> According to strict aliasing rules, if you declare a variable of type > >>>> 'struct > >>>> sockaddr_s

Re: struct sockaddr_storage

2023-01-23 Thread Alejandro Colomar via Gcc
Hi Stefan, On 1/23/23 08:40, Stefan Puiu wrote: According to strict aliasing rules, if you declare a variable of type 'struct sockaddr_storage', that's what you get, and trying to access it later as some other sockaddr_8 is simply not legal. The compiler may assume those access

Re: struct sockaddr_storage

2023-01-22 Thread Stefan Puiu via Gcc
Hi Alex, On Fri, Jan 20, 2023 at 2:40 PM Alejandro Colomar wrote: > > Hi Stefan, > > On 1/20/23 11:06, Stefan Puiu wrote: > > Hi Alex, > > > > On Thu, Jan 19, 2023 at 4:14 PM Alejandro Colomar > > wrote: > >> > >> Hi! > >> > &g

Re: struct sockaddr_storage

2023-01-20 Thread Alejandro Colomar via Gcc
Hi Stefan, On 1/20/23 11:06, Stefan Puiu wrote: Hi Alex, On Thu, Jan 19, 2023 at 4:14 PM Alejandro Colomar wrote: Hi! I just received a report about struct sockaddr_storage in the man pages. It reminded me of some concern I've always had about it: it doesn't seem to be a usable

Re: struct sockaddr_storage

2023-01-20 Thread Stefan Puiu via Gcc
Hi Alex, On Thu, Jan 19, 2023 at 4:14 PM Alejandro Colomar wrote: > > Hi! > > I just received a report about struct sockaddr_storage in the man pages. It > reminded me of some concern I've always had about it: it doesn't seem to be a > usable type. > > It has

struct sockaddr_storage

2023-01-19 Thread Alejandro Colomar via Gcc
Hi! I just received a report about struct sockaddr_storage in the man pages. It reminded me of some concern I've always had about it: it doesn't seem to be a usable type. It has some alignment promises that make it "just work" most of the time, but it's still a UB