tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Compiler bug or violation of strict aliasing rule?



On 2021/11/05 3:48, Christos Zoulas wrote:
In article <b189f531-0837-be29-9053-1f33f01ac8ca%gmail.com@localhost>,
Rin Okuyama  <rokuyama.rk%gmail.com@localhost> 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 for your comment! I will commit the patch soon.

rin


Home | Main Index | Thread Index | Old Index