https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71053
Bug ID: 71053 Summary: [6.1 regression] Volatile read optimized into endless loop Product: gcc Version: 6.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michael at weiser dot dinsnail.net Target Milestone: --- avr-g++ of vanilla gcc 6.1.0 called with avr-g++ -Wall -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -Os t.c -o t.S -S compiles the following code while (((*(volatile unsigned char *)(0x1)) & 1) == 0); into lds r24,1 sbrs r24,0 .L4: rjmp .L4 , producing and endless loop. avr-gcc from the same install as well as avr-gcc and avr-g++ of vanilla gcc 5.3.0 produce: .L2: lds r24,1 sbrs r24,0 rjmp .L2 Preprocessed source: # ~/bin/gcc-6.1.0-avr/bin/avr-g++ -Wall -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -Os t.c -E # 1 "t.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "t.c" int main(void) { while (((*(volatile unsigned char *)(0x1)) & 1) == 0); } Full call and output: # ~/bin/gcc-6.1.0-avr/bin/avr-g++ -Wall -Wextra -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -Os t.c -o t.S -S -v Using built-in specs. Reading specs from /Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/device-specs/specs-avr2 COLLECT_GCC=/Users/michael/bin/gcc-6.1.0-avr/bin/avr-g++ Target: avr Configured with: ../configure --prefix=/Users/michael/bin/gcc-6.1.0-avr --with-gmp=/Users/michael/bin/gcc-6.1.0-avr --with-mpfr=/Users/michael/bin/gcc-6.1.0-avr --with-mpc=/Users/michael/bin/gcc-6.1.0-avr --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 Thread model: single gcc version 6.1.0 (GCC) COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fno-strict-aliasing' '-fwrapv' '-fno-aggressive-loop-optimizations' '-Os' '-o' 't.S' '-S' '-v' '-specs=device-specs/specs-avr2' /Users/michael/bin/gcc-6.1.0-avr/libexec/gcc/avr/6.1.0/cc1plus -quiet -v t.c -mn-flash=6 -mskip-bug -quiet -dumpbase t.c -auxbase-strip t.S -Os -Wall -Wextra -version -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -o t.S -mn-flash=6 -mskip-bug -fno-rtti -fno-enforce-eh-specs -fno-exceptions GNU C++14 (GCC) version 6.1.0 (avr) compiled by GNU C version 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/include/c++/6.1.0" ignoring nonexistent directory "/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/include/c++/6.1.0/avr" ignoring nonexistent directory "/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/include/c++/6.1.0/backward" ignoring nonexistent directory "/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/sys-include" #include "..." search starts here: #include <...> search starts here: /Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/include /Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/include-fixed /Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/include End of search list. GNU C++14 (GCC) version 6.1.0 (avr) compiled by GNU C version 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 7c30ccc7fec31875d3fa3f6ec56cc92b COMPILER_PATH=/Users/michael/bin/gcc-6.1.0-avr/libexec/gcc/avr/6.1.0/:/Users/michael/bin/gcc-6.1.0-avr/libexec/gcc/avr/6.1.0/:/Users/michael/bin/gcc-6.1.0-avr/libexec/gcc/avr/:/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/:/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/:/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/bin/ LIBRARY_PATH=/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/:/Users/michael/bin/gcc-6.1.0-avr/lib/gcc/avr/6.1.0/../../../../avr/lib/ COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fno-strict-aliasing' '-fwrapv' '-fno-aggressive-loop-optimizations' '-Os' '-o' 't.S' '-S' '-v' '-specs=device-specs/specs-avr2'