PR28045 (gcc optimization bug) still not fixed in dapper

Bug #178637 reported by Arnd
258
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://gcc.gnu.org/bugzilla/show_bug.cgi?id=28045

arnd@slowhand:~/gcc$ gcc -lgmp gcc-bug.c
arnd@slowhand:~/gcc$ ./a.out
 obj is 1.
-obj is -1.
arnd@slowhand:~/gcc$ gcc -O2 -lgmp gcc-bug.c
arnd@slowhand:~/gcc$ ./a.out
 obj is 1.
-obj is a bignum.

Best regards,
Arnd

Revision history for this message
In , Jerry James (jerry-james) wrote :

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;
}

Revision history for this message
In , Rguenth (rguenth) wrote :

Works for me on the mainline.

Revision history for this message
In , Jerry James (jerry-james) wrote :

Created attachment 11688
Testcase showing an optimizaton bug

Revision history for this message
In , Jerry James (jerry-james) wrote :

I can confirm that both the mainline and the current 4.1 branch compile the testcase correctly. Nevertheless, both the current 4.1 branch and the mainline (revision 114741) are still miscompiling XEmacs when any optimization at all is used, so the testcase must be too simple. I just attached a more complex testcase that includes much of the actual code from XEmacs. I trimmed this down quite a bit from the original code, but it's still over 600 lines. This code illustrates the bug on both the i386 and x86_64 platforms. You have to link with the GMP library (-lgmp) when compiling.

Revision history for this message
In , Pinskia (pinskia) wrote :

Reduced testcase:
struct a
{
   unsigned int bits : 1;
   signed long val : ((sizeof(long) * 8) - 1);
};
int Fnegate (struct a b)
{
  if ((-((long)b.val)) <= ((long) ((1UL << (((sizeof(long) * 8) - 1) - 1)) -1UL)) && (-((long)b.val)) >= (-(((long) ((1UL << (((sizeof(long) * 8) - 1) - 1)) -1UL))) - 1))
     return 0 ;
     abort ();
}
int main ()
{
  struct a b = {1, 1};
  Fnegate (b);
  return 0;
}

Revision history for this message
In , Rguenth (rguenth) wrote :

operand_equal_p (bD.1525.valD.1524, (long intD.2) bD.1525.valD.1524, 0)

is true. make_range preserved the cast to (long int) for a reason, though.

If we fix operand_equal_p, we no longer fold the test, but keep

  if (-(long int) b.val <= 1073741823 && -(long int) b.val >= -1073741824)
    {
      return 0;
    }
  abort ();

so, I have a patch.

Revision history for this message
In , Rguenth (rguenth) wrote :

Subject: Bug 28045

Author: rguenth
Date: Mon Jun 19 14:48:47 2006
New Revision: 114772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114772
Log:
2006-06-19 Richard Guenther <email address hidden>

 PR middle-end/28045
 * fold-const.c (operand_equal_p): Check if the argument types
 have the same precision before stripping NOPs.

 * gcc.dg/torture/pr28045.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Revision history for this message
In , Rguenth (rguenth) wrote :

Fixed on the mainline.

Revision history for this message
In , Jerry James (jerry-james) wrote :

On behalf of the XEmacs team, I thank you for your amazingly speedy attention to this bug report.

Revision history for this message
In , Rguenth (rguenth) wrote :

Subject: Bug 28045

Author: rguenth
Date: Fri Jun 23 09:52:40 2006
New Revision: 114929

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114929
Log:
2006-06-23 Richard Guenther <email address hidden>

 PR middle-end/28045
 * fold-const.c (operand_equal_p): Check if the argument types
 have the same precision before stripping NOPs.

 * gcc.dg/torture/pr28045.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/torture/pr28045.c
      - copied unchanged from r114772, trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/fold-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Revision history for this message
In , Rguenth (rguenth) wrote :

Subject: Bug 28045

Author: rguenth
Date: Fri Jun 23 09:57:37 2006
New Revision: 114930

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114930
Log:
2006-06-23 Richard Guenther <email address hidden>

 PR middle-end/28045
 * fold-const.c (operand_equal_p): Check if the argument types
 have the same precision before stripping NOPs.

 * gcc.dg/torture/pr28045.c: New testcase.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/torture/pr28045.c
      - copied unchanged from r114772, trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/fold-const.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Revision history for this message
In , Rguenth (rguenth) wrote :

Fixed.

Revision history for this message
In , Patchapp (patchapp) wrote :

Subject: Bug number PR28045

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-06/msg01000.html

Changed in gcc-4.0:
importance: Undecided → Medium
Changed in gcc:
status: Unknown → Fix Released
Revision history for this message
Ante Karamatić (ivoks) wrote :

I can confirm this bug.

Changed in gcc-4.0:
status: New → Confirmed
Revision history for this message
Matthias Klose (doko) wrote :

fixed in newer Ubuntu releases

Changed in gcc-4.0:
importance: Undecided → Medium
status: New → Confirmed
status: Confirmed → Fix Released
Revision history for this message
Ante Karamatić (ivoks) wrote :

But it should really be fixed in dapper too, cause on a mail server, one can't compile newer versions of clamav, ispconfig, etc...

Revision history for this message
Jason Drage (geek-au) wrote :

I agree with Ante. I'm also here because I can't get the latest virus definitions to my mailserver because there's no updated clamav/freshclam package in Dapper, nor can I build my own because of this gcc bug.

Revision history for this message
Ante Karamatić (ivoks) wrote :

Mattias, it's a 5 line patch (out of which two are comments, and one is whitespace) which does nothing special, but a thing that should've be done in the first place :)

http://gcc.gnu.org/ml/gcc-patches/2006-06/msg01000.html

Revision history for this message
Jason Levine (v-launchpad-net-site-masshole-us) wrote :

Completely agree -- this really NEEDS to be fixed in Dapper/6.06, since there are now reasonably prevalent packages that can't be compiled on Dapper.

Any chance of seeing this fixed?

Revision history for this message
Ace Suares (acesuares) wrote :

I can't compile clamav 0.93 because of this bug, on Dapper.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thank you for reporting this bug to Ubuntu. dapper has reached EOL
(End of Life) and is no longer supported. As a result, this bug
against dapper is being marked "Won't Fix". Please see
https://wiki.ubuntu.com/Releases for currently supported Ubuntu
releases.

Please feel free to report any other bugs you may find.

Changed in gcc-4.0 (Ubuntu Dapper):
status: Confirmed → Won't Fix
Changed in gcc:
importance: Unknown → Medium
Revision history for this message
In , Jackie-rosen (jackie-rosen) wrote :

*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.

To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.