From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23436 invoked by alias); 23 Feb 2009 23:53:30 -0000 Received: (qmail 23414 invoked by uid 48); 23 Feb 2009 23:53:18 -0000 Date: Mon, 23 Feb 2009 23:53:00 -0000 Message-ID: <20090223235318.23413.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/38341] Wrong warning comparison of promoted ~unsigned with unsigned In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "john dot carter at tait dot co dot nz" 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: 2009-02/txt/msg02062.txt.bz2 ------- Comment #7 from john dot carter at tait dot co dot nz 2009-02-23 23:53 ------- R Guenther said... > (int)u1 == (int)(u8_t)(~(int)u2) > > that we do not warn for the first case is because it is optimized to > u1 == ~u2 before. > > Why do you think the warning is incorrect? ----------------------------------------------- I would expect u2 to be promoted to a 4 byte int ~ to do the ones complement on a 4 byte int (unsigned char)~u2 to truncate to one byte discarding the most significant 3 bytes and then the result get promoted to an int to evaluate the == ie. The cast cannot get optimized away, it's not a null op, it discards the most significant bytes. ie. (int)(unsigned char)~(int)u2 is not equivalent to ~(int)u2 ie. This is a bug -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38341