Open
Description
The following code snippet, clang-14
and clang-17
at -O2/3/s produces the wrong code. clang-12
has no problem.
$ cat test.c
int printf(const char *, ...);
int __attribute__((noinline))
f(int *pi, long *pl)
{
*pi = 1;
*pl = 0;
return *(char *)pi;
}
int main()
{
union { long l; int i; } a;
if (f (&a.i, &a.l) != 0)
printf("error\n");
return 0;
}
$
$ clang-12 test.c -O0; ./a.out
$ clang-12 test.c -O1; ./a.out
$ clang-12 test.c -O2; ./a.out
$ clang-12 test.c -O3; ./a.out
$ clang-12 test.c -Os; ./a.out
$
$ clang-14 test.c -O0; ./a.out
$ clang-14 test.c -O1; ./a.out
error
$ clang-14 test.c -O2; ./a.out
error
$ clang-14 test.c -O3; ./a.out
error
$ clang-14 test.c -Os; ./a.out
error
$
$ clang-17 test.c -O0; ./a.out
$ clang-17 test.c -O1; ./a.out
error
$ clang-17 test.c -O2; ./a.out
error
$ clang-17 test.c -O3; ./a.out
error
$ clang-17 test.c -Os; ./a.out
error
$ clang-12 --version
Ubuntu clang version 12.0.1-++20211102090516+fed41342a82f-1~exp1~20211102211019.11
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$
$ clang-14 --version
Ubuntu clang version 14.0.6
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$
$ clang-17 --version
Ubuntu clang version 17.0.6 (++20231208085808+6009708b4367-1~exp1~20231208085905.78)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin