From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20217 invoked by alias); 15 Jun 2006 19:12:11 -0000 Received: (qmail 20122 invoked by uid 48); 15 Jun 2006 19:12:03 -0000 Date: Thu, 15 Jun 2006 19:34:00 -0000 Subject: [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "Jerry dot James at usu dot edu" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-06/txt/msg01472.txt.bz2 List-Id: This is a stripped-down bit of code representing a bad code generation problem we've been having with XEmacs 21.5 + gcc 4.X + optimization. I can reproduce with Fedora Core 5's packaging of gcc 4.1.1 on the x86_64 platform, and with Ubuntu's packaging of gcc 4.0.3 on the i386 platform. Compile the following code without optimization, and it reports that the negation of 1 is -1, which is in bounds. Compile with any -O flag (confirmed for -O, -O2, -O3, and -Os) and the code reports that the negation of 1 is -1, which is out of bounds. If I break the && expression up into 2 consecutive if statements to see which bound is supposedly violated, the optimized code reports that -1 is within each bound individually. Things that have no effect: int/long are interchangeable; the size of the "tag" bitfield doesn't seem to matter, so long as the "tag" size and the "val" size add up to "INT_BITS". I also tried compiling with all of the flags turned on by -O, but without -O itself. Good code is generated in that case. #include #define INT_BITS (sizeof(int) * 8) #define MAX_VALUE (int)((1UL << (INT_BITS - 2)) - 1UL) #define MIN_VALUE (-MAX_VALUE - 1) struct tagged_int { int tag: 2; int val: INT_BITS - 2; }; static void negate (struct tagged_int accum) { printf ("min = %d, max = %d\n", MIN_VALUE, MAX_VALUE); printf ("The negation of 1 is %d, which is ", -(int)accum.val); if (-(int)accum.val <= MAX_VALUE && -(int)accum.val >= MIN_VALUE) { puts ("in bounds."); } else { puts ("out of bounds."); } } int main () { struct tagged_int obj; obj.tag = 0; obj.val = 1L; negate(obj); return 0; } -- Summary: Bitfield, &&, and optimization => bad code generation Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Jerry dot James at usu dot edu GCC build triplet: x86_64-redhat-linux GCC host triplet: x86_64-redhat-linux GCC target triplet: x86_64-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28045