This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug in double->unsigned casting on powerpc-unknown-linux-gnu


Albrecht Dress <ad@Speckle.mpifr-bonn.mpg.de> reported that the
attached program failed under recent egcs, with or without
optimization.  It returns the value of the double which appears in the
.s file (what is that value and what is it doing there, anyway?)
instead of the value which was supposed to be assigned to it.  The
relevant section of the assembly produced by egcs (-) and gcc 2.7.2 (+)
[the latter works correctly]:

-       lis 11,0x4330
-       addis 7,0,.LC1@ha
-       addi 7,7,.LC1@l
-       lfd 0,0(7)
-       lis 10,0x10
-       ori 10,10,8
-       addi 8,31,8
-       add 10,8,10
-       stw 0,4(10)
-       stw 11,0(10)
-       lfd 13,0(10)
-       fsub 0,13,0
+       lis 10,0x4330
+       addis 8,0,.LC1@ha
+       addi 8,8,.LC1@l
+       lfd 13,0(8)
+       addis 11,31,16
+       stw 0,36(11)
+       stw 10,32(11)
+       lfd 0,32(1)
+       fsub 0,0,13

I can't quite follow it - the fsub doesn't seem to make sense but is
apparently not at fault, so my understanding of ppc floating point is
probably a little off.

Attached are the .c, .s, and .i (all fairly small).  The problem does
not exist if the integer is signed (-DINT), or if an array is not used.

Dan
#include <stdio.h>

#define UINT

#ifdef INT
typedef int chktype;
#elif  USHORT
typedef unsigned short chktype;
#elif  UINT
typedef unsigned int chktype;
#elif  SHORT
typedef short chktype;
#else
#error "no type defined!"
#endif

int main (void)
{
        chktype a [512][512];
        double b;

        a [123][456] = 1009;
        b = (double)a [123][456];
        printf ("%d == %g ?????\n", a [123][456], b);
        return 0;
}
# 1 "Check.c"
# 1 "/usr/include/stdio.h" 1 3
 

















 







# 1 "/usr/include/features.h" 1 3
 




















 

























































 



















 





 



 







 
# 136 "/usr/include/features.h" 3


 









 





 



























# 194 "/usr/include/features.h" 3


































 



 








 




 

# 1 "/usr/include/sys/cdefs.h" 1 3
 




















# 1 "/usr/include/features.h" 1 3
 

















# 279 "/usr/include/features.h" 3

# 22 "/usr/include/sys/cdefs.h" 2 3


 




 








 




# 67 "/usr/include/sys/cdefs.h" 3


 







 



# 99 "/usr/include/sys/cdefs.h" 3



 








 















 








 








 









 




# 248 "/usr/include/features.h" 2 3


 








 





 

 








# 1 "/usr/include/gnu/stubs.h" 1 3
 
























# 276 "/usr/include/features.h" 2 3




# 27 "/usr/include/stdio.h" 2 3


 



# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 1 3






 


# 19 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3



 


 





 


# 61 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 





 


















 





 

 

# 131 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 

 


































typedef unsigned int size_t;






















 




 

# 271 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


# 283 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 

 

# 317 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3




 





















# 33 "/usr/include/stdio.h" 2 3





# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 1 3
 








































# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 1 3
 


 
 







 



 

typedef struct __va_list_tag {
  char gpr;			 


  char fpr;			 


  char *overflow_arg_area;	 

  char *reg_save_area;		 
} __va_list[1], __gnuc_va_list[1];









 

# 174 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 3



# 230 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 3

# 42 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 2 3

# 124 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 3











# 202 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 3




# 38 "/usr/include/stdio.h" 2 3


# 1 "/usr/include/bits/types.h" 1 3
 

















 









# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 1 3






 


# 19 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3



 


 





 


# 61 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 





 


















 





 

 

# 131 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 

 


# 188 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3





 




 

# 271 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


# 283 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 

 

