https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102627
Bug ID: 102627
Summary: wrong code with "-O1"
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: suochenyao at 163 dot com
Target Milestone: ---
*******************************************************************************
OS and Platform:
CentOS Linux release 7.8.2003 (Core).0, x86_64 GNU/Linux
*******************************************************************************
Program:
int printf(const char *, ...);
int a, f, l, m, q, c, d, g;
long b, e;
struct g {
signed h;
signed i;
unsigned j;
unsigned k;
};
unsigned n;
char o;
int *p = &m;
long(r)(s) { return s && b ?: b; }
long v() {
l = 0 || r(n & o);
return q;
}
void w(int, unsigned, struct g x) {
c ?: a;
for (; d < 2; d++)
*p = x.k;
}
struct g y() {
struct g h = {3, 908, 1, 20};
for (; g; g++)
;
return h;
}
int main() {
long t;
struct g u = y();
t = e << f;
w(0, t, u);
v(0, 4, 4, 4);
printf("%d\n", m);
}
*******************************************************************************
version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/data/bin/gcc-dev/bin/gcc
COLLECT_LTO_WRAPPER=/data/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/data/bin/gcc-dev/ --disable-multilib
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211006 (experimental) (GCC)
git ver: bb6194e0b44a8262d8de304be3bd3ee65187772a
*******************************************************************************
Command Lines:
$ gcc -O1 -Wall -Wextra -fno-strict-aliasing -fwrapv a.c -o a1.o
a.c: In function ‘r’:
a.c:13:6: warning: type of ‘s’ defaults to ‘int’ [-Wimplicit-int]
13 | long(r)(s) { return s && b ?: b; }
| ^
a.c:13:29: warning: the omitted middle operand in ‘?:’ will always be ‘true’,
suggest explicit middle operand [-Wparentheses]
13 | long(r)(s) { return s && b ?: b; }
| ^
$ gcc a.c -o a0.o
a.c: In function ‘r’:
a.c:13:6: warning: type of ‘s’ defaults to ‘int’ [-Wimplicit-int]
13 | long(r)(s) { return s && b ?: b; }
| ^
$ ./a1.o
0
$ ./a0.o
20