From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E4D723858D3C; Sat, 2 Mar 2024 09:06:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4D723858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709370385; bh=H76fTWSjcwtpPzy9ki/VDBJ5CKaH60qieafF3d508Sc=; h=From:To:Subject:Date:From; b=F4K2TMB+iROxqDhfoEkH1jI4YT9GEYNpuaR/Lqyl6/xogUL1z1C2OLFbXW6dPrvVO bkDBDxLq99pmyeMAeFqQLb+mmtB5sYs32J9SITeSRdZBy+c4dJhW6Q/KtV+N0IjsCQ AFIlK3YQOUCAMODhe7kQ3ij9ef+XKSevTl26RdAc= From: "congli at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114206] New: GCC generates wrong-code Date: Sat, 02 Mar 2024 09:06:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: congli at smail dot nju.edu.cn 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114206 Bug ID: 114206 Summary: GCC generates wrong-code Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: congli at smail dot nju.edu.cn Target Milestone: --- The program shown below presents a wrong code bug, where the correct results should be "f(0, NULL) =3D 0" while `-Os -fno-tree-ccp -fno-tree-copy-prop -fno-tree-forwprop -fno-tree-fre -fno-tree-vrp` prints "f(0, NULL) =3D 1". ``` #include int f(int t, const int *a) { const int b[4] =3D {0}; if (t =3D=3D 0) { return f(1, b); } else { return b =3D=3D a; } } int main(void) { printf("f(0, NULL) =3D %d\n", f(0, NULL)); } ``` Compiler Explorer: https://gcc.godbolt.org/z/W164xWMrP=20 We checked the assembly, finding that it is weird that the compiler generat= es a `cmove` instruction. See explanations below: ``` f: leaq -16(%rsp), %rax -> RAX =3D RSP-16 testl %edi, %edi -> we called f(0, NULL); %edi =3D 0, ZF =3D= 1 cmove %rax, %rsi -> condition fulfilled; RSI=3DRAX=3DRSP-16;= weird generation cmpq %rax, %rsi -> RSI=3DRAX; ZF=3D1 sete %al -> AL =3D 1 movzbl %al, %eax -> EAX =3D 1 (error) ret ```=