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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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 ` pinskia at gcc dot gnu.org
  2012-02-22  4:29 ` gpib at rickyrockrat dot net
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-21  3:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-21 03:42:56 UTC ---
Can you provide the preprocessed source?  Add -save-temps and attach the .i
file?
Also can you run "avr-gcc -v" and provide the output of that?


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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gpib at rickyrockrat dot net @ 2012-02-22  4:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

--- Comment #2 from rickyrockrat <gpib at rickyrockrat dot net> 2012-02-22 04:27:01 UTC ---
Created attachment 26722
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26722
Intermediate file

Intermediate file, as requested. Changed name to bug52301.


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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gpib at rickyrockrat dot net @ 2012-02-22  4:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

--- Comment #3 from rickyrockrat <gpib at rickyrockrat dot net> 2012-02-22 04:29:21 UTC ---
Created attachment 26723
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26723
Script to compile bug52301.c

Script to run avr-gcc on the subject file.


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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: gpib at rickyrockrat dot net @ 2012-02-22  4:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

--- Comment #4 from rickyrockrat <gpib at rickyrockrat dot net> 2012-02-22 04:31:11 UTC ---
Created attachment 26724
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26724
Assembly generated using script and original source

Resulting assembly from recently supplied files - just to make sure the problem
is still there.


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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-22  4:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-22 04:33:50 UTC ---
This is invalid as GCC has no way to know that stat can change.  Mark stat as
volatile and then GCC will know it can change.


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

* [Bug target/52301] avr-gcc 4.6.2  produces NOP loop in simple while statement
  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
                   ` (4 preceding siblings ...)
  2012-02-22  4:42 ` pinskia at gcc dot gnu.org
@ 2012-02-22  5:32 ` gpib at rickyrockrat dot net
  5 siblings, 0 replies; 7+ messages in thread
From: gpib at rickyrockrat dot net @ 2012-02-22  5:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52301

--- Comment #6 from rickyrockrat <gpib at rickyrockrat dot net> 2012-02-22 05:05:56 UTC ---
I guess I'm a little confused. How can GCC NOT know it can change? 
Any RAM location not only can but usually does change. It seems that volatile
should be the norm.

Whatever. I'll just set all my data types to be volatile, since this doesn't
make sense to me.

Thanks.


^ 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).