public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52301] New: avr-gcc 4.6.2  produces NOP loop in simple while statement
@ 2012-02-17 21:30 gpib at rickyrockrat dot net
  2012-02-21  3:45 ` [Bug target/52301] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gpib at rickyrockrat dot net @ 2012-02-17 21:30 UTC (permalink / raw)
  To: gcc-bugs

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
\fGAS 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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-02-22  5:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-17 21:30 [Bug c/52301] New: avr-gcc 4.6.2 produces NOP loop in simple while statement gpib at rickyrockrat dot net
2012-02-21  3:45 ` [Bug target/52301] " pinskia at gcc dot gnu.org
2012-02-22  4:29 ` gpib at rickyrockrat dot net
2012-02-22  4:31 ` gpib at rickyrockrat dot net
2012-02-22  4:34 ` gpib at rickyrockrat dot net
2012-02-22  4:42 ` pinskia at gcc dot gnu.org
2012-02-22  5:32 ` gpib at rickyrockrat dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).