Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread Jakub Jelinek
On Wed, Jun 07, 2017 at 05:16:44PM +0300, K wrote: > > ui16 *ptr = (ui16*)buf; > > > > There's no need for any of this messing about with pointer casts, as has > > been explained. > > > > Sorry, but I still can't get the idea. Cast from udp_pseudo to uint8_t > doesn't have an aliasing

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread K
On 06/07/2017 04:56 PM, Andrew Haley wrote: On 07/06/17 14:45, K wrote: And I found that that a version which I beleve mustn't have aliasing problems still generates same warnings. It still has aliasing problems: you can't make them magically go away by using an intermediate uint8_t*.

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread Andrew Haley
On 07/06/17 14:45, K wrote: > And I found that that a version which I beleve mustn't have aliasing > problems still generates same warnings. It still has aliasing problems: you can't make them magically go away by using an intermediate uint8_t*. You're doing this: struct udp_pseudo {

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread K
That snippet invokes undefined behavior at runtime (violates C++ aliasing rules), so just fix it, rather than bother with bugreports. E.g. look for -fstrict-aliasing in GCC documentation, or read the C++ standard. With -fno-strict-aliasing, which is a workaround for broken code you won't

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread David Brown
On 07/06/17 11:33, Andrew Haley wrote: > On 07/06/17 10:15, Kirill Yu Berezin wrote: >> My question is. Is this an expected behaviour or I must report a bug ? > > It's not a bug: your code displays undefined behaviour: you're casting > a pointer to struct udp_pseudo fields to an array of

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread Andrew Haley
On 07/06/17 10:15, Kirill Yu Berezin wrote: > My question is. Is this an expected behaviour or I must report a bug ? It's not a bug: your code displays undefined behaviour: you're casting a pointer to struct udp_pseudo fields to an array of uint16_t. This is never well-defined in C++, but if you

Re: "Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread Jakub Jelinek
On Wed, Jun 07, 2017 at 12:15:54PM +0300, Kirill Yu Berezin wrote: > Hello! > > I have a code snippet (actually it is a part of larger project): That snippet invokes undefined behavior at runtime (violates C++ aliasing rules), so just fix it, rather than bother with bugreports. E.g. look for

"Uninitialized array" warnings by c++ with -O2

2017-06-07 Thread Kirill Yu Berezin
Hello! I have a code snippet (actually it is a part of larger project): #include #define UDP_PROTO_NUMBER 17 uint32_t calc_16bit_checksum_part(uint8_t* buf, int len, uint32_t ret) { uint16_t *ptr = reinterpret_cast(buf); int i; for( i = 0; i < (len / 2);