public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu
@ 2022-07-03 8:40 zhendong.su at inf dot ethz.ch
2022-07-03 8:41 ` [Bug tree-optimization/106171] " zhendong.su at inf dot ethz.ch
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2022-07-03 8:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
Bug ID: 106171
Summary: wrong code at -O1 and above on x86_64-linux-gnu
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zhendong.su at inf dot ethz.ch
Target Milestone: ---
It appears to be quite long-latent, and affects all versions 7.* and later.
[560] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--prefix=/local/suz-local/software/local/gcc-trunk --enable-sanitizers
--enable-languages=c,c++ --disable-werror --enable-multilib --with-system-zlib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20220703 (experimental) [master r13-1411-ga26f3eb2683] (GCC)
[561] %
[561] % gcctk -O0 small.c; ./a.out
1
[562] % gcctk -O1 small.c; ./a.out
0
[563] % gcctk -Os small.c; ./a.out
-2089837456
[564] % gcctk -O2 small.c; ./a.out
0
[565] % gcctk -O3 small.c; ./a.out
0
[566] %
[566] % cat small.c
int printf(const char *, ...);
int a, b;
int c() {
int d = 0;
for (; d < 2; d++) {
int e[2];
for (; b < 2; b++)
e[b] = 1;
if (d)
return e[0];
}
return 0;
}
int main() {
a = c();
printf("%d\n", a);
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2022-07-03 8:41 ` zhendong.su at inf dot ethz.ch
2022-07-03 10:20 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2022-07-03 8:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
--- Comment #1 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
Compiler Explorer: https://godbolt.org/z/eEhKn8x9T
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2022-07-03 8:41 ` [Bug tree-optimization/106171] " zhendong.su at inf dot ethz.ch
@ 2022-07-03 10:20 ` jakub at gcc dot gnu.org
2022-07-03 10:58 ` zhendong.su at inf dot ethz.ch
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-07-03 10:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Isn't that UB? Both e[0] and e[1] initialized in the first loop when d == 0,
but not used there, then e goes out of scope, in the d == 1 iteration e is
uninitialized, nothing initializes it and e[0] is returned.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2022-07-03 8:41 ` [Bug tree-optimization/106171] " zhendong.su at inf dot ethz.ch
2022-07-03 10:20 ` jakub at gcc dot gnu.org
@ 2022-07-03 10:58 ` zhendong.su at inf dot ethz.ch
2022-07-03 11:15 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2022-07-03 10:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
--- Comment #3 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
Yes, you're right, Jakub.
Then, it's a false negative for the sanitizers.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
` (2 preceding siblings ...)
2022-07-03 10:58 ` zhendong.su at inf dot ethz.ch
@ 2022-07-03 11:15 ` jakub at gcc dot gnu.org
2022-07-03 11:16 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-07-03 11:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
We don't have uninitialized memory sanitizer.
-fsanitize-address-use-after-scope doesn't trigger because it is use in scope,
just not initialized there.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
` (3 preceding siblings ...)
2022-07-03 11:15 ` jakub at gcc dot gnu.org
@ 2022-07-03 11:16 ` jakub at gcc dot gnu.org
2022-07-03 11:21 ` zhendong.su at inf dot ethz.ch
2022-07-03 11:38 ` zhendong.su at inf dot ethz.ch
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-07-03 11:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And -O1 -Wall warns:
pr106171.c: In function ‘c’:
pr106171.c:10:15: warning: ‘e[0]’ is used uninitialized [-Wuninitialized]
10 | return e[0];
| ~^~~
pr106171.c:6:9: note: ‘e’ declared here
6 | int e[2];
| ^
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
` (4 preceding siblings ...)
2022-07-03 11:16 ` jakub at gcc dot gnu.org
@ 2022-07-03 11:21 ` zhendong.su at inf dot ethz.ch
2022-07-03 11:38 ` zhendong.su at inf dot ethz.ch
6 siblings, 0 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2022-07-03 11:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
Zhendong Su <zhendong.su at inf dot ethz.ch> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #6 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
The test has UB.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/106171] wrong code at -O1 and above on x86_64-linux-gnu
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
` (5 preceding siblings ...)
2022-07-03 11:21 ` zhendong.su at inf dot ethz.ch
@ 2022-07-03 11:38 ` zhendong.su at inf dot ethz.ch
6 siblings, 0 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2022-07-03 11:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
--- Comment #7 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
(In reply to Jakub Jelinek from comment #5)
> And -O1 -Wall warns:
> pr106171.c: In function ‘c’:
> pr106171.c:10:15: warning: ‘e[0]’ is used uninitialized [-Wuninitialized]
> 10 | return e[0];
> | ~^~~
> pr106171.c:6:9: note: ‘e’ declared here
> 6 | int e[2];
> | ^
Ah, this is quite clever of GCC :)
Clang fails to detect and warn about it.
CompCert lifts "int e[2]" to the same scope as "int d", thus also misses the
UB.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-07-03 11:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-03 8:40 [Bug tree-optimization/106171] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2022-07-03 8:41 ` [Bug tree-optimization/106171] " zhendong.su at inf dot ethz.ch
2022-07-03 10:20 ` jakub at gcc dot gnu.org
2022-07-03 10:58 ` zhendong.su at inf dot ethz.ch
2022-07-03 11:15 ` jakub at gcc dot gnu.org
2022-07-03 11:16 ` jakub at gcc dot gnu.org
2022-07-03 11:21 ` zhendong.su at inf dot ethz.ch
2022-07-03 11:38 ` zhendong.su at inf dot ethz.ch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).