Hi, I have problem using gcc4.7.2 with -fno-strict-aliasing switch along with -O2. This combination makes boost::spirit::classic::assign_a (boost1.48) not working properly. In undermentioned example value 101101 is not assigned to 'variable'. It worked fine with gcc3.4.3, and it works ok with gcc4.7.2 -O2 without -fno-strict-aliasing. //---------- start ------------ #include <boost/spirit/include/classic.hpp> #include <boost/spirit/include/phoenix1.hpp> #include <stdio.h> int main() { int variable = 123; using namespace boost::spirit::classic; using namespace phoenix; rule<> testRule // = eps_p [ var( variable ) = 101101 ] //that one works fine with -O2 -fno-strict-aliasing = eps_p [ assign_a( variable, 101101 ) ] //this one gives rubbish with -O2 -fno-strict-aliasing ; parse_info<> result = parse( "bla bla", testRule ); if ( result.hit ) printf( "%d\n", variable ); return 0; } //---------- end ------------ gcc details: COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../gcc-4.7.2/configure --prefix=/usr/local/gcc-4.7.2 --enable-languages=c,c++ --with-gmp=/usr/local/gcc-4.7.2 --with-ppl=/usr/local/gcc-4.7.2 --with-cloog=/usr/local/gcc-4.7.2 Thread model: posix gcc version 4.7.2 (GCC) Whole comilation log (g++ -v -save-temps -O2 -fno-strict-aliasing -pthread -I/usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include -L/usr/local/gcc-4.7.2/STLport-5.2.1/lib main.cpp -o test): Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../gcc-4.7.2/configure --prefix=/usr/local/gcc-4.7.2 --enable-languages=c,c++ --with-gmp=/usr/local/gcc-4.7.2 --with-ppl=/usr/local/gcc-4.7.2 --with-cloog=/usr/local/gcc-4.7.2 Thread model: posix gcc version 4.7.2 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-fno-strict-aliasing' '-pthread' '-I' '/usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include' '-L/usr/local/gcc-4.7.2/STLport-5.2.1/lib' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro' /home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/cc1plus -E -quiet -v -I /usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include -iprefix /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/ -D_GNU_SOURCE -D_REENTRANT main.cpp -mtune=generic -march=pentiumpro -fno-strict-aliasing -O2 -fpch-preprocess -o main.ii ignoring nonexistent directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/include" ignoring duplicate directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2" ignoring duplicate directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/i686-pc-linux-gnu" ignoring duplicate directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/backward" ignoring duplicate directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/include" ignoring duplicate directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/include-fixed" ignoring nonexistent directory "/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2 /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/i686-pc-linux-gnu /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../include/c++/4.7.2/backward /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/include /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/include-fixed /usr/local/include /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/../../include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-fno-strict-aliasing' '-pthread' '-I' '/usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include' '-L/usr/local/gcc-4.7.2/STLport-5.2.1/lib' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro' /home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/cc1plus -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -march=pentiumpro -auxbase main -O2 -version -fno-strict-aliasing -o main.s GNU C++ (GCC) version 4.7.2 (i686-pc-linux-gnu) compiled by GNU C version 4.7.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.7.2 (i686-pc-linux-gnu) compiled by GNU C version 4.7.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 18f6eb2e590887d903a9b1835552c140 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-fno-strict-aliasing' '-pthread' '-I' '/usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include' '-L/usr/local/gcc-4.7.2/STLport-5.2.1/lib' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro' /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/bin/as -v -I /usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include --32 -o main.o main.s GNU assembler version 2.21.1 (i686-pc-linux-gnu) using BFD version (GNU Binutils) 2.21.1 COMPILER_PATH=/home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/:/home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/:/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/bin/ LIBRARY_PATH=/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/:/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/:/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/lib/:/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-fno-strict-aliasing' '-pthread' '-I' '/usr/local/gcc-4.7.2/STLport-5.2.1/boost-1.48/include' '-L/usr/local/gcc-4.7.2/STLport-5.2.1/lib' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro' /home/build/storage/toolchain/gcc-4.7.2/bin/../libexec/gcc/i686-pc-linux-gnu/4.7.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test /usr/lib/crt1.o /usr/lib/crti.o /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/crtbegin.o -L/usr/local/gcc-4.7.2/STLport-5.2.1/lib -L/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2 -L/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc -L/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/lib -L/home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/../../.. main.o -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /home/build/storage/toolchain/gcc-4.7.2/bin/../lib/gcc/i686-pc-linux-gnu/4.7.2/crtend.o /usr/lib/crtn.o
Created attachment 29700 [details] preprocessor output + log + test case
Also broken on trunk with plain -O2. Thus very likely triggered by changes of inline decisions. Works with -O and -O2 -fno-inline on trunk.
I can confirm this with gcc 4.7.3 -O2 Assign_a is not working within boost spirit classic on ubuntu 13.04.
Confirming for 4.9.1, I found no combination of options to make it work, but in some cases it actually corrupted the value of the variable.
Created attachment 37607 [details] reduced testcase Here's a somewhat reduced testcase that fails with gcc-5 and gcc-6. I haven't looked deeper yet. markus@x4 tmp % clang++ -std=c++14 -O2 boost.ii && ./a.out markus@x4 tmp % clang++ -std=c++14 -O3 boost.ii && ./a.out markus@x4 tmp % clang++ -std=c++14 -O0 boost.ii && ./a.out markus@x4 tmp % icpc -std=c++14 -O0 boost.ii && ./a.out markus@x4 tmp % icpc -std=c++14 -O2 boost.ii && ./a.out markus@x4 tmp % icpc -std=c++14 -O3 boost.ii && ./a.out markus@x4 tmp % g++ -std=c++14 -O1 boost.ii && ./a.out markus@x4 tmp % g++ -std=c++14 -O2 boost.ii && ./a.out [1] 12466 abort ./a.out
This is not a GCC bug. The examples above have use after scope bug. Look at `assign_a` documentation https://www.boost.org/doc/libs/1_69_0/libs/spirit/classic/doc/predefined_actors.html it takes a value by reference (by const reference actually).
As explained in comment #6 this is not a bug.
(In reply to Nikita Kniazev from comment #6) > This is not a GCC bug. The examples above have use after scope bug. > Look at `assign_a` documentation > https://www.boost.org/doc/libs/1_69_0/libs/spirit/classic/doc/ > predefined_actors.html it takes a value by reference (by const reference > actually). How does example use "after scope bug" as 'variable' is all the time in the same scope as assign_a ?
Gushhh my fault, VALUE not VARIABLE :) all it is clear, sorry.