This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/31075] New: 2's complement arithmetic (LLONG_MIN-1) works differently with and without optimization
- From: "sdirkse at gams dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Mar 2007 19:49:58 -0000
- Subject: [Bug c/31075] New: 2's complement arithmetic (LLONG_MIN-1) works differently with and without optimization
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
testing if LLONG_MIN-1 == LLONG_MAX gives different results with -O3 and
without. Here's a short example and the output I get on my machine.
mamie:/home/distrib/lang/pas$cat mini64.c
#include <stdio.h>
typedef signed long long int int64;
#define MAXINT64 9223372036854775807LL
#define MININT64 ((-9223372036854775807LL)-1LL)
int main (int argc, char **argv)
{
int64 minint64;
printf ("mini64: test 2's-complement arithmetic\n");
minint64 = MININT64;
printf ("minint64-1 = %lld\n", minint64-1);
if (minint64 - 1 != MAXINT64) {
printf ("minint64 - 1 <> MAXINT64\n");
}
else {
printf ("minint64 - 1 == MAXINT64\n");
}
return 0;
} /* main */
mamie:/home/distrib/lang/pas$gcc -o mini64 mini64.c && ./mini64
mini64: test 2's-complement arithmetic
minint64-1 = 9223372036854775807
minint64 - 1 == MAXINT64
mamie:/home/distrib/lang/pas$gcc -O3 -o mini64 mini64.c && ./mini64
mini64: test 2's-complement arithmetic
minint64-1 = 9223372036854775807
minint64 - 1 <> MAXINT64
mamie:/home/distrib/lang/pas$gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.3.0 20070305 (experimental)
--
Summary: 2's complement arithmetic (LLONG_MIN-1) works
differently with and without optimization
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sdirkse at gams dot com
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31075