extern void abort (void); int f1 (void) { int a = 128; return (a & 0x80) ? 0x80 : 0; }
int f2 (void) { unsigned char a = 128; return (a & 0x80) ? 0x80 : 0; } int main (void) { if (f1 () != 128) abort (); if (f2 () != 128) abort (); return 0; } f2 () is miscompiled with -O2 (on x86-64 and ppc at least), returns -128 rather than 128. -- Summary: [4.1/4.2/4.3 Regression] Folding breaks (a & 0x80) ? 0x80 : 0 for unsigned char or unsigned short a Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29695