This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [C]: Unnecessary int(16)->long(32) promotion: Bug in C front end?
- From: Ian Lance Taylor <iant at google dot com>
- To: Georg-Johann Lay <avr at gjlay dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 08 Jul 2011 06:31:16 -0700
- Subject: Re: [C]: Unnecessary int(16)->long(32) promotion: Bug in C front end?
- References: <4E16F9C7.8020008@gjlay.de>
Georg-Johann Lay writes:
> 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.
The constant 0x200000 does not fit in a 16-bit integer. Therefore the
compiler gives it the type long, as the C standard requires. The
arithmetic promotion rules then cause the compiler to cast i and
grub_scratch_mem to long, and to do the operation in long. The warning
then occurs when casting from long to a pointer type.
Ian