public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/5774: gcc -O causes local const structure to be corrupted.
@ 2002-02-24 22:46 stuart
  0 siblings, 0 replies; only message in thread
From: stuart @ 2002-02-24 22:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5774
>Category:       optimization
>Synopsis:       gcc -O causes local const structure to be corrupted.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 24 22:06:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Stuart
>Release:        3.0.4
>Organization:
>Environment:
System: AIX tatooine 3 4 004107134600


	
host: powerpc-ibm-aix4.3.1.0
build: powerpc-ibm-aix4.3.1.0
target: powerpc-ibm-aix4.3.1.0
configured with: ../gcc-3.0.4/configure --prefix=/usr/local-gcc-3.0.4
>Description:
When compiling without -O the output from the sample code is
as expected.  When -O is used the values are garbage.  The
sample code attached illustrates this by the printf() statements.
>How-To-Repeat:
Compile the sample code attached with
  gcc -O simple_aix_gcc_bug.c

./a.out
dist  val=0.000000
speed val=0.000000

Expected output (which gcc produces without -O):
./a.out
dist  val=13.000000
speed val=5.000000

gcc -E output follows

# 1 "/home/bart/stuart/hello/simple_aix_gcc_bug.c"
# 1 "/usr/include/stdio.h" 1 3
# 43 "/usr/include/stdio.h" 3
# 1 "/usr/include/standards.h" 1 3
# 44 "/usr/include/stdio.h" 2 3
# 73 "/usr/include/stdio.h" 3
typedef unsigned long size_t;
# 82 "/usr/include/stdio.h" 3
typedef long fpos_t;



typedef long long fpos64_t;
# 136 "/usr/include/stdio.h" 3
typedef struct {
        unsigned char *_ptr;
        int _cnt;
        unsigned char *_base;
        unsigned char *_bufendp;
        short _flag;
        short _file;
        int __stdioid;
        char *__newbase;



        long _unused[1];




} FILE;




extern FILE _iob[16];
# 171 "/usr/include/stdio.h" 3
extern size_t fread(void *, size_t, size_t, FILE *);
extern size_t fwrite(const void *, size_t, size_t,FILE *);
# 220 "/usr/include/stdio.h" 3
extern int __flsbuf(unsigned char, FILE *);
extern int __filbuf(FILE *);
extern int ferror(FILE *);
extern int feof(FILE *);
extern void clearerr(FILE *);
extern int putchar(int);
extern int getchar(void);
extern int putc(int, FILE *);
extern int getc(FILE *);
extern int remove(const char *);
extern int rename(const char *, const char *);
extern FILE *tmpfile(void);
extern char *tmpnam(char *);
extern int fclose(FILE *);
extern int fflush(FILE *);
extern FILE *fopen(const char *, const char *);
extern FILE *freopen(const char *, const char *, FILE *);
extern void setbuf(FILE *, char *);
extern int setvbuf(FILE *, char *, int, size_t);
extern int fprintf(FILE *, const char *, ...);
extern int fscanf(FILE *, const char *, ...);
extern int printf(const char *, ...);
extern int scanf(const char *, ...);
extern int sprintf(char *, const char *, ...);

extern int snprintf(char *, size_t, const char *, ...);

extern int sscanf(const char *, const char *, ...);
# 258 "/usr/include/stdio.h" 3
# 1 "/usr/include/va_list.h" 1 3
# 66 "/usr/include/va_list.h" 3
typedef char *__va_list;
# 259 "/usr/include/stdio.h" 2 3
extern int vfprintf(FILE *, const char *, __va_list);
extern int vprintf(const char *, __va_list);
extern int vsprintf(char *, const char *, __va_list);

extern int vsnprintf(char *, size_t, const char *, __va_list);



extern int fgetc(FILE *);
extern char *fgets(char *, int, FILE *);
extern int fputc(int, FILE *);
extern int fputs(const char *, FILE *);
extern char *gets(char *);
extern int puts(const char *);
extern int ungetc(int, FILE *);
extern int fgetpos(FILE *, fpos_t *);
extern int fseek(FILE *, long int, int);
extern int fsetpos(FILE *, const fpos_t *);
extern long ftell(FILE *);
extern void rewind(FILE *);
extern void perror(const char *);





