Bug 57695 - [c++11] generalized attributes with avr __progmem__
Summary: [c++11] generalized attributes with avr __progmem__
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-24 08:18 UTC by Klaus Rudolph
Modified: 2013-06-24 08:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Klaus Rudolph 2013-06-24 08:18:23 UTC
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.
Comment 1 Jakub Jelinek 2013-06-24 08:20:27 UTC
Probably because you should be using [[gnu::progmem]] or [[gnu::__progmem__]].
Comment 2 Klaus Rudolph 2013-06-24 08:46:10 UTC
@Jakub:

[[gnu::__progmem__]]  works!
[[gnu::progmem]] fails.

Thanks a lot!