This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/28651] New: signed compare incorrectly false for (int)(U+4)<(int)U where U is unsigned INT_MAX (for optimized x86)


This happens with 4.1.1 release too but not with gcc-4.2-20060805. Also happens
for gcc 4.1.1 on i386 Solaris 10.

bash-3.00$ uname -a
Linux bonk.sics.se 2.6.16-1.2111_FC4smp #1 SMP Sat May 20 20:16:24 EDT 2006
i686 unknown unknown GNU/Linux
bash-3.00$ cat bug.c
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  unsigned u;

  /* u = INT_MAX but gcc cannot know that */
  if (argc != 2 || sscanf(argv[1], "%x", &u) != 1) exit(2);

  if (((int)(u + 4)) < (int)u)
    {
      exit(0);
    }
  exit(1);
}
bash-3.00$ /src/sicstus/install/gcc-4.1-20060804/x86-linux-glibc2.3/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /src/sicstus/install/src/gcc-4.1-20060804/configure
--prefix=/src/sicstus/install/gcc-4.1-20060804/x86-linux-glibc2.3
--enable-languages=c,c++
Thread model: posix
gcc version 4.1.2 20060804 (prerelease)
## Uses sscanf to obtain INT_MAX to keep gcc in the dark
## without optimization the comparison is true which is correct
bash-3.00$ /src/sicstus/install/gcc-4.1-20060804/x86-linux-glibc2.3/bin/gcc
/home/perm/sicstus/sicstus4slon/bug.c && ./a.out 0x7fffffff && echo "success"
|| echo "exited with $?"
success
## with optimization the comparison is false which is correct
bash-3.00$ /src/sicstus/install/gcc-4.1-20060804/x86-linux-glibc2.3/bin/gcc -O1
/home/perm/sicstus/sicstus4slon/bug.c && ./a.out 0x7fffffff && echo "success"
|| echo "exited with $?"
exited with 1
bash-3.00$


-- 
           Summary: signed compare incorrectly false for (int)(U+4)<(int)U
                    where U is unsigned INT_MAX (for optimized  x86)
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: per dot mildner at sics dot se


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28651


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]