The following test code incorrectly generates an assertion failure on gcc mainline and 4.0.1: #include <assert.h> struct fbs { unsigned char uc8; } fbs1 = {255}; void testfn ( struct fbs *fbs_ptr ) { if ((fbs_ptr->uc8 != 255) && (fbs_ptr->uc8 != 0)) assert(0); } int main (int argc, char *argv[]) { testfn (&fbs1); return 0; }
I believe I have tracked down the root of this behavior to an invalid transformation in simplify_comparison (from combine.c). See email thread starting here: http://gcc.gnu.org/ml/gcc/2005-08/msg00159.html
Confirmed.
Just a note for fullness, this was caused by the patch which fixed PR 19296.
> Just a note for fullness, this was caused by the patch which fixed PR 19296. Right. The annoying thing is that it is in 3.3.6 too so I think someone should fix the typo on the 3.3 branch too.
Subject: Re: [3.4/4.0/4.1 Regression] Invalid code generated for comparison of uchar to 255 > Right. The annoying thing is that it is in 3.3.6 too so I think > someone should > fix the typo on the 3.3 branch too. Will do. Thanks for pointing that out - I would have missed it otherwise! - Josh
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Changes by: jconner@gcc.gnu.org 2005-08-08 18:28:47 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: char-compare.c Log message: PR rtl-optimization/23241 * gcc.dg/char-compare.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5894&r2=1.5895 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/char-compare.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Changes by: jconner@gcc.gnu.org 2005-08-08 18:30:11 Modified files: gcc : ChangeLog combine.c Log message: PR rtl-optimization/23241 * combine.c (simplify_comparison): Fix error in determining whether to lift a subreg from comparison. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9680&r2=2.9681 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&r1=1.501&r2=1.502
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: jconner@gcc.gnu.org 2005-08-08 18:35:14 Modified files: gcc : ChangeLog combine.c Log message: PR rtl-optimization/23241 * combine.c (simplify_comparison): Fix error in determining whether to lift a subreg from comparison. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.358&r2=2.7592.2.359 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.475.4.5&r2=1.475.4.6
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: jconner@gcc.gnu.org 2005-08-08 18:37:57 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: char-compare.c Log message: PR rtl-optimization/23241 * gcc.dg/char-compare.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.323&r2=1.5084.2.324 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/char-compare.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: jconner@gcc.gnu.org 2005-08-08 18:41:07 Modified files: gcc : ChangeLog combine.c Log message: PR rtl-optimization/23241 * combine.c (simplify_comparison): Fix error in determining whether to lift a subreg from comparison. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.905&r2=2.2326.2.906 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.400.4.14&r2=1.400.4.15
Subject: Bug 23241 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: jconner@gcc.gnu.org 2005-08-08 18:43:11 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: char-compare.c Log message: PR rtl-optimization/23241 * gcc.dg/char-compare.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.420&r2=1.3389.2.421 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/char-compare.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1
Fixed, thanks Josh.
Subject: Bug 23241 Author: jsm28 Date: Wed Feb 1 00:13:07 2006 New Revision: 110456 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110456 Log: Backport: 2005-08-08 Josh Conner <jconner@apple.com> PR rtl-optimization/23241 * combine.c (simplify_comparison): Fix error in determining whether to lift a subreg from comparison. * gcc.dg/char-compare.c: New test. Added: branches/csl-3_4_3-linux-branch/gcc/testsuite/gcc.dg/char-compare.c - copied unchanged from r110455, branches/gcc-3_4-branch/gcc/testsuite/gcc.dg/char-compare.c Modified: branches/csl-3_4_3-linux-branch/ChangeLog.csl branches/csl-3_4_3-linux-branch/gcc/combine.c