From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25799 invoked by alias); 1 Dec 2008 12:56:37 -0000 Received: (qmail 25442 invoked by uid 48); 1 Dec 2008 12:55:13 -0000 Date: Mon, 01 Dec 2008 12:56:00 -0000 Message-ID: <20081201125513.25441.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: "fredrik dot hederstierna at securitas-direct dot com" 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: 2008-12/txt/msg00046.txt.bz2 ------- Comment #4 from fredrik dot hederstierna at securitas-direct dot com 2008-12-01 12:55 ------- Heres another example, then I do not think the warnings are due to optimization. I have same warnings with both -O0 and -O3. #include typedef unsigned char u8_t; void test_cast(unsigned char c1, unsigned char c2, u8_t u1, u8_t u2) { if (c1 == (unsigned char)(~c2)) { printf("No warning"); } if (c1 == ~c2) { printf("This gives warning"); } if (u1 == (u8_t)(~u2)) { printf("This gives warning"); } if ((unsigned char)u1 == (unsigned char)(~u2)) { printf("This gives warning"); } } The original code that caused this warnings are the TCP/IP stack lwIP, then I constructed this minimal example. Original code from lwIP TCP/IP stack: ------------------------------------- static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8) + 1]; static const u8_t bitmap_bits[8] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; /.../ if (ip_reassbitmap[ip_reasslen / (8 * 8)] != (u8_t) ~ bitmap_bits[ip_reasslen / 8 & 7]) { /.../ -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38341