PR28045 (gcc optimization bug) still not fixed in dapper
Bug #178637 reported by
Arnd
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc |
Fix Released
|
Medium
|
|||
gcc-4.0 (Ubuntu) |
Fix Released
|
Medium
|
Unassigned | ||
Dapper |
Won't Fix
|
Medium
|
Unassigned |
Bug Description
Binary package hint: gcc-4.0
Standard gcc in dapper (gcc version 4.0.3-1) is broken on AMD64. (other architectures maybe affected as well)
newest debian volatile clamav packages won't build with this gcc
Testcase from:
http://
arnd@slowhand:
arnd@slowhand:
obj is 1.
-obj is -1.
arnd@slowhand:
arnd@slowhand:
obj is 1.
-obj is a bignum.
Best regards,
Arnd
Changed in gcc-4.0: | |
importance: | Undecided → Medium |
Changed in gcc: | |
status: | Unknown → Fix Released |
Changed in gcc: | |
importance: | Unknown → Medium |
To post a comment you must log in.
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;
}