[Bug c++/90886] New: loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
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)
0090 :
  90:   10 92 00 01 sts 0x0100, r1  ; 0x800100 <_edata>

0094 <_exit>:
  94:   f8 94   cli

0096 <__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

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

--- Comment #2 from Joe  ---
Using built-in specs.
Reading specs from /usr/lib/gcc/avr/5.4.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/5.4.0/lto-wrapper
Target: avr
Configured with: ../gcc/configure -v --enable-languages=c,c++ --prefix=/usr/lib
--infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin
--libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib
--enable-long-long --enable-nls --without-included-gettext --disable-libssp
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr CFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong -Wformat ' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2'
CXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong -Wformat ' FCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong' FFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong' GCJFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro'
OBJCFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong -Wformat ' OBJCXXFLAGS='-g -O2
-fdebug-prefix-map=/build/gcc-avr-n0nSsH/gcc-avr-5.4.0+Atmel3.6.0=.
-fstack-protector-strong -Wformat '
Thread model: single
gcc version 5.4.0 (GCC)

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

--- Comment #3 from Joe  ---
Changing i to 127 produces following assembly...

volatile unsigned char x;

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

0090 :
  90:   80 e0   ldi r24, 0x00   ; 0
  92:   80 93 00 01 sts 0x0100, r24 ; 0x800100 <_edata>
  96:   8f 5f   subir24, 0xFF   ; 255
  98:   8f 37   cpi r24, 0x7F   ; 127
  9a:   d1 f3   breq.-12; 0x90 
  9c:   fa cf   rjmp.-12; 0x92 

009e <_exit>:
  9e:   f8 94   cli

00a0 <__stop_program>:
  a0:   ff cf   rjmp.-2 ; 0xa0 <__stop_program>

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

Joe  changed:

   What|Removed |Added

Version|5.4.0   |7.3.0

--- Comment #5 from Joe  ---
Tested with 7.3.0 with same results.

Using built-in specs.
Reading specs from
/home/xxx/avr-tools-test/avr/bin/../lib/gcc/avr/7.3.0/device-specs/specs-avr2
COLLECT_GCC=./avr-g++
COLLECT_LTO_WRAPPER=/home/xxx/avr-tools-test/avr/bin/../libexec/gcc/avr/7.3.0/lto-wrapper
Target: avr
Configured with: ../gcc/configure --enable-fixed-point --enable-languages=c,c++
--prefix=/home/jenkins/workspace/avr-gcc-staging/label/debian7-x86_64/objdir
--disable-nls --disable-libssp --disable-libada --disable-shared
--with-avrlibc=yes --with-dwarf2 --disable-doc --target=avr
Thread model: single
gcc version 7.3.0 (GCC)

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

--- Comment #6 from Joe  ---
Hmmm... Maybe 7.3.0 isn't supported either.

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

Joe  changed:

   What|Removed |Added

Version|7.3.0   |7.4.0

--- Comment #8 from Joe  ---
Here is assembler under 7.4.0...  Segmentation fault with i=128.  Any other
value within the bounds of unsigned char is ok.

i=128
04f0 :
 4f0:   c6 05 1a 0b 20 00 00movb   $0x0,0x200b1a(%rip)# 201011 
 4f7:   66 0f 1f 84 00 00 00nopw   0x0(%rax,%rax,1)
 4fe:   00 00 


i=129
04f0 :
 4f0:   31 c0   xor%eax,%eax
 4f2:   88 05 19 0b 20 00   mov%al,0x200b19(%rip)# 201011 
 4f8:   ff c0   inc%eax
 4fa:   3c 81   cmp$0x81,%al
 4fc:   75 f4   jne4f2 
 4fe:   eb f0   jmp4f0 

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

--- Comment #9 from Joe  ---
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
7.4.0-1ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

[Bug target/90886] loop/while/for problem

2019-06-14 Thread joe at freakyacres dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90886

--- Comment #10 from Joe  ---
probably noticed but code is always "i <" not "i =" as I stated in the previous
comments.