Bug 26882 - [AVR][C++] ICE when using template function with memory attributes
Summary: [AVR][C++] ICE when using template function with memory attributes
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.5.2
: P5 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2006-03-27 07:19 UTC by Ned Konz
Modified: 2012-03-03 14:08 UTC (History)
3 users (show)

See Also:
Host:
Target: avr-*
Build:
Known to work: 4.7.0
Known to fail: 4.0.2, 4.2.1, 4.5.2, 4.6.1
Last reconfirmed: 2011-06-10 00:00:00


Attachments
Test program (no included files) demonstrating the problem. (685 bytes, text/plain)
2006-03-27 07:26 UTC, Ned Konz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ned Konz 2006-03-27 07:19:43 UTC

This program (which has no included files) causes an ICE and a bus error:

--

typedef unsigned char uint8_t ;
typedef unsigned short uint16_t ;
typedef unsigned long uint32_t ;

#define PROGMEM __attribute__((__progmem__))

template<typename T>
T PROGMEM * rom(const T& init)
{
	static T PROGMEM t = init;
	return &t;
}

struct funny
{
    uint8_t a;
    uint16_t b;
    uint32_t c;
};

uint8_t PROGMEM *rom1 = rom((uint8_t)123);

funny f = { 0xBB, 0xCCCC, 0xDDDDEEEE };
funny PROGMEM *rom2 = rom(f);

int main()
{
    *((volatile uint8_t*)0x55) = *rom1;
    *((volatile uint8_t*)0xAA) = rom2->a;
}

bool __cxa_guard_acquire(uint8_t *gv) { return true; }
bool __cxa_guard_release(uint8_t *gv) { return true; }

--

Environment:
System: Darwin Neds-Mini.local 8.5.0 Darwin Kernel Version 8.5.0: Sun Jan 22 10:38:46 PST 2006; root:xnu-792.6.61.obj~1/RELEASE_PPC Power Macintosh powerpc


	
host: powerpc-apple-darwin8.5.0
build: powerpc-apple-darwin8.5.0
target: avr-unknown-none
configured with: /opt/local/var/db/dports/build/_Users_ned_src_darwinports_dports_cross_avr-gcc/work/gcc-4.0.2/configure --prefix=/opt/local --infodir=/opt/local/share/info --mandir=/opt/local/share/man --target=avr --program-prefix=avr- --with-included-gettext --enable-obsolete --with-gxx-include-dir=/opt/local/avr/include/c++/4.0.2/ --enable-languages=c,c++

How-To-Repeat:

Compile the above program. I used the command line:

avr-g++ -mmcu=atmega128 -c -o romtest2.o romtest2.cpp

and got this:

romtest2.cpp: In function 'T* rom(const T&) [with T = uint8_t]':
romtest2.cpp|21| instantiated from here
romtest2.cpp|10| internal compiler error: Bus error
Comment 1 Ned Konz 2006-03-27 07:26:16 UTC
Created attachment 11133 [details]
Test program (no included files) demonstrating the problem.
Comment 2 Ned Konz 2006-05-01 15:01:22 UTC
Still present in 4.2-20060429 snapshot.
Comment 3 Eric Weddington 2007-07-25 17:42:10 UTC
Confirmed for 4.2.1 on mingw host.

test.cpp: In function 'T* rom(const T&) [with T = uint8_t]':
test.cpp:21:   instantiated from here
test.cpp:10: internal compiler error: Segmentation fault
Comment 4 Georg-Johann Lay 2011-06-10 20:30:12 UTC
Reduded testcase that threds avr-gcc 4.5.2:

template<typename T>
T * rom (const T& init)
{
    static T t = init;
    return &t;
}

int * rom1 = rom(123);

extern bool __cxa_guard_acquire (void*);
Comment 5 Georg-Johann Lay 2012-03-03 14:08:33 UTC
Works in 4.7.0, thus closed