Hi all,

I found a issue in the optimization part of gcc-avr.
(I'm new to this stuff so be patient :) )


I'm losing some data returned from a function,
Attaching the smallest example, I could find.
Similarly bug occurs in the ArduinoISP example,
function program_page().


code:
unsigned char getch();

int f()
{
    int a;
    unsigned char c2;
    a = getch();
    a *= 256;  //!! bug - getch() value disappears
    c2 = getch();
    a  += c2;
    return a;
}


output:
int f()
{
   0: ef 92       push r14
   2: ff 92       push r15
   4: cf 93       push r28
   6: df 93       push r29
    int a;
    unsigned char c2;
    a = getch();
   8: 0e 94 00 00 call 0 ; 0x0 <_Z1fv>
    a *= 256;  //!! bug - getch() value disappears
   c: 80 e0       ldi r24, 0x00 ; 0
   e: ec 01       movw r28, r24
    c2 = getch();
  10: 0e 94 00 00 call 0 ; 0x0 <_Z1fv>
    a  += c2;
  14: c8 0f       add r28, r24
  16: d1 1d       adc r29, r1
    return a;
}
  18: ce 01       movw r24, r28
  1a: df 91       pop r29
  1c: cf 91       pop r28
  1e: ff 90       pop r15
  20: ef 90       pop r14
  22: 08 95       ret

some info:
system ubuntu 11.10 amd64

#avr-g++ -mmcu=atmega1280 -g -Os -c b.cpp
#avr-objdump -S  -d b.o > b.asm
#avr-g++ -v

Using built-in specs.
COLLECT_GCC=avr-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man
--bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared
--with-system-zlib --enable-long-long --enable-nls
--without-included-gettext --disable-checking --disable-libssp
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)


Best regards
Paweł,
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to