Hi

I am running uptodate RELENG_7. It has gcc (GCC) 4.2.1 20070719
[FreeBSD].

I tried to track down segfaults from my code and I accidentaly found a
optimization error. Code did not segfault when compiled without
optimization but crashed when -O2 was used.

I tried to track it I could make the gcc give me following error by
simply stripping few lines:

-----------------------
wrong.c: In function 'wrong':
wrong.c:11: error: Attempt to delete prologue/epilogue insn:
(insn/f 47 46 48 2 (set (mem:SI (plus:SI (reg/f:SI 6 bp)
                (const_int -8 [0xfffffffffffffff8])) [0 S4 A8])
        (reg:SI 3 bx)) -1 (nil)
    (nil))
wrong.c:11: internal compiler error: in propagate_one_insn, at
flow.c:1735 Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

------------------


And this is what triggers it:


#include <wchar.h>
#include <stdio.h>

#define max_word_len    64

wchar_t *wrong(wchar_t *wordlist, wchar_t *word)
{   wchar_t     buffer[max_word_len+2];
    buffer[max_word_len+2]=0;

        <STRIPPED PART>

    if(wcsstr(wordlist,buffer)==0) wcscpy(wordlist,buffer);

        <STRIPPED PART>

    return wordlist;
}





-Mikael


------------ wrong.i --------------


# 1 "wrong.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "wrong.c"
# 1 "/usr/include/wchar.h" 1 3 4
# 70 "/usr/include/wchar.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 71 "/usr/include/wchar.h" 2 3 4
# 1 "/usr/include/sys/_null.h" 1 3 4
# 72 "/usr/include/wchar.h" 2 3 4
# 1 "/usr/include/sys/_types.h" 1 3 4
# 33 "/usr/include/sys/_types.h" 3 4
# 1 "/usr/include/machine/_types.h" 1 3 4
# 51 "/usr/include/machine/_types.h" 3 4
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short __int16_t;
typedef unsigned short __uint16_t;
typedef int __int32_t;
typedef unsigned int __uint32_t;







typedef int __attribute__((__mode__(__DI__))) __int64_t;
typedef unsigned int __attribute__((__mode__(__DI__))) __uint64_t;
# 76 "/usr/include/machine/_types.h" 3 4
typedef unsigned long __clock_t;
typedef unsigned int __cpumask_t;
typedef __int32_t __critical_t;
typedef double __double_t;
typedef double __float_t;
typedef __int32_t __intfptr_t;
typedef __int64_t __intmax_t;
typedef __int32_t __intptr_t;
typedef __int32_t __int_fast8_t;
typedef __int32_t __int_fast16_t;
typedef __int32_t __int_fast32_t;
typedef __int64_t __int_fast64_t;
typedef __int8_t __int_least8_t;
typedef __int16_t __int_least16_t;
typedef __int32_t __int_least32_t;
typedef __int64_t __int_least64_t;
typedef __int32_t __ptrdiff_t;
typedef __int32_t __register_t;
typedef __int32_t __segsz_t;
typedef __uint32_t __size_t;
typedef __int32_t __ssize_t;
typedef __int32_t __time_t;
typedef __uint32_t __uintfptr_t;
typedef __uint64_t __uintmax_t;
typedef __uint32_t __uintptr_t;
typedef __uint32_t __uint_fast8_t;
typedef __uint32_t __uint_fast16_t;
typedef __uint32_t __uint_fast32_t;
typedef __uint64_t __uint_fast64_t;
typedef __uint8_t __uint_least8_t;
typedef __uint16_t __uint_least16_t;
typedef __uint32_t __uint_least32_t;
typedef __uint64_t __uint_least64_t;
typedef __uint32_t __u_register_t;
typedef __uint32_t __vm_offset_t;
typedef __int64_t __vm_ooffset_t;



typedef __uint32_t __vm_paddr_t;

typedef __uint64_t __vm_pindex_t;
typedef __uint32_t __vm_size_t;





typedef __builtin_va_list __va_list;






typedef __va_list __gnuc_va_list;
# 34 "/usr/include/sys/_types.h" 2 3 4




