Re: Compiler bug or violation of strict aliasing rule?

[email protected] (Christos Zoulas)
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
In article <[email protected]>,
Rin Okuyama  <[email protected]> wrote:
>For aarch64eb, GCC 9 and 10 compile this "if" block of
>tests/net/net/t_tcp.c:
>
>https://nxr.netbsd.org/xref/src/tests/net/net/t_tcp.c#141
>
>    141          if (sfamily == AF_INET6 && cfamily == AF_INET) {
>    142                  ss = bs;
>    143                  sin6 = (void *)&ss;
>    144                  sin = (void *)&bs;
>    145                  addrlen = sizeof(*sin);
>    146  #ifdef BSD4_4
>    147                  sin->sin_len = sizeof(*sin);
>    148  #endif
>    149                  sin->sin_family = AF_INET;
>    150                  sin->sin_port = sin6->sin6_port;
>    151                  sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
>    152          }
>
>into a code, where fetch for "sin6->sin6_port" is preceding to
>structure copy "ss = bs".
>
>This is apparently not what the author of this code intended.
>
>However, I'm not sure whether this is a compiler bug, or a kind of
>violation of strict aliasing rule.
>
>Note that the emitted code is "fixed" if (1) -fno-strict-aliasing
>option is added, or (2) the attached patch is applied.
>
>Thoughts?

I'd apply the patch.

Thanks,

christos
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.