public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "0xe2.0x9a.0x9b at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug other/95971] New: [10 regression] Optimizer converts a false boolean value into a true boolean value Date: Mon, 29 Jun 2020 16:19:15 +0000 [thread overview] Message-ID: <bug-95971-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95971 Bug ID: 95971 Summary: [10 regression] Optimizer converts a false boolean value into a true boolean value Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: 0xe2.0x9a.0x9b at gmail dot com Target Milestone: --- Hello. I have found an optimization issue that is triggered by the -O2 optimization option in GCC 10.1.0. The source code (see below) contains an infinite while(cond){} loop. The loop condition is expected to always evaluate to true. The optimizer incorrectly derives that the loop condition evaluates to false and removes the loop. It is possible that the issue is related to optimizations of the delete operator in C++. Reproducibility: g++ 10.1.0 -O0: not reproducible g++ 10.1.0 -O1: not reproducible g++ 10.1.0 -O2: REPRODUCIBLE g++ 10.1.0 -O3: not reproducible g++ 9.3.0 -O2: not reproducible clang++ 10 -O2: not reproducible Full source code: $ cat a.cc void xbool(bool value); struct A { char *a = (char*)1; ~A() { delete a; } bool isZero() { return a == (void*)0; } }; int main() { A a; xbool(a.isZero()); while(!a.isZero()); xbool(a.isZero()); // This line isn't required to trigger the issue return 0; } $ cat b.cc void xbool(bool value) {} $ cat Makefile test: g++ -c -O2 a.cc g++ -c b.cc g++ -o a a.o b.o time ./a Dump of assembler code for function main: push %rbp xor %edi,%edi // %rdi := false sub $0x10,%rsp movq $0x1,0x8(%rsp) callq xbool(bool) mov $0x1,%edi // %rdi := true callq xbool(bool) lea 0x8(%rsp),%rdi callq A::~A() add $0x10,%rsp xor %eax,%eax pop %rbp retq mov %rax,%rbp jmpq main.cold In the assembler code: The compiler correctly passes zero (false) in the 1st call to function xbool(bool), then incorrectly passes one (true) in the 2nd call to function xbool(bool). The source code initializes A::a to (char*)1 in order to keep the code as small as possible to trigger the issue. A::a could have been initialized to a valid delete-able heap address, but this would unnecessarily enlarge the source code. The GCC version string on my machine is "g++ (Gentoo 10.1.0-r1 p2) 10.1.0". Please confirm the reproducibility of this issue.
next reply other threads:[~2020-06-29 16:19 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-29 16:19 0xe2.0x9a.0x9b at gmail dot com [this message] 2020-06-29 16:20 ` [Bug other/95971] " 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 16:20 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 16:20 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 17:43 ` marxin at gcc dot gnu.org 2020-06-29 18:05 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 18:27 ` marxin at gcc dot gnu.org 2020-06-29 18:44 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 18:50 ` marxin at gcc dot gnu.org 2020-06-29 19:15 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 20:50 ` 0xe2.0x9a.0x9b at gmail dot com 2020-06-29 21:30 ` glisse at gcc dot gnu.org 2020-06-29 21:43 ` 0xe2.0x9a.0x9b at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-95971-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).