This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/52301] New: avr-gcc 4.6.2 produces NOP loop in simple while statement
- From: "gpib at rickyrockrat dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 17 Feb 2012 21:27:54 +0000
- Subject: [Bug c/52301] New: avr-gcc 4.6.2 produces NOP loop in simple while statement
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301
Bug #: 52301
Summary: avr-gcc 4.6.2 produces NOP loop in simple while
statement
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: gpib@rickyrockrat.net
Created attachment 26696
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26696
Problem source code
The while loop produces a jump to L3 which is = L5. The code immediately
following jumps to L5, which does nothing but loop.
In a main function, I have a loop like so:
while(1) {
if (stat &DAT_READY) {
cli();
stat=0;
sei();
}
Which produces this asm code:
89 .L6:
64:spi_irq_echo.c **** sei(); // Enable global interrupts
90 .loc 1 64 0
91 /* #APP */
92 ; 64 "spi_irq_echo.c" 1
93 0016 7894 sei
94 ; 0 "" 2
65:spi_irq_echo.c **** while(1) {
66:spi_irq_echo.c **** if (stat &DAT_READY) {
95 .loc 1 66 0
96 /* #NOAPP */
97 0018 8091 0000 lds r24,stat
98 001c 80FF sbrs r24,0
99 001e 00C0 rjmp .L3
67:spi_irq_echo.c **** cli();
100 .loc 1 67 0
101 /* #APP */
102 ; 67 "spi_irq_echo.c" 1
103 0020 F894 cli
104 ; 0 "" 2
GAS LISTING /tmp/ccXonaYI.s page 4
68:spi_irq_echo.c **** stat=0;
105 .loc 1 68 0
106 /* #NOAPP */
107 0022 1092 0000 sts stat,__zero_reg__
108 0026 00C0 rjmp .L6
109 .L3:
110 .L5:
111 0028 00C0 rjmp .L5
112 .cfi_endproc
If add a global that is u8 x, and modify the loop as follows:
while(1) {
x=1;
if (stat &DAT_READY) {
cli();
stat=0;
sei();
}
It produces the correct assembler.
Command line is:
avr-gcc -Os -Wa,-a=spi_irq_echo.x -fno-zero-initialized-in-bss -Wall -g
-mmcu=attiny26 -mshort-calls -mtiny-stack -I ../../common -I. -c -o
spi_irq_echo.o spi_irq_echo.c
Complete file is attached.