public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101080] New: wrong code with "-O3"
@ 2021-06-15 14:16 suochenyao at 163 dot com
2021-06-16 6:47 ` [Bug tree-optimization/101080] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: suochenyao at 163 dot com @ 2021-06-15 14:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101080
Bug ID: 101080
Summary: wrong code with "-O3"
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), x86_64 GNU/Linux
*******************************************************************************
Program:
struct a {
unsigned b : 3;
} const c;
char d;
int e;
long f;
void g(const struct a h) {
for (; d != 20; d = d + 4) {
int i = h.b;
e = h.b;
f = h.b || 0;
}
}
int main() { g(c); }
*******************************************************************************
gcc 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 20210614 (experimental) (GCC)
git version: f9598d89a9f5a327ecdfa6f6978a0cfbe4447111
*******************************************************************************
Command Lines:
$ gcc a.c -o a1.out
$ gcc -O3 -Wall -Wextra -fno-strict-aliasing -fwrapv a.c -o a2.out
a.c: In function ‘g’:
a.c:9:9: warning: unused variable ‘i’ [-Wunused-variable]
9 | int i = h.b;
| ^
$ ./a1.out
$ ./a2.out
Segmentation fault (core dumped)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/101080] wrong code with "-O3"
2021-06-15 14:16 [Bug tree-optimization/101080] New: wrong code with "-O3" suochenyao at 163 dot com
@ 2021-06-16 6:47 ` rguenth at gcc dot gnu.org
2021-06-16 7:25 ` pinskia at gcc dot gnu.org
2021-06-16 7:26 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-16 6:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101080
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |wrong-code
Last reconfirmed| |2021-06-16
Ever confirmed|0 |1
CC| |jamborm at gcc dot gnu.org
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Also happens with -O3 -fno-tree-vectorize which produces
Program received signal SIGSEGV, Segmentation fault.
0x00000000004003b7 in main ()
(gdb) disassemble
Dump of assembler code for function main:
0x00000000004003a0 <+0>: movzbl 0x200c95(%rip),%eax # 0x60103c
<d>
0x00000000004003a7 <+7>: cmp $0x14,%al
0x00000000004003a9 <+9>: je 0x4003da <main+58>
0x00000000004003ab <+11>: nopl 0x0(%rax,%rax,1)
0x00000000004003b0 <+16>: add $0x4,%eax
0x00000000004003b3 <+19>: cmp $0x14,%al
0x00000000004003b5 <+21>: jne 0x4003b0 <main+16>
=> 0x00000000004003b7 <+23>: andb $0xf8,0x186(%rip) # 0x400544 <c>
0x00000000004003be <+30>: movl $0x0,0x200c70(%rip) # 0x601038
<e>
0x00000000004003c8 <+40>: movq $0x0,0x200c5d(%rip) # 0x601030
<f>
0x00000000004003d3 <+51>: movb $0x14,0x200c62(%rip) # 0x60103c
<d>
0x00000000004003da <+58>: xor %eax,%eax
0x00000000004003dc <+60>: ret
simpler IL testcase (elide g) - note the inlining is critical.
struct a {
unsigned b : 3;
} const c;
char d;
int e;
long f;
static void g(const struct a h)
{
for (; d != 20; d = d + 4) {
int i = h.b;
e = h.b;
f = h.b || 0;
}
}
int main()
{
g(c);
}
so the issue is we store to 'c' which resides in .rodata - suspect this is
a dup of the pending SRA issue. -fno-tree-sra fixes it.
But it's a nice testcase.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/101080] wrong code with "-O3"
2021-06-15 14:16 [Bug tree-optimization/101080] New: wrong code with "-O3" suochenyao at 163 dot com
2021-06-16 6:47 ` [Bug tree-optimization/101080] " rguenth at gcc dot gnu.org
@ 2021-06-16 7:25 ` pinskia at gcc dot gnu.org
2021-06-16 7:26 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-16 7:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101080
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is a dup of the other SRA issue.
PR 100453
*** This bug has been marked as a duplicate of bug 100453 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/101080] wrong code with "-O3"
2021-06-15 14:16 [Bug tree-optimization/101080] New: wrong code with "-O3" suochenyao at 163 dot com
2021-06-16 6:47 ` [Bug tree-optimization/101080] " rguenth at gcc dot gnu.org
2021-06-16 7:25 ` pinskia at gcc dot gnu.org
@ 2021-06-16 7:26 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-16 7:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101080
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> But it's a nice testcase.
The other PR has basically the same testcase even already and about the same
size.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-16 7:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 14:16 [Bug tree-optimization/101080] New: wrong code with "-O3" suochenyao at 163 dot com
2021-06-16 6:47 ` [Bug tree-optimization/101080] " rguenth at gcc dot gnu.org
2021-06-16 7:25 ` pinskia at gcc dot gnu.org
2021-06-16 7:26 ` pinskia 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).