/* * Compile -O0 (no optimization) */ #include <stdio.h>
typedef int int32; typedef long long int64; int main () { int32 i = 1; /* hence (2*i)-1 below is 1... */ #define K 0x800000003LL /* 64 bit constant; low 32 are 3; high 32 are 8 */ printf("%016llx (gcc 2.96 bad: 0000000000000003)\n", K * ( (2*i) - 1 )); printf("%016llx (gcc 2.96 bad: 0000000000000003)\n", K * ( (2*i) - 1LL)); printf("%016llx (gcc 2.96 bad: 0000000000000003)\n", K * ( (2*i) - (int64)1 )); printf("%016llx (gcc 2.96 bad: fffffff800000003)\n", K * ( (int64)(2*i) - 1 )); printf("%016llx (gcc 2.96 bad: fffffff800000003)\n", K * ( (int64)(2*i) - 1LL)); printf("%016llx (gcc 2.96 bad: fffffff800000003)\n", K * ( (int64)(2*i) - (int64)1 )); printf("%016llx (gcc 2.96 good: 0000000800000003)\n", K * (2*(int64)( i) - 1 )); } -- Summary: 64 bit multiplication incorrectly folded. Product: gcc Version: 2.96 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jyates at netezza dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25332