extern int getc_unlocked(FILE *);
extern int getchar_unlocked(void);
extern int putc_unlocked(int, FILE *);
extern int putchar_unlocked(int);
# 363 "/usr/include/stdio.h" 3
# 1 "/usr/include/sys/types.h" 1 3
# 55 "/usr/include/sys/types.h" 3
# 1 "/usr/include/sys/inttypes.h" 1 3
# 49 "/usr/include/sys/inttypes.h" 3
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;




typedef signed long long int64_t;



typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;




typedef unsigned long long uint64_t;
# 76 "/usr/include/sys/inttypes.h" 3
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 88 "/usr/include/sys/inttypes.h" 3
typedef signed long intptr_t;
typedef unsigned long uintptr_t;





typedef signed char int_least8_t;
typedef signed short int_least16_t;
typedef signed int int_least32_t;




typedef signed long long int_least64_t;



typedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned int uint_least32_t;




typedef unsigned long long uint_least64_t;
# 122 "/usr/include/sys/inttypes.h" 3
typedef int32_t intfast_t;
typedef uint32_t uintfast_t;


typedef signed char int_fast8_t;
typedef int32_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast8_t;
typedef uint32_t uint_fast16_t;
typedef uint32_t uint_fast32_t;

typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 559 "/usr/include/sys/inttypes.h" 3
typedef signed long __long32_t;
typedef unsigned long __ulong32_t;
# 571 "/usr/include/sys/inttypes.h" 3
typedef signed int __long64_t;
typedef unsigned int __ulong64_t;
# 583 "/usr/include/sys/inttypes.h" 3
typedef signed int int32long64_t;
typedef unsigned int uint32long64_t;
# 596 "/usr/include/sys/inttypes.h" 3
typedef signed long long32int64_t;
typedef unsigned long ulong32int64_t;
# 606 "/usr/include/sys/inttypes.h" 3
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;




typedef signed long long int64;



typedef unsigned char u_int8;
typedef unsigned char u_int8_t;
typedef unsigned short u_int16;
typedef unsigned short u_int16_t;
typedef unsigned int u_int32;
typedef unsigned int u_int32_t;





typedef unsigned long long u_int64;
typedef unsigned long long u_int64_t;
# 56 "/usr/include/sys/types.h" 2 3
# 76 "/usr/include/sys/types.h" 3
typedef long ptrdiff_t;




typedef unsigned short wchar_t;




typedef unsigned int wctype_t;
# 106 "/usr/include/sys/types.h" 3
typedef int32long64_t time_t;




typedef int clock_t;
# 125 "/usr/include/sys/types.h" 3
typedef unsigned char uchar_t;
typedef unsigned short ushort_t;
typedef unsigned int uint_t;
typedef unsigned long ulong_t;
typedef signed long ssize_t;




typedef int level_t;
typedef int32long64_t daddr_t;
typedef int daddr32_t;

typedef int64_t daddr64_t;

typedef char * caddr_t;
typedef uint32long64_t ino_t;
typedef uint_t ino32_t;

typedef uint64_t ino64_t;

typedef short cnt_t;
typedef uint32long64_t dev_t;
typedef uint_t dev32_t;

typedef uint64_t dev64_t;

typedef int chan_t;
typedef int time32_t;
typedef int pid32_t;
typedef int tid32_t;

typedef uint64_t pid64_t;
typedef uint64_t tid64_t;
typedef uint64_t time64_t;







typedef void * __ptr32;
typedef char * __cptr32;


typedef int soff_t;




typedef long off_t;



typedef long long off64_t;


typedef long paddr_t;
typedef int key_t;
typedef int timer_t;
typedef short nlink_t;
typedef uint_t mode_t;
typedef uint_t uid_t;
typedef uint_t gid_t;
typedef __ptr32 mid_t;
typedef int pid_t;
typedef int tid_t;
typedef char slab_t[12];
typedef long mtyp_t;
typedef int boolean_t;


typedef int blkcnt_t;
typedef int blksize_t;
# 210 "/usr/include/sys/types.h" 3
typedef ulong_t fsblkcnt_t;
typedef ulong_t fsfilcnt_t;



        typedef int wint_t;



typedef uint_t id_t;
typedef unsigned int useconds_t;
typedef signed int suseconds_t;
typedef int clockid_t;




typedef struct sigset_t {

        unsigned int losigs;
        unsigned int hisigs;




} sigset_t;

typedef int signal_t;




typedef struct fsid_t {

        unsigned int val[2];



} fsid_t;

