Consider tree.c:upper_bound_in_type Suppose that outer is ulong64 and that inner is int32. Then the function returns 2^32-1, which is wrong. Since we are widening a signed value, we need to use a sign extension. The largest value after casting to ulong64 is actually 2^64-1, which occurs when sign-extending (int32) -1. Consider tree.c:lower_bound_in_type Suppose that outer is int32 and that inner is ulong64. Then the function returns 0, which is wrong. Since we are narrowing, the result of a cast can take all values of int32. The smallest value after casting to int32 is -2^31, which occurs when we narrow 2^31. These functions are used from fold-const.c, but I was unable to come up with a testcase that exposed this bug. This bug showed up as a latent bug while I was working on PR20139. I've got a patch to fix this.
Confirmed, this is a latent bug in 4.0.0. The code was not in 3.4.0 so this is 4.0.0 regression.
This also blocks the tree combiner even though I don't see the regression on ppc-darwin.
Subject: Bug 22360 CVSROOT: /cvs/gcc Module name: gcc Changes by: kazu@gcc.gnu.org 2005-07-08 18:49:07 Modified files: gcc : ChangeLog tree.c Log message: PR tree-optimization/22360 * tree.c (upper_bound_in_type): Fix calculations for casting to a non-wider signed type and casting a signed value to a wider unsigned type. (lower_bound_in_type): Fix calculations for casting to a non-wider signed type. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9384&r2=2.9385 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.c.diff?cvsroot=gcc&r1=1.494&r2=1.495
Just checked in a fix.
Fixed at least on the mainline.
Unassigning myself.
Fixed in GCC-4.1.1 not release critcal for GCC-4.0.x