This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: [C]: Unnecessary int(16)->long(32) promotion: Bug in C front end?


On Fri, Jul 08, 2011 at 02:36:23PM +0200, Georg-Johann Lay wrote:
> I am on 4.7 trunk (175991)
> 
> Configured with: ../../gcc.gnu.org/trunk/configure --target=avr
> --prefix=/local/gnu/install/gcc-4.7 --disable-nls --disable-shared
> --enable-languages=c,c++ --with-dwarf2 --disable-lto
> 
> Suppose the following source from gcc.c-torture/compile/pr30338.c:
> 
> extern char *grub_scratch_mem;
> int testload_func (char *arg, int flags)
> {
>   int i;
>   for (i = 0; i < 0x10ac0; i++)
>     if (*((unsigned char *) ((0x200000 + i + (int) grub_scratch_mem)))
>         != *((unsigned char *) ((0x300000 + i + (int) grub_scratch_mem))))
>       return 0;
>   return 1;
> }
> 
> And compiled with the command line
> 
> > avr-gcc pr30338.c -S -Os -dp -mmcu=atmega128 -fdump-tree-original
> 
> pr30338.c: In function 'testload_func':
> pr30338.c:9:11: warning: cast to pointer from integer of different
> size [-Wint-to-pointer-cast]
> pr30338.c:10:14: warning: cast to pointer from integer of different
> size [-Wint-to-pointer-cast]
> 
> Frist of all, the warning is incorrect because Pmode=HImode=int on AVR.

This is a gcc-help matter, if you have 16-bit int, then obviously
0x200000 doesn't fit into signed or unsigned int, and as it fits into
long (which must be 32-bit at least), it has type long int.
See ISO C99, 6.4.4.1.
"The type of an integer constant is the first of the corresponding list in
which its value can be represented."
For no suffix and hexadecimal constant, the list is
{,long ,long long }{,unsigned }int

	Jakub


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