typedef struct __ptq_queue {
        struct __ptq_queue *__ptq_next;
        struct __ptq_queue *__ptq_prev;
} __ptq_queue;

typedef int __ptlock_type;

typedef struct __pt_attr *pthread_attr_t;
typedef struct __pt_attr *pthread_condattr_t;
typedef struct __pt_attr *pthread_mutexattr_t;


typedef struct __pt_attr *pthread_rwlockattr_t;


typedef unsigned int pthread_t;
typedef unsigned int pthread_key_t;
# 302 "/usr/include/sys/types.h" 3
typedef struct {
        __ptq_queue * __ptq_link;
        int __reserved1;
        __ptlock_type __ptmtx_lock;
        int __ptmtx_flags;
        pthread_t __ptmtx_owner;
        int __mtx_id;
        int __acquisitions;
        int __mtx_kind;
        int __lock_cpt;
        int __sleeps;
        int __misses;
        int __reserved2;
        unsigned long __ptmtx_dbx;
} pthread_mutex_t;

typedef struct {
        unsigned long __ptcv_dbx;
        int __reserved1;
        __ptlock_type __ptcv_lock;
        int __ptcv_flags;
        __ptq_queue * __ptcv_waiters;
        int __reserved2;
        int __cv_id;
        pthread_mutex_t *__cv_mutex;
        int __reserved3;
        int __cptwait;
        int __reserved;

} pthread_cond_t;



typedef struct {
        __ptlock_type __ptonce_lock;
        int __ptonce_initialized;
        int __ptonce_executing;
        int __ptonce_completed;
        pthread_mutex_t __ptonce_mutex;
        pthread_cond_t __ptonce_executed;
} pthread_once_t;


typedef struct {





        int __pad;
        unsigned long __ptrlock_dbx;


        pthread_mutex_t __rwl_mutex;
        pthread_cond_t __rwl_rsleepers;
        pthread_cond_t __rwl_wsleepers;
        int __rwl_flags;
        pthread_t __rwl_owner;
        int __rwl_rwlock_id;
        int __rwl_lock_count;


        int __rwl_waiting;
        int __rwl_wacquisitions;
        int __rwl_racquisitions;
        int __rwl_wsleeps;
        int __rwl_rsleeps;
        unsigned long __reserved[6];
} pthread_rwlock_t;
# 379 "/usr/include/sys/types.h" 3
# 1 "/usr/include/sys/m_types.h" 1 3
# 46 "/usr/include/sys/m_types.h" 3
typedef struct

label_t

{

        struct label_t *prev;
        ulong_t iar;
        ulong_t stack;
        ulong_t toc;
        ulong_t cr;
        ulong_t intpri;
        ulong_t reg[19];
# 68 "/usr/include/sys/m_types.h" 3
} label_t;




typedef long vmid_t;






typedef ulong_t vmhandle_t;






typedef long32int64_t kvmid_t;
typedef ulong32int64_t kvmhandle_t;

typedef int32long64_t vpn_t;
typedef int kvpn_t;
typedef int32long64_t rpn_t;
typedef int krpn_t;
typedef int32long64_t ext_t;
typedef int32long64_t vmsize_t;

typedef struct

vmaddr_t

{

        vmhandle_t srval;
        caddr_t offset;




} vmaddr_t;

typedef struct

adspace_t

{

        ulong32int64_t alloc;
        kvmhandle_t srval[16];




} adspace_t;
# 380 "/usr/include/sys/types.h" 2 3
# 427 "/usr/include/sys/types.h" 3
typedef unsigned long long __ptr64;
typedef unsigned long long __cptr64;





typedef ushort_t UniChar;




typedef uchar_t uchar;
typedef ushort_t ushort;
typedef uint_t uint;
typedef ulong_t ulong;

typedef struct { int r[1]; } * physadr_t;
typedef physadr_t physadr;


typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;

typedef struct _quad { int val[2]; } quad;
typedef int swblk_t;




struct sigset {
        unsigned int losigs;
        unsigned int hisigs;
};


struct fsid {
        unsigned int val[2];
};
# 476 "/usr/include/sys/types.h" 3
struct fileid {
        uint_t fid_len;
        ino_t fid_ino;
        uint_t fid_gen;
        char fid_x[(32 - sizeof(fsid_t) - sizeof(uint_t)) - (sizeof(ino_t) + 2) - sizeof(uint_t)];
};
# 497 "/usr/include/sys/types.h" 3
struct fid {
        uint_t fid_len;
        char fid_data[(32 - sizeof(fsid_t) - sizeof(uint_t))];
};
typedef struct fid fid_t;


