This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Optimization bug on Redhat Linux 5.1 with gcc 2.7.2.3
- To: "'gcc-bugs at gcc dot gnu dot org'" <gcc-bugs at gcc dot gnu dot org>
- Subject: Optimization bug on Redhat Linux 5.1 with gcc 2.7.2.3
- From: "Jacoby, Jeffrey" <jjacoby at rsasecurity dot com>
- Date: Fri, 31 Mar 2000 12:44:07 -0800
Bug report
-----------------------------------------------------------------------
Version of gcc:
[jjacoby@ceilo]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/specs
gcc version 2.7.2.3
-----------------------------------------------------------------------
Machine and OS information (this is on a Redhat Linux 5.1 machine)
[jjacoby@ceilo]$ uname -sr
Linux 2.0.34
[jjacoby@ceilo]$ uname -m
i686
-----------------------------------------------------------------------
Command arguments which will reproduce bug
[jjacoby@ceilo]$ gcc -O1 example.c
-----------------------------------------------------------------------
Observed behavior, first with optimization turned ON, then with
optimization turned OFF. Notice that output from printf is
different depending on optimization level.
[jjacoby@ceilo]$ gcc -O1 example.c
[jjacoby@ceilo]$ ./a.out
sign: ff
sign == 0xff: 0
[jjacoby@ceilo]$ gcc -O0 example.c
[jjacoby@ceilo]$ ./a.out
sign: ff
sign == 0xff: 1
-----------------------------------------------------------------------
Input file (with lots and lots of blank lines):
[jjacoby@ceilo]$ gcc -O1 -save-temps example.c
[jjacoby@ceilo]$ cat example.i
# 1 "example.c"
# 1 "/usr/include/stdio.h" 1 3
# 1 "/usr/include/libio.h" 1 3
# 1 "/usr/include/features.h" 1 3
# 117 "/usr/include/features.h" 3
# 1 "/usr/include/sys/cdefs.h" 1 3
# 1 "/usr/include/features.h" 1 3
# 222 "/usr/include/features.h" 3
# 22 "/usr/include/sys/cdefs.h" 2 3
# 54 "/usr/include/sys/cdefs.h" 3
# 86 "/usr/include/sys/cdefs.h" 3
# 205 "/usr/include/features.h" 2 3
# 1 "/usr/include/gnu/stubs.h" 1 3
# 219 "/usr/include/features.h" 2 3
# 29 "/usr/include/libio.h" 2 3
# 1 "/usr/include/_G_config.h" 1 3
# 1 "/usr/include/gnu/types.h" 1 3
typedef unsigned char __u_char;
typedef unsigned short __u_short;
typedef unsigned int __u_int;
typedef unsigned long __u_long;
typedef unsigned long long int __u_quad_t;
typedef long long int __quad_t;
# 41 "/usr/include/gnu/types.h" 3
typedef __quad_t *__qaddr_t;
typedef __u_quad_t __dev_t;
typedef __u_int __uid_t;
typedef __u_int __gid_t;
typedef __u_long __ino_t;
typedef __u_int __mode_t;
typedef __u_int __nlink_t;
typedef long int __off_t;
typedef __quad_t __loff_t;
typedef int __pid_t;
typedef int __ssize_t;
typedef struct
{
int __val[2];
} __fsid_t;
typedef int __daddr_t;
typedef char *__caddr_t;
typedef long int __time_t;
typedef long int __swblk_t;
typedef long int __clock_t;
typedef unsigned long int __fd_mask;
typedef struct
{
__fd_mask fds_bits[1024 / (8 * sizeof (__fd_mask)) ];
} __fd_set;
typedef int __key_t;
typedef unsigned short int __ipc_pid_t;
# 9 "/usr/include/_G_config.h" 2 3
# 1 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 1 3
# 17 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 3
# 59 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 3
# 129 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 3
typedef unsigned int size_t;
# 256 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 3
# 288 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stddef.h" 3
# 13 "/usr/include/_G_config.h" 2 3
typedef unsigned int wint_t;
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__)));
typedef int _G_int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__)));
# 31 "/usr/include/libio.h" 2 3
# 1 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stdarg.h" 1 3
typedef void *__gnuc_va_list;
# 94 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stdarg.h" 3
# 171 "/usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stdarg.h" 3
# 47 "/usr/include/libio.h" 2 3
# 64 "/usr/include/libio.h" 3
# 96 "/usr/include/libio.h" 3
struct _IO_jump_t; struct _IO_FILE;
typedef void _IO_lock_t;
struct _IO_marker {
struct _IO_marker *_next;
struct _IO_FILE *_sbuf;
int _pos;
# 180 "/usr/include/libio.h" 3
};
struct _IO_FILE {
int _flags;
char* _IO_read_ptr;
char* _IO_read_end;
char* _IO_read_base;
char* _IO_write_base;
char* _IO_write_ptr;
char* _IO_write_end;
char* _IO_buf_base;
char* _IO_buf_end;
char *_IO_save_base;
char *_IO_backup_base;
char *_IO_save_end;
struct _IO_marker *_markers;
struct _IO_FILE *_chain;
int _fileno;
int _blksize;
__off_t _offset;
unsigned short _cur_column;
char _unused;
char _shortbuf[1];
_IO_lock_t *_lock;
};
typedef struct _IO_FILE _IO_FILE;
struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
typedef struct
{
__ssize_t (*read) (struct _IO_FILE *, void *, __ssize_t ) ;
__ssize_t (*write) (struct _IO_FILE *, const void *, __ssize_t ) ;
__off_t (*seek) (struct _IO_FILE *, __off_t , int) ;
int (*close) (struct _IO_FILE *) ;
} _IO_cookie_io_functions_t;
struct _IO_cookie_file {
struct _IO_FILE file;
const void *vtable;
void *cookie;
_IO_cookie_io_functions_t io_functions;
};
extern int __underflow (_IO_FILE*) ;
extern int __uflow (_IO_FILE*) ;
extern int __overflow (_IO_FILE*, int) ;
extern int _IO_getc (_IO_FILE *__fp) ;
extern int _IO_putc (int __c, _IO_FILE *__fp) ;
extern int _IO_feof (_IO_FILE *__fp) ;
extern int _IO_ferror (_IO_FILE *__fp) ;
extern int _IO_peekc_locked (_IO_FILE *__fp) ;
extern void _IO_flockfile (_IO_FILE *) ;
extern void _IO_funlockfile (_IO_FILE *) ;
extern int _IO_ftrylockfile (_IO_FILE *) ;
extern int _IO_vfscanf (_IO_FILE*, const char*, __gnuc_va_list , int*) ;
extern int _IO_vfprintf (_IO_FILE*, const char*, __gnuc_va_list ) ;
extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t ) ;
extern size_t _IO_sgetn (_IO_FILE *, void*, size_t ) ;
extern __off_t _IO_seekoff (_IO_FILE*, __off_t , int, int) ;
extern __off_t _IO_seekpos (_IO_FILE*, __off_t , int) ;
extern void _IO_free_backup_area (_IO_FILE*) ;
# 29 "/usr/include/stdio.h" 2 3
# 69 "/usr/include/stdio.h" 3
typedef struct _IO_FILE FILE;
typedef __off_t fpos_t;
# 1 "/usr/include/stdio_lim.h" 1 3
# 74 "/usr/include/stdio.h" 2 3
extern FILE *stdin, *stdout, *stderr;
extern void clearerr (FILE*) ;
extern int fclose (FILE*) ;
extern int feof (FILE*) ;
extern int ferror (FILE*) ;
extern int fflush (FILE*) ;
extern int fgetc (FILE *) ;
extern int fgetpos (FILE* fp, fpos_t *pos) ;
extern char* fgets (char*, int, FILE*) ;
extern FILE* fopen (__const char*, __const char*) ;
extern FILE* fopencookie (void *cookie, __const char *mode,
_IO_cookie_io_functions_t io_functions) ;
extern int fprintf (FILE*, __const char* format, ...) ;
extern int fputc (int, FILE*) ;
extern int fputs (__const char *str, FILE *fp) ;
extern size_t fread (void*, size_t, size_t, FILE*) ;
extern FILE* freopen (__const char*, __const char*, FILE*) ;
extern int fscanf (FILE *fp, __const char* format, ...) ;
extern int fseek (FILE* fp, long int offset, int whence) ;
extern int fsetpos (FILE* fp, __const fpos_t *pos) ;
extern long int ftell (FILE* fp) ;
extern size_t fwrite (__const void*, size_t, size_t, FILE*) ;
extern int getc (FILE *) ;
extern int getchar (void) ;
extern char* gets (char*) ;
extern void perror (__const char *) ;
extern int printf (__const char* format, ...) ;
extern int putc (int, FILE *) ;
extern int putchar (int) ;
extern int puts (__const char *str) ;
extern int remove (__const char*) ;
extern int rename (__const char* _old, __const char* _new) ;
extern void rewind (FILE*) ;
extern int scanf (__const char* format, ...) ;
extern void setbuf (FILE*, char*) ;
extern void setlinebuf (FILE*) ;
extern void setbuffer (FILE*, char*, int) ;
extern int setvbuf (FILE*, char*, int mode, size_t size) ;
extern int sprintf (char*, __const char* format, ...) ;
extern int sscanf (__const char* string, __const char* format, ...) ;
extern FILE* tmpfile (void) ;
extern char* tmpnam (char*) ;
extern char* tmpnam_r (char*) ;
extern char *tempnam (__const char *__dir, __const char *__pfx) ;
extern char *__stdio_gen_tempname (char *__buf, size_t bufsize,
__const char *dir, __const char
*pfx,
int dir_search, size_t *lenptr,
FILE **streamptr) ;
extern int ungetc (int c, FILE* fp) ;
extern int vfprintf (FILE *fp, char __const *fmt0, __gnuc_va_list ) ;
extern int vprintf (char __const *fmt, __gnuc_va_list ) ;
extern int vsprintf (char* string, __const char* format, __gnuc_va_list )
;
extern void __libc_fatal (__const char *__message)
__attribute__ ((__noreturn__));
extern int dprintf (int, __const char *, ...) ;
extern int vdprintf (int, __const char *, __gnuc_va_list ) ;
extern int vfscanf (FILE*, __const char *, __gnuc_va_list ) ;
extern int __vfscanf (FILE*, __const char *, __gnuc_va_list ) ;
extern int vscanf (__const char *, __gnuc_va_list ) ;
extern int vsscanf (__const char *, __const char *, __gnuc_va_list ) ;
extern int __vsscanf (__const char *, __const char *, __gnuc_va_list ) ;
# 177 "/usr/include/stdio.h" 3
extern FILE *fdopen (int, __const char *) ;
extern int fileno (FILE*) ;
extern FILE* popen (__const char*, __const char*) ;
extern int pclose (FILE*) ;
extern char *ctermid (char *__buf) ;
extern char *cuserid (char * __buf) ;
extern int snprintf (char *, size_t, __const char *, ...) ;
extern int __snprintf (char *, size_t, __const char *, ...) ;
extern int vsnprintf (char *, size_t, __const char *, __gnuc_va_list ) ;
extern int __vsnprintf (char *, size_t, __const char *, __gnuc_va_list ) ;
# 214 "/usr/include/stdio.h" 3
extern int __underflow (struct _IO_FILE*) ;
extern int __overflow (struct _IO_FILE*, int) ;
extern int sys_nerr;
extern const char *const sys_errlist[];
extern void clearerr_locked (FILE *) ;
extern void clearerr_unlocked (FILE *) ;
extern int feof_locked (FILE *) ;
extern int feof_unlocked (FILE *) ;
extern int ferror_locked (FILE*) ;
extern int ferror_unlocked (FILE*) ;
extern int fileno_locked (FILE *) ;
extern int fileno_unlocked (FILE *) ;
extern int fclose_unlocked (FILE *) ;
extern int fflush_locked (FILE *) ;
extern int fflush_unlocked (FILE *) ;
extern size_t fread_unlocked (void *, size_t, size_t, FILE *) ;
extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *) ;
extern int fputc_locked (int, FILE*) ;
extern int fputc_unlocked (int, FILE*) ;
extern int getc_locked (FILE *) ;
extern int getchar_locked (void) ;
extern int putc_locked (int, FILE *) ;
extern int putchar_locked (int) ;
extern void flockfile (FILE *) ;
extern void funlockfile (FILE *) ;
extern int ftrylockfile (FILE *) ;
extern int getc_unlocked (FILE *) ;
extern int getchar_unlocked (void) ;
extern int putc_unlocked (int, FILE *) ;
extern int putchar_unlocked (int) ;
# 1 "example.c" 2
int main(void) {
unsigned char sign;
unsigned char integer[2] = {0xff };
if ( integer[0] != 0 )
sign = 0xff;
else
sign = 0x00;
printf ( "sign: %x\n", sign );
printf ( "sign == 0xff: %d\n", (sign == 0xff) );
return 0;
}
-----------------------------------------------------------------------
Sincerely,
Jeff Jacoby