public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105598] New: Flag -O2 causes code to misbehave
@ 2022-05-13 17:49 greenfoo at u92 dot eu
2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: greenfoo at u92 dot eu @ 2022-05-13 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
Bug ID: 105598
Summary: Flag -O2 causes code to misbehave
Product: gcc
Version: 11.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: greenfoo at u92 dot eu
Target Milestone: ---
Created attachment 52974
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52974&action=edit
Small example that triggers the issue when using -O2 in gcc 11.x
I found a situation where the "-O2" flag was causing trouble at least in
x86_64.
The attached file "example.c" code is expected to print "4" when compiled and
executed, but it would print "2" when compiled with "-02".
This happens with gcc 11.1, 11.2 and 11.3, but works correctly with gcc 10.3
and 12.1:
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:10.3 gcc -o example example.c && ./example
> 4
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.1 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.2 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.3 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:12.1 gcc -o example example.c && ./example
> 4
I don't know if this deserves further investigation. If not, please feel free
to discard this bug report.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/105598] [11 Regression] Flag -O2 causes code to misbehave
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
@ 2022-05-13 18:25 ` jakub at gcc dot gnu.org
2022-05-16 8:47 ` [Bug tree-optimization/105598] " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-13 18:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.4
Keywords| |wrong-code
Summary|Flag -O2 causes code to |[11 Regression] Flag -O2
|misbehave |causes code to misbehave
Status|UNCONFIRMED |NEW
Priority|P3 |P2
Ever confirmed|0 |1
Last reconfirmed| |2022-05-13
CC| |hubicka at gcc dot gnu.org,
| |jakub at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This went away with r12-3918-g5b8b1522e04adc20980f396571be1929a32d148a
on the trunk and started r11-3772-gc8fd2be174a15ff154a3102decb0e643f67cad02
typedef struct { unsigned int num; } info_t;
typedef struct { unsigned int flag, type; } block_t;
info_t info;
block_t blocks[] = { {2,0}, {3,0}, {1,0}, {1,0} };
static block_t *
f (info_t *i, block_t *b) {
while (1) {
unsigned int is_last = b->flag & 0x01;
i->num++;
if (b->flag & 0x02) {
if (b->type != 0x1) b->type = b->type;
b = f (i, b+1);
}
if (is_last)
break;
b++;
}
return b;
}
int
main () {
f(&info, &blocks[0]);
if (info.num != 4)
__builtin_abort ();
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105598] [11 Regression] Flag -O2 causes code to misbehave
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
@ 2022-05-16 8:47 ` rguenth at gcc dot gnu.org
2022-05-16 8:59 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-16 8:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
r12-3918-g5b8b1522e04adc20980f396571be1929a32d148a is an optimization
improvement. When backporting the change the failure goes away but it
re-appears with -fdisable-tree-fre1 and can be mitigated with -fno-ipa-cp.
-fdisable-tree-fre1 doesn't re-introduce the issue on trunk.
Can you bisect what fixed this with -fdisable-tree-fre1?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105598] [11 Regression] Flag -O2 causes code to misbehave
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
2022-05-16 8:47 ` [Bug tree-optimization/105598] " rguenth at gcc dot gnu.org
@ 2022-05-16 8:59 ` jakub at gcc dot gnu.org
2022-05-16 9:18 ` rguenth at gcc dot gnu.org
2022-05-16 10:06 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-16 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
With -O2 -fdisable-tree-fre1 it started with the same revision, but went away
with r12-5104-gb406bb901f7e98f7c6d66a240c2eb64b7cd7e615 instead.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105598] [11 Regression] Flag -O2 causes code to misbehave
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
` (2 preceding siblings ...)
2022-05-16 8:59 ` jakub at gcc dot gnu.org
@ 2022-05-16 9:18 ` rguenth at gcc dot gnu.org
2022-05-16 10:06 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-16 9:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm going to backport this rev.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105598] [11 Regression] Flag -O2 causes code to misbehave
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
` (3 preceding siblings ...)
2022-05-16 9:18 ` rguenth at gcc dot gnu.org
@ 2022-05-16 10:06 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-16 10:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105598
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Known to fail| |11.3.0
Known to work| |11.3.1, 12.1.0
Status|ASSIGNED |RESOLVED
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-16 10:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
2022-05-16 8:47 ` [Bug tree-optimization/105598] " rguenth at gcc dot gnu.org
2022-05-16 8:59 ` jakub at gcc dot gnu.org
2022-05-16 9:18 ` rguenth at gcc dot gnu.org
2022-05-16 10:06 ` rguenth at gcc dot gnu.org
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).