https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

            Bug ID: 90886
           Summary: loop/while/for problem
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joe at freakyacres dot com
  Target Milestone: ---

I apologize because this all got a little bit above my head.  But the following
code only runs the "for" loop once.  

volatile unsigned char x;

int main() {
  while (1) {
    for (unsigned char i = 0 ; i < 128 ; i++) {
      x = i;
    }
  }
}


Apparently compiles to...

$ avr-g++ -Os -mmcu=atmega328p main.cpp -o main.elf
$ avr-objdump --demangle -d main.elf
(other code omitted)
00000090 <main>:
  90:   10 92 00 01     sts     0x0100, r1      ; 0x800100 <_edata>

00000094 <_exit>:
  94:   f8 94           cli

00000096 <__stop_program>:
  96:   ff cf           rjmp    .-2             ; 0x96 <__stop_program>
$ avr-g++ --version


Replacing the for loop 128 with any other value fixes the problem.


Much work was done at the github link below where minds much more advanced than
my own researched and confirmed what was happening.



https://github.com/arduino/Arduino/issues/8973

https://forum.arduino.cc/index.php?topic=621017.0

Reply via email to