From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6399F388E83E; Mon, 29 Jun 2020 16:19:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6399F388E83E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593447555; bh=PpgGM1QzfJf/lzMEcPQ9m8WnjbKvMaW7+WIVwDn5u8I=; h=From:To:Subject:Date:From; b=WzGksFFldTDFzhgk9eWFmRTQVdgMRMd5CR8/2mkBRAzwTiEMYqVKt5iEO5Yxu6Lf6 D7rciXIvTwKPVTT8YajTQGe47OgXMZ/rRBwQWFHlMgb2bRgyaB/7RCQ2ZOKhySV87g RI/zud5hIL+ll0IXCrLZ8xIJ6iVc1Fd83xH8vdVo= From: "0xe2.0x9a.0x9b at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 0xe2.0x9a.0x9b at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 16:19:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95971 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 lo= op 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 =3D (char*)1; ~A() { delete a; } bool isZero() { return a =3D=3D (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=20 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 :=3D false sub $0x10,%rsp movq $0x1,0x8(%rsp) callq xbool(bool) mov $0x1,%edi // %rdi :=3D true callq xbool(bool) lea 0x8(%rsp),%rdi callq A::~A() add $0x10,%rsp xor %eax,%eax pop %rbp retq=20=20=20 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 s= mall as possible to trigger the issue. A::a could have been initialized to a val= id delete-able heap address, but this would unnecessarily enlarge the source c= ode. 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.=