http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57695

            Bug ID: 57695
           Summary: [c++11] generalized attributes with avr __progmem__
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lts-rudolph at gmx dot de

The two statements:
extern const X x __attribute__ ((__progmem__)) = { 1 };  // works as expected
extern const X x [[__progmem__]] = { 1 };                // warning & broken
code

See the following description to get working example.

The following code compiles as expected with avr-g++ 4.8.1: (code must split in
different translation units to see any result, because the optimizer will
remove all effects while inlining the instructions)

x.h:

struct X
{
    uint8_t a;
};

x.cpp:

extern const X x __attribute__ ((__progmem__)) = { 1 };

main.cpp:

#include "x.h"
extern const X x __attribute__ (( __progmem__ )); 

int main()
{   
    PORTB = pgm_read_byte(& (x.a));
    return 0;
}

results in (objdump -d):

0000001a <x>:
  1a:   01 00                                               ..
  ...

  2e:   ea e1           ldi r30, 0x1A   ; 26
  30:   f0 e0           ldi r31, 0x00   ; 0
  32:   c8 95           lpm

the result is fine.

Using generalized attributes do NOT work:

extern const X x [[__progmem__]] = { 1 };

this results in a warning "x.cpp:8:32: warning: 'progmem' attribute directive
ignored [-Wattributes]" and the code is broken because the var x is stored to
ram instead of flash.

Reply via email to