typedef __uint32_t __blksize_t;
typedef __int64_t __blkcnt_t;
typedef __int32_t __clockid_t;
typedef __uint32_t __fflags_t;
typedef __uint64_t __fsblkcnt_t;
typedef __uint64_t __fsfilcnt_t;
typedef __uint32_t __gid_t;
typedef __int64_t __id_t;
typedef __uint32_t __ino_t;
typedef long __key_t;
typedef __int32_t __lwpid_t;
typedef __uint16_t __mode_t;
typedef int __nl_item;
typedef __uint16_t __nlink_t;
typedef __int64_t __off_t;
typedef __int32_t __pid_t;
typedef __int64_t __rlim_t;


typedef __uint8_t __sa_family_t;
typedef __uint32_t __socklen_t;
typedef long __suseconds_t;
typedef struct __timer *__timer_t;
typedef struct __mq *__mqd_t;
typedef __uint32_t __uid_t;
typedef unsigned int __useconds_t;
# 83 "/usr/include/sys/_types.h" 3 4
typedef int __ct_rune_t;
typedef __ct_rune_t __rune_t;
typedef __ct_rune_t __wchar_t;
typedef __ct_rune_t __wint_t;

typedef __uint32_t __dev_t;

typedef __uint32_t __fixpt_t;





typedef union {
 char __mbstate8[128];
 __int64_t _mbstateL;
} __mbstate_t;
# 73 "/usr/include/wchar.h" 2 3 4
# 1 "/usr/include/machine/_limits.h" 1 3 4
# 74 "/usr/include/wchar.h" 2 3 4
# 1 "/usr/include/_ctype.h" 1 3 4
# 74 "/usr/include/_ctype.h" 3 4

unsigned long ___runetype(__ct_rune_t) __attribute__((__pure__));
__ct_rune_t ___tolower(__ct_rune_t) __attribute__((__pure__));
__ct_rune_t ___toupper(__ct_rune_t) __attribute__((__pure__));

# 90 "/usr/include/_ctype.h" 3 4
extern int __mb_sb_limit;







# 1 "/usr/include/runetype.h" 1 3 4
# 52 "/usr/include/runetype.h" 3 4
typedef struct {
 __rune_t __min;
 __rune_t __max;
 __rune_t __map;
 unsigned long *__types;
} _RuneEntry;

typedef struct {
 int __nranges;
 _RuneEntry *__ranges;
} _RuneRange;

typedef struct {
 char __magic[8];
 char __encoding[32];

 __rune_t (*__sgetrune)(const char *, __size_t, char const **);
 int (*__sputrune)(__rune_t, char *, __size_t, char **);
 __rune_t __invalid_rune;

 unsigned long __runetype[(1 <<8 )];
 __rune_t __maplower[(1 <<8 )];
 __rune_t __mapupper[(1 <<8 )];






 _RuneRange __runetype_ext;
 _RuneRange __maplower_ext;
 _RuneRange __mapupper_ext;

 void *__variable;
 int __variable_len;
} _RuneLocale;



extern _RuneLocale _DefaultRuneLocale;
extern _RuneLocale *_CurrentRuneLocale;
# 99 "/usr/include/_ctype.h" 2 3 4

static __inline int
__maskrune(__ct_rune_t _c, unsigned long _f)
{
 return ((_c < 0 || _c >= (1 <<8 )) ? ___runetype(_c) :
  _CurrentRuneLocale->__runetype[_c]) & _f;
}

static __inline int
__sbmaskrune(__ct_rune_t _c, unsigned long _f)
{
 return (_c < 0 || _c >= __mb_sb_limit) ? 0 :
        _CurrentRuneLocale->__runetype[_c] & _f;
}

static __inline int
__istype(__ct_rune_t _c, unsigned long _f)
{
 return (!!__maskrune(_c, _f));
}

static __inline int
__sbistype(__ct_rune_t _c, unsigned long _f)
{
 return (!!__sbmaskrune(_c, _f));
}

static __inline int
__isctype(__ct_rune_t _c, unsigned long _f)
{
 return (_c & ~0x7F) ? 0 :
        !!(_DefaultRuneLocale.__runetype[_c] & _f);
}

