From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20344 invoked by alias); 28 Jul 2010 09:32:24 -0000 Received: (qmail 19930 invoked by uid 48); 28 Jul 2010 09:32:09 -0000 Date: Wed, 28 Jul 2010 09:32:00 -0000 Message-ID: <20100728093209.19928.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug tree-optimization/45034] [4.3/4.4/4.5/4.6 Regression] "safe" conversion from unsigned to signed char gives broken code In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg03053.txt.bz2 ------- Comment #11 from rguenth at gcc dot gnu dot org 2010-07-28 09:32 ------- I suppose that uy = -ux; is really uy = (unsigned char) -(int) ux; as unsigned char promotes to int. We then incorrectly narrow this to -(signed char) ux. We do this again in convert_to_integer. Our bag of premature (and bogus) optimizations. case NEGATE_EXPR: case BIT_NOT_EXPR: /* This is not correct for ABS_EXPR, since we must test the sign before truncation. */ { tree typex; /* Don't do unsigned arithmetic where signed was wanted, or vice versa. */ if (TYPE_UNSIGNED (TREE_TYPE (expr))) typex = unsigned_type_for (type); else typex = signed_type_for (type); return convert (type, fold_build1 (ex_form, typex, convert (typex, TREE_OPERAND (expr, 0)))); well - I have no idea why we can't always choose an unsigned type here (testing that now). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45034