Bug 34734 - [4.2/4.3/4.5/4.6 Regression][avr] attribute((progmem)) not handled properly in C++
Summary: [4.2/4.3/4.5/4.6 Regression][avr] attribute((progmem)) not handled properly i...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.2.2
: P3 normal
Target Milestone: 4.6.2
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 40112 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-01-11 01:23 UTC by Markus Lampert
Modified: 2014-02-16 10:02 UTC (History)
11 users (show)

See Also:
Host: x86
Target: avr
Build:
Known to work: 4.6.2
Known to fail: 4.2.1, 4.2.2, 4.3.2, 4.6.1
Last reconfirmed: 2009-08-07 19:18:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Lampert 2008-01-11 01:23:27 UTC
Using the progmem attribute in C++ sources produce warning messages about uninitialized variables. The following preprocessor output works correctly under 4.1 but produces said warnings (in every warning level):

# 1 "is.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "is.cpp"
int i1 __attribute__((__progmem__)) = 1;
int __attribute__((__progmem__)) i2 = 2;
__attribute__((__progmem__)) int i3 = 3;
extern int i4 __attribute__((__progmem__)); int i4 = 4;
extern int __attribute__((__progmem__)) i5; int i5 = 5;
extern __attribute__((__progmem__)) int i6; int i6 = 6;
typedef int i7_t __attribute__((__progmem__)); i7_t i7 = 7;
typedef int __attribute__((__progmem__)) i8_t; i8_t i8 = 8;
typedef __attribute__((__progmem__)) int i9_t; i9_t i9 = 9;
const char s1[] __attribute__((__progmem__)) = "string 1";
const char __attribute__((__progmem__)) s2[] = "string 2";
const __attribute__((__progmem__)) char s3[] = "string 3";
__attribute__((__progmem__)) const char s4[] = "string 4";
extern const char s5[] __attribute__((__progmem__)); const char s5[] = "string 5";
extern const char __attribute__((__progmem__)) s6[]; const char s6[] = "string 6";
extern const __attribute__((__progmem__)) char s7[]; const char s7[] = "string 7";
extern __attribute__((__progmem__)) const char s8[]; const char s8[] = "string 8";
typedef const char s9_t __attribute__((__progmem__)); const s9_t s9[] = "string 9";
typedef const char __attribute__((__progmem__)) s10_t; const s10_t s10[] = "string 10";
typedef const __attribute__((__progmem__)) char s11_t; const s11_t s11[] = "string 11";
typedef __attribute__((__progmem__)) const char s12_t; const s12_t s12[] = "string 12";

This is the used command line and the compiler output:

/usr/local/avr-4.2.2/bin/avr-gcc -Wall -save-temps -mmcu=atmega88 -Os -c -o /tmp/x.o is.cpp
is.cpp:1: warning: only initialized variables can be placed into program memory area
is.cpp:2: warning: only initialized variables can be placed into program memory area
is.cpp:3: warning: only initialized variables can be placed into program memory area
is.cpp:10: warning: only initialized variables can be placed into program memory area
is.cpp:11: warning: only initialized variables can be placed into program memory area
is.cpp:12: warning: only initialized variables can be placed into program memory area
is.cpp:13: warning: only initialized variables can be placed into program memory area

Please note that the same source compiled as C works properly without any warnings.
Comment 1 Liviu Ionescu 2008-02-02 08:11:59 UTC
after upgrading to WinAVR-20071221 my C++ projects trigger the same warning message.

for completeness, my sources look like:


// usb_user_device_descriptor
PROGMEM S_usb_device_descriptor usb_dev_desc =
  {
    sizeof( usb_dev_desc ), DEVICE_DESCRIPTOR,
    U_WORD( USB_SPECIFICATION ), DEVICE_CLASS,
    DEVICE_SUB_CLASS, DEVICE_PROTOCOL, EP_CONTROL_LENGTH,
    U_WORD( VENDOR_ID ),
    U_WORD( PRODUCT_ID ),
    U_WORD( RELEASE_NUMBER ), STRING_INDEX_MAN, STRING_INDEX_PROD,
    STRING_INDEX_SN, NB_CONFIGURATION
  };

Liviu
Comment 2 hsteinhaus 2008-03-07 20:59:16 UTC
version 4.2.1 seems to be affected as well:

--------------------------------------------
holger@x:~/scratch$ cat foo.cpp
#include <avr/pgmspace.h>

const int foobar1 = 42;
int foobar2 = 42;
const int PROGMEM foobar3 = 42;
int PROGMEM foobar4 = 42;

