User account creation filtered due to spam.
The attached program prints (unsigned) -1 as opposed to 1. This doesn't happen if intermediate variables are used somewhere in the process. I tested gcc 3.4, 4.2.3 (on both x86 and x86-64) with -O0 and -O2, all ended up with -1. suncc printed 1.
Created attachment 15581 [details] testcase
test.c.t02.original says: u = MAX_EXPR <(unsigned int) i, 1>; ... but this is wrong.
fold_binary sees both MAX_EXPRs and reassociates. (I think this is why it works with intermediate variables.) Then associate_trees creates a new MAX_EXPR, converting each argument to unsigned: return fold_build2 (code, type, fold_convert (type, t1), fold_convert (type, t2)); So, this is where the error enters. I'm not sure where this is best fixed though.
Subject: Bug 36137 Author: jakub Date: Wed May 7 07:40:01 2008 New Revision: 135028 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135028 Log: PR middle-end/36137 * fold-const.c (fold_binary): Use STRIP_SIGN_NOPS instead of STRIP_NOPS on arguments even for MIN_EXPR and MAX_EXPR. * gcc.c-torture/execute/20080506-1.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/20080506-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 36137 Author: jakub Date: Wed May 7 07:58:33 2008 New Revision: 135031 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135031 Log: PR middle-end/36137 * fold-const.c (fold_binary): Use STRIP_SIGN_NOPS instead of STRIP_NOPS on arguments even for MIN_EXPR and MAX_EXPR. * gcc.c-torture/execute/20080506-1.c: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/20080506-1.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/fold-const.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed in 4.3 and on the trunk.