# 317 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3




 





















# 29 "/usr/include/bits/types.h" 2 3


 
typedef unsigned char __u_char;
typedef unsigned short __u_short;
typedef unsigned int __u_int;
typedef unsigned long __u_long;

__extension__ typedef unsigned long long int __u_quad_t;
__extension__ typedef long long int __quad_t;
# 48 "/usr/include/bits/types.h" 3

typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;

__extension__ typedef signed long long int __int64_t;
__extension__ typedef unsigned long long int __uint64_t;

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 long int __rlim_t;		 
typedef __quad_t __rlim64_t;		 
typedef __u_int __id_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;


 

 
typedef __u_long __blkcnt_t;
typedef __u_quad_t __blkcnt64_t;

 
typedef long int __fsblkcnt_t;
typedef __quad_t __fsblkcnt64_t;

 
typedef __u_long __fsfilcnt_t;
typedef __u_quad_t __fsfilcnt64_t;

 
typedef __u_long __ino64_t;

 
typedef __loff_t __off64_t;

 
typedef int __t_scalar_t;
typedef unsigned int __t_uscalar_t;

 
typedef int __intptr_t;


 





# 40 "/usr/include/stdio.h" 2 3







 
typedef struct _IO_FILE FILE;








# 1 "/usr/include/libio.h" 1 3
 




























# 1 "/usr/include/_G_config.h" 1 3
 





 






# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 1 3






 


# 19 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3



 


 





 


# 61 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 





 


















 





 

 

# 131 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3


 

 


# 188 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3





 




 





























 


























typedef long int wchar_t;
























typedef unsigned int  wint_t;




 

 

# 317 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stddef.h" 3




 





















# 14 "/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__)));




 


















 




 














# 30 "/usr/include/libio.h" 2 3
















 

# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 1 3
 








































# 1 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 1 3
 


 
 

# 37 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 3


 

# 174 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 3



# 230 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/va-ppc.h" 3

# 42 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 2 3

# 124 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 3











# 202 "/usr/lib/gcc-lib/powerpc-linux/egcs-2.91.58/include/stdarg.h" 3




# 48 "/usr/include/libio.h" 2 3







# 67 "/usr/include/libio.h" 3


 

















# 98 "/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;
# 186 "/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   _old_offset;  


   
  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];

   

  _IO_lock_t *_lock;








  __off64_t   _offset;
  char *_IO_save_ptr;
   
  char _unused2[16 * sizeof (int) - sizeof (char *)];

};


typedef struct _IO_FILE _IO_FILE;


struct _IO_FILE_plus;
extern struct _IO_FILE_plus _IO_2_1_stdin_;
extern struct _IO_FILE_plus _IO_2_1_stdout_;
extern struct _IO_FILE_plus _IO_2_1_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 __off64_t   _IO_seekoff  (_IO_FILE *, __off64_t  , int, int)    ;
extern __off64_t   _IO_seekpos  (_IO_FILE *, __off64_t  , int)    ;

extern void _IO_free_backup_area  (_IO_FILE *)    ;






# 57 "/usr/include/stdio.h" 2 3








 

typedef __off_t  fpos_t;







 





 





 






 







 




 








# 1 "/usr/include/bits/stdio_lim.h" 1 3
 




































# 116 "/usr/include/stdio.h" 2 3



 
extern FILE *stdin;		 
extern FILE *stdout;		 
extern FILE *stderr;		 


 
extern int remove  (__const char *__filename)    ;
 
extern int rename  (__const char *__old, __const char *__new)    ;


 

extern FILE *tmpfile  (void)    ;










 
extern char *tmpnam  (char *__s)    ;


 

extern char *tmpnam_r  (char *__s)    ;




 






extern char *tempnam  (__const char *__dir, __const char *__pfx)    ;



 
extern int fclose  (FILE *__stream)    ;
 
