http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50733
Bug #: 50733 Summary: avr-gcc 4.3.5 generates incorrect code when using PROGMEM macro Classification: Unclassified Product: gcc Version: 4.3.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: marcos...@coel.com.br Created attachment 25505 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25505 Preprocessed file Hi, The compiler is generating incorrect code for the source code below, when using the PROGMEM macro: #include <avr/io.h> #include <avr/pgmspace.h> // PROGMEM #include <stdio.h> static PROGMEM const char orig[6] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; static char dest[6]; int main(void) { for(;;) { unsigned int loop; for (loop = 0; loop < sizeof(orig)/sizeof(orig[0]); loop++) dest[loop] = orig[loop]; } } I compiled using the folowing command line: avr-gcc -I/usr/lib/gcc/avr/4.3.5/include -I/usr/lib/gcc/avr/4.3.5/include-fixed -I/usr/lib/avr/include -Wall -g3 -gstabs -O0 -fpack-struct -fshort-enums -std=gnu99 -funsigned-char -funsigned-bitfields -save-temps -Wall -Wextra -fno-strict-aliasing -fwrapv -mmcu=atmega16 -DF_CPU=1000000UL test.c It should have a "lpm" instruction somewhere in the asm output. The result is "orig" not being copied to "dest". The compiler generates correct code when the PROGMEM macro is removed but it generates a copy of the constant in the SRAM which is undesirable because I´m using large tables that fills up all the SRAM. GCC version: 4.3.5 Host type: x86_64-linux-gnu (Ubuntu 11.04) Target type: avr Configure command line: ../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