static __inline __ct_rune_t
__toupper(__ct_rune_t _c)
{
 return (_c < 0 || _c >= (1 <<8 )) ? ___toupper(_c) :
        _CurrentRuneLocale->__mapupper[_c];
}

static __inline __ct_rune_t
__sbtoupper(__ct_rune_t _c)
{
 return (_c < 0 || _c >= __mb_sb_limit) ? _c :
        _CurrentRuneLocale->__mapupper[_c];
}

static __inline __ct_rune_t
__tolower(__ct_rune_t _c)
{
 return (_c < 0 || _c >= (1 <<8 )) ? ___tolower(_c) :
        _CurrentRuneLocale->__maplower[_c];
}

static __inline __ct_rune_t
__sbtolower(__ct_rune_t _c)
{
 return (_c < 0 || _c >= __mb_sb_limit) ? _c :
        _CurrentRuneLocale->__maplower[_c];
}

static __inline int
__wcwidth(__ct_rune_t _c)
{
 unsigned int _x;

 if (_c == 0)
  return (0);
 _x = (unsigned int)__maskrune(_c, 0xe0000000L|0x00040000L);
 if ((_x & 0xe0000000L) != 0)
  return ((_x & 0xe0000000L) >> 30);
 return ((_x & 0x00040000L) != 0 ? 1 : -1);
}
# 75 "/usr/include/wchar.h" 2 3 4


typedef __mbstate_t mbstate_t;




typedef __size_t size_t;





typedef __wchar_t wchar_t;





typedef __wint_t wint_t;
# 107 "/usr/include/wchar.h" 3 4
struct __sFILE;
struct tm;


wint_t btowc(int);
wint_t fgetwc(struct __sFILE *);
wchar_t *
 fgetws(wchar_t * , int, struct __sFILE * );
wint_t fputwc(wchar_t, struct __sFILE *);
int fputws(const wchar_t * , struct __sFILE * );
int fwide(struct __sFILE *, int);
int fwprintf(struct __sFILE * , const wchar_t * , ...);
int fwscanf(struct __sFILE * , const wchar_t * , ...);
wint_t getwc(struct __sFILE *);
wint_t getwchar(void);
size_t mbrlen(const char * , size_t, mbstate_t * );
size_t mbrtowc(wchar_t * , const char * , size_t,
     mbstate_t * );
int mbsinit(const mbstate_t *);
size_t mbsrtowcs(wchar_t * , const char ** , size_t,
     mbstate_t * );
wint_t putwc(wchar_t, struct __sFILE *);
wint_t putwchar(wchar_t);
int swprintf(wchar_t * , size_t n, const wchar_t * ,
     ...);
int swscanf(const wchar_t * , const wchar_t * , ...);
wint_t ungetwc(wint_t, struct __sFILE *);
int vfwprintf(struct __sFILE * , const wchar_t * ,
     __va_list);
int vswprintf(wchar_t * , size_t n, const wchar_t * ,
     __va_list);
int vwprintf(const wchar_t * , __va_list);
size_t wcrtomb(char * , wchar_t, mbstate_t * );
wchar_t *wcscat(wchar_t * , const wchar_t * );
wchar_t *wcschr(const wchar_t *, wchar_t) __attribute__((__pure__));
int wcscmp(const wchar_t *, const wchar_t *) __attribute__((__pure__));
int wcscoll(const wchar_t *, const wchar_t *);
wchar_t *wcscpy(wchar_t * , const wchar_t * );
size_t wcscspn(const wchar_t *, const wchar_t *) __attribute__((__pure__));
size_t wcsftime(wchar_t * , size_t, const wchar_t * ,
     const struct tm * );
size_t wcslen(const wchar_t *) __attribute__((__pure__));
wchar_t *wcsncat(wchar_t * , const wchar_t * ,
     size_t);
int wcsncmp(const wchar_t *, const wchar_t *, size_t)
__attribute__((__pure__));
wchar_t *wcsncpy(wchar_t * , const wchar_t * , size_t);
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) __attribute__((__pure__));
wchar_t *wcsrchr(const wchar_t *, wchar_t) __attribute__((__pure__));
size_t wcsrtombs(char * , const wchar_t ** , size_t,
     mbstate_t * );
