[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Uninitialized warning in 3.4.3
From: |
David Kelly |
Subject: |
[avr-gcc-list] Uninitialized warning in 3.4.3 |
Date: |
Mon, 4 Apr 2005 21:42:56 -0500 |
Another little issue I've run across recently:
This warning made me look twice at the generated code. Unless my brain
is totally fried the warning is wrong. The code within my
"#ifdef/#endif" gets optimized to nothing if enabled, and also mutes the
warning:
#define __bs_16(x) (((x) >> 8) | ((x) << 8))
extern void do_something( unsigned, unsigned );
void function( unsigned a, unsigned b )
{
unsigned mbr, cnt;
#ifdef MUTE_WARNING
mbr = cnt = 0;
#endif
mbr = __bs_16(a);
cnt = __bs_16(b);
do_something( mbr, cnt );
}
Built like this:
% avr-gcc -O -gdwarf-2 -Wall -ffreestanding -mmcu=atmega128 -c junk.c
junk.c: In function `function':
junk.c:7: warning: 'mbr' might be used uninitialized in this function
junk.c:7: warning: 'cnt' might be used uninitialized in this function
%
Or quietened like this:
% avr-gcc -DMUTE_WARNING -O -gdwarf-2 -Wall -ffreestanding
-mmcu=atmega128 -c junk.c
%
Either way the disassembly looks the same:
% avr-objdump -S junk.o
junk.o: file format elf32-avr
Disassembly of section .text:
00000000 <function>:
void function( unsigned a, unsigned b )
{
unsigned mbr, cnt;
mbr = __bs_16(a);
0: 49 2f mov r20, r25
2: 58 2f mov r21, r24
cnt = __bs_16(b);
4: 27 2f mov r18, r23
6: 36 2f mov r19, r22
do_something( mbr, cnt );
8: b9 01 movw r22, r18
a: ca 01 movw r24, r20
c: 0e 94 00 00 call 0x0
10: 08 95 ret
%
Apparently my byte-swap macro is confusing avr-gcc. It doesn't confuse
FreeBSD gcc 3.4.2. OTOH its quite impressive how the optimizer did the
right thing.
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] Uninitialized warning in 3.4.3,
David Kelly <=