struct fhandle {
        char x[32];
};
typedef struct fhandle fhandle_t;

struct filehandle {
        fsid_t fh_fsid;
        struct fileid fh_fid;
};
# 521 "/usr/include/sys/types.h" 3
struct unique_id {
       __ulong32_t word1;
       __ulong32_t word2;
       __ulong32_t word3;
       __ulong32_t word4;
};
typedef struct unique_id unique_id_t;
# 553 "/usr/include/sys/types.h" 3
typedef long long offset_t;





typedef unsigned long long size64_t;
typedef long long ssize64_t;






typedef long long longlong_t;
typedef unsigned long long u_longlong_t;
# 364 "/usr/include/stdio.h" 2 3
# 374 "/usr/include/stdio.h" 3
extern int fileno(FILE *);
extern FILE *fdopen(int,const char *);
extern char *ctermid(char *);

extern void flockfile(FILE *);
extern void funlockfile(FILE *);
extern int fseeko(FILE *, off_t, int);
extern off_t ftello(FILE *);
extern int ftrylockfile(FILE *);
extern void funlockfile(FILE *);
# 396 "/usr/include/stdio.h" 3
# 1 "/usr/include/va_list.h" 1 3
# 70 "/usr/include/va_list.h" 3
typedef __va_list va_list;
# 397 "/usr/include/stdio.h" 2 3

extern char *optarg;
extern int opterr;
extern int optind;
extern int optopt;
# 414 "/usr/include/stdio.h" 3
extern int getw(FILE *);
extern int putw(int, FILE *);
extern char *tempnam(const char*, const char*);
extern FILE *popen(const char *, const char *);
extern int pclose(FILE *);
extern int getopt(int, char * const [], const char*);
extern char *cuserid(char *);
# 430 "/usr/include/stdio.h" 3
# 1 "/usr/include/sys/limits.h" 1 3
# 247 "/usr/include/sys/limits.h" 3
# 1 "/usr/include/float.h" 1 3
# 206 "/usr/include/float.h" 3
        extern unsigned int SINFINITY;
        extern unsigned int _DBLINF[2];
        extern unsigned int SQNAN;
        extern unsigned int DQNAN[2];
        extern unsigned int SSNAN;
        extern unsigned int DSNAN[2];
# 237 "/usr/include/float.h" 3
typedef unsigned short fprnd_t;
# 246 "/usr/include/float.h" 3
fprnd_t fp_read_rnd(void);
fprnd_t fp_swap_rnd(fprnd_t rnd);
# 248 "/usr/include/sys/limits.h" 2 3
# 431 "/usr/include/stdio.h" 2 3



extern int fgetpos64(FILE *, fpos64_t *);
extern FILE *fopen64(const char *, const char *);
extern FILE *freopen64(const char *, const char *, FILE *);
extern int fseeko64(FILE *, off64_t, int);
extern int fsetpos64(FILE *, const fpos64_t *);
extern off64_t ftello64(FILE *);






extern void setbuffer(FILE *, char *, size_t);
extern void setlinebuf(FILE *);
# 2 "/home/bart/stuart/hello/simple_aix_gcc_bug.c" 2

typedef struct Map_NodeRef
{
        int iNode;
        int iMap;
}
Map_NodeRef;

typedef struct Map_Link
{
        Map_NodeRef from;
        Map_NodeRef to;
        double distance;
        double speed;
        double time;
}
Map_Link;

extern double addLinks( Map_Link *apLinks[], int nLinks )
{
        int i;
        double total = 0;

        for( i = 0; i < nLinks; i++ )
        {
                const Map_Link link = *apLinks[ i ];

                printf("dist  val=%.6lf\n", link.distance);
                printf("speed val=%.6lf\n", link.speed);
        }
        return total;
}
extern int main(int argc, char *argv[])
{
        Map_Link *al[1];
        Map_Link a = { {1, 2}, {2, 1}, 13, 5, 2.6 };

        al[0] = &a;
        addLinks(al, 1);

        return 0;
}
	
>Fix:
	Workaround is to not use -O (not very practical).
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-02-25  6:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-24 22:46 optimization/5774: gcc -O causes local const structure to be corrupted stuart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).