size_t wcsspn(const wchar_t *, const wchar_t *) __attribute__((__pure__));
wchar_t *wcsstr(const wchar_t * , const wchar_t * )
     __attribute__((__pure__));
size_t wcsxfrm(wchar_t * , const wchar_t * , size_t);
int wctob(wint_t);
double wcstod(const wchar_t * , wchar_t ** );
wchar_t *wcstok(wchar_t * , const wchar_t * ,
     wchar_t ** );
long wcstol(const wchar_t * , wchar_t ** , int);
unsigned long
  wcstoul(const wchar_t * , wchar_t ** , int);
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) __attribute__((__pure__));
int wmemcmp(const wchar_t *, const wchar_t *, size_t)
__attribute__((__pure__));
wchar_t *wmemcpy(wchar_t * , const wchar_t * , size_t);
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t);
wchar_t *wmemset(wchar_t *, wchar_t, size_t);
int wprintf(const wchar_t * , ...);
int wscanf(const wchar_t * , ...);


extern struct __sFILE *__stdinp;
extern struct __sFILE *__stdoutp;
extern struct __sFILE *__stderrp;
# 189 "/usr/include/wchar.h" 3 4
int vfwscanf(struct __sFILE * , const wchar_t * ,
     __va_list);
int vswscanf(const wchar_t * , const wchar_t * ,
     __va_list);
int vwscanf(const wchar_t * , __va_list);
float wcstof(const wchar_t * , wchar_t ** );
long double
 wcstold(const wchar_t * , wchar_t ** );


long long
 wcstoll(const wchar_t * , wchar_t ** , int);

unsigned long long
  wcstoull(const wchar_t * , wchar_t ** , int);




int wcswidth(const wchar_t *, size_t);
int wcwidth(wchar_t);




wchar_t *fgetwln(struct __sFILE * , size_t * );
size_t mbsnrtowcs(wchar_t * , const char ** , size_t,
     size_t, mbstate_t * );
wchar_t *wcsdup(const wchar_t *);
size_t wcsnrtombs(char * , const wchar_t ** , size_t,
     size_t, mbstate_t * );
size_t wcslcat(wchar_t *, const wchar_t *, size_t);
size_t wcslcpy(wchar_t *, const wchar_t *, size_t);


# 2 "wrong.c" 2
# 1 "/usr/include/stdio.h" 1 3 4
# 47 "/usr/include/stdio.h" 3 4
typedef __off_t fpos_t;
# 56 "/usr/include/stdio.h" 3 4
typedef __va_list va_list;
# 70 "/usr/include/stdio.h" 3 4
struct __sbuf {
 unsigned char *_base;
 int _size;
};


struct __sFILEX;
# 102 "/usr/include/stdio.h" 3 4
typedef struct __sFILE {
 unsigned char *_p;
 int _r;
 int _w;
 short _flags;
 short _file;
 struct __sbuf _bf;
 int _lbfsize;


 void *_cookie;
 int (*_close)(void *);
 int (*_read)(void *, char *, int);
 fpos_t (*_seek)(void *, fpos_t, int);
 int (*_write)(void *, const char *, int);


 struct __sbuf _ub;
 struct __sFILEX *_extra;
 int _ur;


 unsigned char _ubuf[3];
 unsigned char _nbuf[1];


 struct __sbuf _lb;


 int _blksize;
 fpos_t _offset;
} FILE;
# 208 "/usr/include/stdio.h" 3 4




