Discussion:
[Bug c++/57695] New: [c++11] generalized attributes with avr __progmem__
lts-rudolph at gmx dot de
2013-06-24 08:18:23 UTC
Permalink
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.
jakub at gcc dot gnu.org
2013-06-24 08:20:27 UTC
Permalink
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57695

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Probably because you should be using [[gnu::progmem]] or [[gnu::__progmem__]].
lts-rudolph at gmx dot de
2013-06-24 08:46:10 UTC
Permalink
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57695

Klaus Rudolph <lts-rudolph at gmx dot de> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID

--- Comment #2 from Klaus Rudolph <lts-rudolph at gmx dot de> ---
@Jakub:

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

Thanks a lot!

Loading...