This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/28045] New: Bitfield, &&, and optimization => bad code generation
- From: "Jerry dot James at usu dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jun 2006 19:12:03 -0000
- Subject: [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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 <stdio.h>
#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
- Follow-Ups:
- [Bug c/28045] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug c/28045] Bitfield, &&, and optimization => bad code generation
- From: Jerry dot James at usu dot edu
- [Bug c/28045] Bitfield, &&, and optimization => bad code generation
- From: Jerry dot James at usu dot edu
- [Bug c/28045] Bitfield, &&, and optimization => bad code generation
- From: pinskia at gcc dot gnu dot org
- [Bug c/28045] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1/4.2 Regression] Bitfield, &&, and optimization => bad code generation
- From: pinskia at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1/4.2 Regression] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: Jerry dot James at usu dot edu
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: rguenth at gcc dot gnu dot org
- [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
- From: patchapp at dberlin dot org