extern int fflush  (FILE *__stream)    ;


 
extern int fflush_unlocked  (FILE *__stream)    ;









 
extern FILE *fopen  (__const char *   __filename,
			 __const char *   __modes)    ;
 
extern FILE *freopen  (__const char *   __filename,
			   __const char *   __modes,
			   FILE *   __stream)    ;
# 203 "/usr/include/stdio.h" 3










 
extern FILE *fdopen  (int __fd, __const char *__modes)    ;


# 227 "/usr/include/stdio.h" 3



 

extern void setbuf  (FILE *   __stream, char *   __buf)    ;
 


extern int setvbuf  (FILE *   __stream, char *   __buf,
			 int __modes, size_t __n)    ;


 

extern void setbuffer  (FILE *__stream, char *__buf, size_t __size)    ;

 
extern void setlinebuf  (FILE *__stream)    ;



 
extern int fprintf  (FILE *   __stream,
			 __const char *   __format, ...)    ;
 
extern int printf  (__const char *   __format, ...)    ;
 
extern int sprintf  (char *   __s,
			 __const char *   __format, ...)    ;

 
extern int vfprintf  (FILE *   __s,
			  __const char *   __format,
			  __gnuc_va_list  __arg)    ;
 
extern int vprintf  (__const char *   __format,
			 __gnuc_va_list  __arg)    ;
 
extern int vsprintf  (char *   __s,
			  __const char *   __format,
			  __gnuc_va_list  __arg)    ;










 
extern int snprintf  (char *   __s, size_t __maxlen,
			  __const char *   __format, ...)    
     __attribute__ ((__format__ (__printf__, 3, 4)));

extern int __vsnprintf  (char *   __s, size_t __maxlen,
			     __const char *   __format,
			     __gnuc_va_list  __arg)    
     __attribute__ ((__format__ (__printf__, 3, 0)));
extern int vsnprintf  (char *   __s, size_t __maxlen,
			   __const char *   __format,
			   __gnuc_va_list  __arg)    
     __attribute__ ((__format__ (__printf__, 3, 0)));


# 313 "/usr/include/stdio.h" 3



 
extern int fscanf  (FILE *   __stream,
			__const char *   __format, ...)    ;
 
extern int scanf  (__const char *   __format, ...)    ;
 
extern int sscanf  (__const char *   __s,
			__const char *   __format, ...)    ;

# 341 "/usr/include/stdio.h" 3



 
extern int fgetc  (FILE *__stream)    ;
extern int getc  (FILE *__stream)    ;

 
extern int getchar  (void)    ;

 












 
extern int getc_unlocked  (FILE *__stream)    ;
extern int getchar_unlocked  (void)    ;

# 380 "/usr/include/stdio.h" 3




 
extern int fputc  (int __c, FILE *__stream)    ;
extern int putc  (int __c, FILE *__stream)    ;

 
extern int putchar  (int __c)    ;

 












 
extern int fputc_unlocked  (int __c, FILE *__stream)    ;











 
extern int putc_unlocked  (int __c, FILE *__stream)    ;
extern int putchar_unlocked  (int __c)    ;

# 433 "/usr/include/stdio.h" 3





 
extern int getw  (FILE *__stream)    ;

 
extern int putw  (int __w, FILE *__stream)    ;



 
extern char *fgets  (char *   __s, int __n,
			 FILE *   __stream)    ;







 

extern char *gets  (char *__s)    ;


# 483 "/usr/include/stdio.h" 3



 
extern int fputs  (__const char *   __s,
		       FILE *   __stream)    ;







 
extern int puts  (__const char *__s)    ;


 
extern int ungetc  (int __c, FILE *__stream)    ;


 
extern size_t fread  (void *   __ptr, size_t __size,
			  size_t __n, FILE *   __stream)    ;
 
extern size_t fwrite  (__const void *   __ptr, size_t __size,
			   size_t __n, FILE *   __s)    ;


 
