This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/60840] New: avr-g++: Incorrect avr assembler code generation
- From: "dragontears at bk dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 14 Apr 2014 16:00:30 +0000
- Subject: [Bug c++/60840] New: avr-g++: Incorrect avr assembler code generation
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60840
Bug ID: 60840
Summary: avr-g++: Incorrect avr assembler code generation
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dragontears at bk dot ru
avr-g++ produces incorrect assembler output. Sample code:
#include <stdint.h>
#include <avr/io.h>
struct test
{
uint8_t shift;
};
volatile const test* smth = 0;
int main(void)
{
while(1)
{
if(smth == 0)
continue;
PORTB |= (1 << smth->shift);
}
}
Generated assembler output contains a single check if smth == 0 and an endless
loop right after that. RJMP contains incorrect address:
...
0000007c <main>:
7c: 21 e0 ldi r18, 0x01 ; 1
7e: 30 e0 ldi r19, 0x00 ; 0
80: e0 91 60 00 lds r30, 0x0060
84: f0 91 61 00 lds r31, 0x0061
88: 30 97 sbiw r30, 0x00 ; 0
8a: 09 f4 brne .+2 ; 0x8e <main+0x12>
8c: ff cf rjmp .-2 ; 0x8c <main+0x10> //HERE IT IS
...
But if you put a simple NOP instruction before "continue", you get correct
output:
...
0000007c <main>:
7c: 21 e0 ldi r18, 0x01 ; 1
7e: 30 e0 ldi r19, 0x00 ; 0
80: e0 91 60 00 lds r30, 0x0060
84: f0 91 61 00 lds r31, 0x0061
88: 30 97 sbiw r30, 0x00 ; 0
8a: 11 f4 brne .+4 ; 0x90 <main+0x14>
8c: 00 00 nop
8e: f8 cf rjmp .-16 ; 0x80 <main+0x4> //THE POINTER
IS GOOD NOW
...
Seems that this bug is not dependent on compiler options. Probably, avr-gcc has
this bug too (haven't checked that).