[Bug c/97276] New: A whole if-block is ignored by avr-gcc 9.3.0
tre at gmx dot de
gcc-bugzilla@gcc.gnu.org
Sat Oct 3 00:33:30 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97276
Bug ID: 97276
Summary: A whole if-block is ignored by avr-gcc 9.3.0
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tre at gmx dot de
Target Milestone: ---
Created attachment 49304
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49304&action=edit
Identical example compiled with avr-gcc 7.5.0 and avr-gcc 9.3.0
Hi,
I have a weird avr-gcc bug that costed me some months to find as I couldn't
believe it's the compiler actually. So, I use the avr-gcc 9.3.0 on Mac OS
10.15.7 to compile a little function used for PWM fading of LEDs. The function
update_pwm_timeslots()
contains an if-block (ll.119-125):
if (last_brightness < 181 && j >= 181)
{
/* middle interrupt: top 65k */
slot->top = 0xfe00;
slot->mask = ~mask;
++slot;
}
This block seems to be completely ignored by the compilers equal or newer than
avr-gcc 8.3.0, i.e. the block doesn't appear in the assembly. Here is the list
of compilers I tested:
avr-gcc 4.9.4 (working)
avr-gcc 5.5.0 (working)
avr-gcc 6.5.0 (working)
avr-gcc 7.5.0 (working)
avr-gcc 8.4.0 (broken)
avr-gcc 9.3.0 (broken)
The diff between the assemblies (pwm.s) perfectly reveals that the if-block is
skipped by avr-gcc 9.3.0:
277c274
< mov r15, r31
---
> mov r9, r31
278a276,305
> j = scalevalue(j, global_pwm.dim);
> mov r18, r22
> ldi r19, 0x00 ; 0
> rjmp .+0 ; 0x1b6 <update_pwm_timeslots+0x1b6> 1b4: R_AVR_13_PCREL .text+0x222
> if (j == 255) break;
> cpi r23, 0xFF ; 255
> brne .+0 ; 0x1ba <update_pwm_timeslots+0x1ba> 1b8: R_AVR_7_PCREL .text+0x1bc
> rjmp .+0 ; 0x1bc <update_pwm_timeslots+0x1bc> 1ba: R_AVR_13_PCREL .text+0x270
> if (last_brightness < 181 && j >= 181)
> ldi r30, 0xB4 ; 180
> cp r30, r11
> brcc .+0 ; 0x1c2 <update_pwm_timeslots+0x1c2> 1c0: R_AVR_7_PCREL .text+0x1c4
> rjmp .+0 ; 0x1c4 <update_pwm_timeslots+0x1c4> 1c2: R_AVR_13_PCREL .text+0x24c
> cpi r23, 0xB5 ; 181
> brcc .+0 ; 0x1c8 <update_pwm_timeslots+0x1c8> 1c6: R_AVR_7_PCREL .text+0x1ca
> rjmp .+0 ; 0x1ca <update_pwm_timeslots+0x1ca> 1c8: R_AVR_13_PCREL .text+0x24c
> slot->top = 0xfe00;
> st X+, r8
> st X, r9
> sbiw r26, 0x01 ; 1
> slot->mask = ~mask;
> movw r30, r24
> com r30
> com r31
> adiw r26, 0x02 ; 2
> st X+, r30
> st X, r31
> sbiw r26, 0x03 ; 3
> ++slot;
> adiw r26, 0x04 ; 4
I attached the example with a Makefile adapted to avr-gcc 7.5.0 and avr-gcc
9.3.0 and the corresponding assembly outputs (pwm.s) and all intermediate
files. The README.txt contains the individual log outputs.
More information about the Gcc-bugs
mailing list