extern size_t fread_unlocked  (void *   __ptr, size_t __size,
				   size_t __n, FILE *   __stream)    ;
extern size_t fwrite_unlocked  (__const void *   __ptr,
				    size_t __size, size_t __n,
				    FILE *   __stream)    ;



 
extern int fseek  (FILE *__stream, long int __off, int __whence)    ;
 
extern long int ftell  (FILE *__stream)    ;
 
extern void rewind  (FILE *__stream)    ;

 




 


typedef __off_t off_t;




















 
extern int fgetpos  (FILE *   __stream,
			 fpos_t *   __pos)    ;
 
extern int fsetpos  (FILE *__stream, __const fpos_t *__pos)    ;
# 582 "/usr/include/stdio.h" 3


# 592 "/usr/include/stdio.h" 3


 
extern void clearerr  (FILE *__stream)    ;
 
extern int feof  (FILE *__stream)    ;
 
extern int ferror  (FILE *__stream)    ;


 
extern void clearerr_unlocked  (FILE *__stream)    ;
extern int feof_unlocked  (FILE *__stream)    ;
extern int ferror_unlocked  (FILE *__stream)    ;

# 619 "/usr/include/stdio.h" 3




 
extern void perror  (__const char *__s)    ;

 


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








 
extern int fileno  (FILE *__stream)    ;



 
extern int fileno_unlocked  (FILE *__stream)    ;





 
extern FILE *popen  (__const char *__command, __const char *__modes)    ;

 
extern int pclose  (FILE *__stream)    ;




 
extern char *ctermid  (char *__s)    ;









# 680 "/usr/include/stdio.h" 3




 

 
extern void flockfile  (FILE *__stream)    ;

 

extern int ftrylockfile  (FILE *__stream)    ;

 
extern void funlockfile  (FILE *__stream)    ;










 

 





# 1 "Check.c" 2







typedef unsigned int chktype;






int main (void)
{
        chktype a [512][512];
        double b;

        a [123][456] = 1009;
        b = (double)a [123][456];
        printf ("%d == %g ?????\n", a [123][456], b);
        return 0;
}
	.file	"Check.c"
gcc2_compiled.:
	.section	".rodata"
	.align 2
.LC0:
	.string	"%d == %g ?????\n"
	.align 3
.LC1:
	.double 0d4.50359962737049600000e15
	.section	".text"
	.align 2
	.globl main
	.type	 main,@function
main:
	mr 12,1
	lis 0,65519
	ori 0,0,65488
	stwux 1,1,0
	mflr 0
	stw 31,-8(12)
	stw 0,4(12)
	mr 31,1
	lis 0,0x4
	ori 0,0,8
	add 9,31,0
	li 0,1009
	stw 0,-8416(9)
	lis 0,0x10
	ori 0,0,8
	add 9,31,0
	lis 0,0x4
	ori 0,0,8
	add 11,31,0
	lwz 0,-8416(11)
	lis 10,0x4330
	addis 8,0,.LC1@ha
	addi 8,8,.LC1@l
	lfd 13,0(8)
	addis 11,31,16
	stw 0,36(11)
	stw 10,32(11)
	lfd 0,32(1)
	fsub 0,0,13
	stfd 0,0(9)
	lis 0,0x4
	ori 0,0,8
	add 9,31,0
	lis 0,0x10
	ori 0,0,8
	add 11,31,0
	addis 10,0,.LC0@ha
	addi 3,10,.LC0@l
	lwz 4,-8416(9)
	lfd 1,0(11)
	creqv 6,6,6
	bl printf
	li 3,0
	b .L1
.L1:
	lwz 11,0(1)
	lwz 0,4(11)
	mtlr 0
	lwz 31,-8(11)
	mr 1,11
	blr
.Lfe1:
	.size	 main,.Lfe1-main
	.ident	"GCC: (GNU) egcs-2.91.58 19980901 (egcs-1.1.1 pre-release)"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]