void clearerr(FILE *);
int fclose(FILE *);
int feof(FILE *);
int ferror(FILE *);
int fflush(FILE *);
int fgetc(FILE *);
int fgetpos(FILE * , fpos_t * );
char *fgets(char * , int, FILE * );
FILE *fopen(const char * , const char * );
int fprintf(FILE * , const char * , ...);
int fputc(int, FILE *);
int fputs(const char * , FILE * );
size_t fread(void * , size_t, size_t, FILE * );
FILE *freopen(const char * , const char * , FILE * );
int fscanf(FILE * , const char * , ...);
int fseek(FILE *, long, int);
int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *);
size_t fwrite(const void * , size_t, size_t, FILE * );
int getc(FILE *);
int getchar(void);
char *gets(char *);
void perror(const char *);
int printf(const char * , ...);
int putc(int, FILE *);
int putchar(int);
int puts(const char *);
int remove(const char *);
int rename(const char *, const char *);
void rewind(FILE *);
int scanf(const char * , ...);
void setbuf(FILE * , char * );
int setvbuf(FILE * , char * , int, size_t);
int sprintf(char * , const char * , ...);
int sscanf(const char * , const char * , ...);
FILE *tmpfile(void);
char *tmpnam(char *);
int ungetc(int, FILE *);
int vfprintf(FILE * , const char * ,
     __va_list);
int vprintf(const char * , __va_list);
int vsprintf(char * , const char * ,
     __va_list);


int snprintf(char * , size_t, const char * ,
     ...) __attribute__((__format__ (__printf__, 3, 4)));
int vfscanf(FILE * , const char * , __va_list)
     __attribute__((__format__ (__scanf__, 2, 0)));
int vscanf(const char * , __va_list) __attribute__((__format__ (__scanf__, 1,
0)));
int vsnprintf(char * , size_t, const char * ,
     __va_list) __attribute__((__format__ (__printf__, 3, 0)));
int vsscanf(const char * , const char * , __va_list)
     __attribute__((__format__ (__scanf__, 2, 0)));
# 279 "/usr/include/stdio.h" 3 4
char *ctermid(char *);
FILE *fdopen(int, const char *);
int fileno(FILE *);



int pclose(FILE *);
FILE *popen(const char *, const char *);



int ftrylockfile(FILE *);
void flockfile(FILE *);
void funlockfile(FILE *);





int getc_unlocked(FILE *);
int getchar_unlocked(void);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);


void clearerr_unlocked(FILE *);
int feof_unlocked(FILE *);
int ferror_unlocked(FILE *);
int fileno_unlocked(FILE *);



int fseeko(FILE *, __off_t, int);
__off_t ftello(FILE *);



int getw(FILE *);
int putw(int, FILE *);



char *tempnam(const char *, const char *);






int asprintf(char **, const char *, ...) __attribute__((__format__ (__printf__,
2, 3)));
char *ctermid_r(char *);
void fcloseall(void);
char *fgetln(FILE *, size_t *);
const char *fmtcheck(const char *, const char *) __attribute__((__format_arg__
(2)));
int fpurge(FILE *);
void setbuffer(FILE *, char *, int);
int setlinebuf(FILE *);
int vasprintf(char **, const char *, __va_list)
     __attribute__((__format__ (__printf__, 2, 0)));






extern const int sys_nerr;
extern const char *const sys_errlist[];




FILE *funopen(const void *,
     int (*)(void *, char *, int),
     int (*)(void *, const char *, int),
     fpos_t (*)(void *, fpos_t, int),
     int (*)(void *));
# 363 "/usr/include/stdio.h" 3 4
int ftruncate(int, __off_t);



__off_t lseek(int, __off_t, int);



void *mmap(void *, size_t, int, int, int, __off_t);



int truncate(const char *, __off_t);






int __srget(FILE *);
int __swbuf(int, FILE *);







static __inline int __sputc(int _c, FILE *_p) {
 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  return (*_p->_p++ = _c);
 else
  return (__swbuf(_c, _p));
}
# 416 "/usr/include/stdio.h" 3 4
extern int __isthreaded;
# 450 "/usr/include/stdio.h" 3 4

# 3 "wrong.c" 2



void wrong(wchar_t *wordlist, wchar_t *word)
{ wchar_t buffer[64 +2];
    buffer[64 +2]=0;
    if(wcsstr(wordlist,buffer)==0) wcscpy(wordlist,buffer);
}

int main(int argc, char *argv[])
{ return 0;
}


-- 
           Summary: -O2 fails to compile
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikael dot ikivesi at pp dot inet dot fi
 GCC build triplet: gcc -O2 wrong.c
  GCC host triplet: Freebsd RELEG_7 i387


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35670

Reply via email to