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

            Bug ID: 68022
           Summary: -O2 breaks computed signed integer comparison for AVR
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at tommay dot net
  Target Milestone: ---

Created attachment 36541
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36541&action=edit
Short .c file with the code in question

The attached very short .c file has some code that gets compiled ok with -O0
and -O1 but doesn't execute correctly when compiled with -O2:

(n + 16384) < 0

When n >= 16384 the addition will overflow and the result will be negative, but
the addition is being replaced with a comparison which doesn't detect this
case.

I noticed this behavior in 4.8.2, but it still exists in 6.0.0.

Here is the avr-gcc -v output:

Using built-in specs.
Reading specs from /home/tom/avr-gcc/lib/gcc/avr/6.0.0/device-specs/specs-avr2
COLLECT_GCC=/home/tom/avr-gcc/bin/avr-gcc
Target: avr
Configured with: ../configure --prefix=/home/tom/avr-gcc --target=avr
--enable-languages=c --disable-nls --disable-libssp --with-dwarf2
Thread model: single
gcc version 6.0.0 20151019 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-c'
'-specs=device-specs/specs-avr2'
 /home/tom/avr-gcc/libexec/gcc/avr/6.0.0/cc1 -E -quiet -v bug.c -mn-flash=6
-mskip-bug -O2 -fpch-preprocess -o bug.i
ignoring nonexistent directory
"/home/tom/avr-gcc/lib/gcc/avr/6.0.0/../../../../avr/sys-include"
ignoring nonexistent directory
"/home/tom/avr-gcc/lib/gcc/avr/6.0.0/../../../../avr/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/tom/avr-gcc/lib/gcc/avr/6.0.0/include
 /home/tom/avr-gcc/lib/gcc/avr/6.0.0/include-fixed
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-c'
'-specs=device-specs/specs-avr2'
 /home/tom/avr-gcc/libexec/gcc/avr/6.0.0/cc1 -fpreprocessed bug.i -mn-flash=6
-mskip-bug -quiet -dumpbase bug.c -auxbase bug -O2 -version -o bug.s
GNU C11 (GCC) version 6.0.0 20151019 (experimental) (avr)
        compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C11 (GCC) version 6.0.0 20151019 (experimental) (avr)
        compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 7479be6e1c4383a253f21f5ad7bcd496
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-c'
'-specs=device-specs/specs-avr2'
 as -mmcu=avr2 -o bug.o bug.s
as: unrecognized option '-mmcu=avr2'

Reply via email to