holger@x:~/scratch$ avr-g++ -Wall -mmcu=atmega1281 -c foo.cpp
foo.cpp:5: warning: only initialized variables can be placed into program memory area
foo.cpp:6: warning: only initialized variables can be placed into program memory area
holger@x:~/scratch$ avr-g++ --version
avr-g++ (GCC) 4.2.1 (SUSE Linux)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Comment 3 Eric Weddington 2009-08-07 19:16:32 UTC
*** Bug 40112 has been marked as a duplicate of this bug. ***
Comment 4 Michael Schulze 2010-06-09 09:16:13 UTC
I found a way to place data in program memory for C++ without producing the annoying warnings. The trick is omiting __attribute__((__progmem__)) and instead always use __attribute__((section(".progmem.something"))) for placing your data into a special section beginning with ".progmem.". I tested this with different avr-g++ compiler versions (3.4.4, 4.1.1, 4.2.1, 4.3.3, 4.4.0, and 4.4.3), and it always results in the desired behavior.

Example:
[mschulze@teeth tst]$ cat progmem.cpp 
static char __attribute((section(".progmem.something"))) str[]="program memory data";

const char* test() {
    return str;
}
[mschulze@teeth tst]$ /usr/bin/avr-g++ -Wall -mmcu=atmega1281 -c progmem.cpp 
[mschulze@teeth tst]$ /usr/bin/avr-g++ --version
avr-g++ (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[mschulze@teeth tst]$ 

Regards,
Michael
Comment 5 Michał Walenciak 2011-02-06 12:19:00 UTC
same problem in 4.5.2.
Maybe importance of this bug should be increased? Imho it's a little bit embarrassing to keep this bug so long... (since 2008, over 3 yrs!)

regards
Comment 6 Georg-Johann Lay 2011-06-29 07:57:28 UTC
Author: gjl
Date: Wed Jun 29 07:57:25 2011
New Revision: 175621

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175621
Log:
	PR target/34734
	* config/avr/avr.c (avr_handle_progmem_attribute): Move warning 
	about uninitialized data attributed 'progmem' from here...
	(avr_encode_section_info): ...to this new function.
	(TARGET_ENCODE_SECTION_INFO): New define.
	(avr_section_type_flags): For data in ".progmem.data", remove
	section flag SECTION_WRITE.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.c
Comment 7 Georg-Johann Lay 2011-06-30 13:28:46 UTC
Author: gjl
Date: Thu Jun 30 13:28:43 2011
New Revision: 175705

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175705
Log:
	
	PR target/34734
	Backport from mainline
	* config/avr/avr.c (avr_handle_progmem_attribute): Move warning 
	about uninitialized data attributed 'progmem' from here...
	(avr_encode_section_info): ...to this new function.
	(TARGET_ENCODE_SECTION_INFO): New define.
	(avr_section_type_flags): For data in ".progmem.data", remove
	section flag SECTION_WRITE.


Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/avr/avr.c
Comment 8 Georg-Johann Lay 2011-06-30 13:39:18 UTC
Closed as resolved+fixed.

(In reply to comment #5)
> same problem in 4.5.2.
> Maybe importance of this bug should be increased? Imho it's a little bit
> embarrassing to keep this bug so long... (since 2008, over 3 yrs!)
> regards

Increasing importance won't help.  The only thing that would help is increasing number of people that are inclined to improve avr-gcc.

regards

Note that progmem on types is not documented an not supposed to work at all.
Comment 9 Georg-Johann Lay 2011-06-30 13:45:08 UTC
Author: gjl
Date: Thu Jun 30 13:45:04 2011
New Revision: 175706

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175706
Log:
	PR target/34734
	Backport from mainline
	(avr_section_type_flags): For data in ".progmem.data", remove
	section flag SECTION_WRITE.

Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/avr/avr.c
Comment 10 Georg-Johann Lay 2011-07-04 12:48:07 UTC
Author: gjl
Date: Mon Jul  4 12:48:04 2011
New Revision: 175811

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175811
Log:
	PR target/34734
	PR target/44643
	* gcc.target/avr/avr.exp: Run over cpp files, too.
	* gcc.target/avr/torture/avr-torture.exp: Ditto.
	* gcc.target/avr/progmem.h: New file.
	* gcc.target/avr/exit-abort.h: New file.
	* gcc.target/avr/progmem-error-1.c: New file.
	* gcc.target/avr/progmem-error-1.cpp: New file.
	* gcc.target/avr/progmem-warning-1.c: New file.
	* gcc.target/avr/torture/progmem-1.c: New file.
	* gcc.target/avr/torture/progmem-1.cpp: New file.


Added:
    trunk/gcc/testsuite/gcc.target/avr/exit-abort.h
    trunk/gcc/testsuite/gcc.target/avr/progmem-error-1.c
    trunk/gcc/testsuite/gcc.target/avr/progmem-error-1.cpp
    trunk/gcc/testsuite/gcc.target/avr/progmem-warning-1.c
    trunk/gcc/testsuite/gcc.target/avr/progmem.h
    trunk/gcc/testsuite/gcc.target/avr/torture/progmem-1.c
    trunk/gcc/testsuite/gcc.target/avr/torture/progmem-1.cpp
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/avr/avr.exp
    trunk/gcc/testsuite/gcc.target/avr/torture/avr-torture.exp
Comment 11 Jackie Rosen 2014-02-16 10:02:49 UTC Comment hidden (spam)