optimizer bug, latest version of egcs ( 0 && 0 => 1 )
Deborah Wallach
kerr@pa.dec.com
Thu Mar 18 12:03:00 GMT 1999
This bug occurs on multiple platforms (x86, arm, alpha), on both egcs and
gcc (2.8) variants (but not in gcc 2.7.2.2, nor in the DEC compiler), appears
to be in cc1, and only occurs with optimization on.
Platforms/OS/compiler versions:
1. Pentium II running redhat linux 5.2
Linux version 2.0.34 (root@ditsy.pa.dec.com) (gcc version 2.7.2.3) #2 Tue Nov 24 14:20:20 PST 1998
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
Reading specs from /tmp/EGCS/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(occurs in both variants)
2. Corel Computer ARM-based netwinder
native compiler:
Reading specs from /usr/lib/gcc-lib/arm-linuxelf/2.8.1/specs
gcc version 2.8.1 (arm - netwinder)
cross compiled from the PC platforms mentioned above using:
Reading specs from /usr/local/lib/gcc-lib/arm-unknown-linuxelf/egcs-2.91.55/specs
gcc version egcs-2.91.55 19980824 (gcc2 ss-980609 experimental)
When you compile the program with no optimization, output is as expected:
teeny: gcc -o foo foo.c
teeny: ./foo
Expect 65535, 0, 0 -> 65535 0 0
When you compile the program with optimization, output is different:
teeny: gcc -o foo -O foo.c
teeny: ./foo
Expect 65535, 0, 0 -> 65535 0 1
--------------------------------------------------------------------------------
The source for foo.c:
#include <stdio.h>
typedef struct {
unsigned int beg;
} help1_t;
main()
{
help1_t foo;
foo.beg = (unsigned int)(-1);
printf("Expect 65535, 0, 0 -> %d %d %d\n",
( (unsigned short)foo.beg ),
( (unsigned short)foo.beg != (unsigned short)65535 ),
(
( (unsigned short)foo.beg != (unsigned short)65535 )
&&
( (unsigned short)foo.beg != (unsigned short)65535 )
)
);
return(0);
}
--------------------------------------------------------------------------------
The output of gcc -E foo.c:
# 1 "foo.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/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 1 3
# 19 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 3
# 61 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 3
# 131 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 3
typedef unsigned int size_t;
# 271 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 3
typedef unsigned int wint_t;
# 317 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stddef.h" 3
# 13 "/usr/include/_G_config.h" 2 3
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/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stdarg.h" 1 3
typedef void *__gnuc_va_list;
# 116 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include/stdarg.h" 3
# 202 "/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/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 "foo.c" 2
typedef struct {
unsigned int beg;
} help1_t;
main()
{
help1_t foo;
foo.beg = (unsigned int)(-1);
printf("Expect 65535, 0, 0 -> %d %d %d\n",
( (unsigned short)foo.beg ),
( (unsigned short)foo.beg != (unsigned short)65535 ),
(
( (unsigned short)foo.beg != (unsigned short)65535 )
&&
( (unsigned short)foo.beg != (unsigned short)65535 )
)
);
return(0);
}
--------------------------------------------------------------------------------
More information about the Gcc-bugs
mailing list