Summary: | cross-avr/gcc-4.5.3-r2 generates bad code | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Christopher Head <bugs> |
Component: | [OLD] Development | Assignee: | Gentoo Toolchain Maintainers <toolchain> |
Status: | VERIFIED FIXED | ||
Severity: | normal | ||
Priority: | Normal | ||
Version: | unspecified | ||
Hardware: | Other | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Attachments: |
The main.c file that demonstrates the bug
The auxiliary foo.c used in the demonstration test case |
Description
Christopher Head
2012-04-17 04:47:27 UTC
Created attachment 309207 [details]
The main.c file that demonstrates the bug
Created attachment 309209 [details]
The auxiliary foo.c used in the demonstration test case
Note that removing the infinite loop around the code, or replacing -Os with -O0, -O1, -O2, -O3, or even -O4 fixes the bug. For interest, here's a disassembly of the main function via avr-objdump: 000000c2 <main>: c2: 87 e6 ldi r24, 0x67 ; 103 c4: 90 e0 ldi r25, 0x00 ; 0 c6: 90 93 c5 00 sts 0x00C5, r25 ca: 80 93 c4 00 sts 0x00C4, r24 ce: 10 92 c0 00 sts 0x00C0, r1 d2: 80 e4 ldi r24, 0x40 ; 64 d4: 9f e1 ldi r25, 0x1F ; 31 d6: 01 97 sbiw r24, 0x01 ; 1 d8: f1 f7 brne .-4 ; 0xd6 <main+0x14> da: 88 e0 ldi r24, 0x08 ; 8 dc: 80 93 c1 00 sts 0x00C1, r24 e0: 85 e0 ldi r24, 0x05 ; 5 e2: 91 e0 ldi r25, 0x01 ; 1 e4: 90 93 17 01 sts 0x0117, r25 e8: 80 93 16 01 sts 0x0116, r24 ec: 80 e0 ldi r24, 0x00 ; 0 ee: e8 2e mov r14, r24 f0: 81 e0 ldi r24, 0x01 ; 1 f2: f8 2e mov r15, r24 f4: 00 e9 ldi r16, 0x90 ; 144 f6: 11 e0 ldi r17, 0x01 ; 1 f8: 0e 94 54 00 call 0xa8 ; 0xa8 <get_msb> fc: 0e 94 56 00 call 0xac ; 0xac <get_lsb> 100: 00 d0 rcall .+0 ; 0x102 <main+0x40> 102: 00 d0 rcall .+0 ; 0x104 <main+0x42> 104: ed b7 in r30, 0x3d ; 61 106: fe b7 in r31, 0x3e ; 62 108: f2 82 std Z+2, r15 ; 0x02 10a: e1 82 std Z+1, r14 ; 0x01 10c: e0 e0 ldi r30, 0x00 ; 0 10e: ef 01 movw r28, r30 110: 90 e0 ldi r25, 0x00 ; 0 112: 8c 2b or r24, r28 114: 9d 2b or r25, r29 116: ed b7 in r30, 0x3d ; 61 118: fe b7 in r31, 0x3e ; 62 11a: 94 83 std Z+4, r25 ; 0x04 11c: 83 83 std Z+3, r24 ; 0x03 11e: 0e 94 9d 00 call 0x13a ; 0x13a <printf> 122: 0f 90 pop r0 124: 0f 90 pop r0 126: 0f 90 pop r0 128: 0f 90 pop r0 12a: 80 e1 ldi r24, 0x10 ; 16 12c: 97 e2 ldi r25, 0x27 ; 39 12e: f8 01 movw r30, r16 130: 31 97 sbiw r30, 0x01 ; 1 132: f1 f7 brne .-4 ; 0x130 <main+0x6e> 134: 01 97 sbiw r24, 0x01 ; 1 136: d9 f7 brne .-10 ; 0x12e <main+0x6c> 138: df cf rjmp .-66 ; 0xf8 <main+0x36> Observe that get_msb() is called and its return value is completely discarded. sorry, we have no avr experts here, or really anyone skilled in working with code generation. please file these bugs upstream: http://gcc.gnu.org/bugzilla/ feel free to CC us though Are they likely to care about a bug in 4.5? they'll most likely want you to look at 4.7 first. if that's fixed (you can test easily with portage now), then there's nothing to do. if it's a simple fix, we can look at adding to our 4.5 patchset if you like. Actually, this is fixed in 4.5.4 (a "mov r13, r24" instruction was added between the two function calls). |