http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51862
Bug #: 51862 Summary: Over optimization for assignments to char[] defined inner than used Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: nar...@airemix.jp GCC 4.7 optimization out assignments to char[] if the char[] is defined inner than it is used. The too simplified case is like following (func() changes buf and enough small to inline): char *res; if (bool) { char buf[4]; func(buf); res = buf; } fprintf(stderr, "'%s'\n", res); = gcc47 -v Using built-in specs. COLLECT_GCC=gcc47 COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/lto-wrapper Target: x86_64-portbld-freebsd9.0 Configured with: ./../gcc-4.7-20111217/configure --disable-nls --enable-languages=c,c++,fortran --libdir=/usr/local/lib/gcc47 --libexecdir=/usr/local/libexec/gcc47 --program-suffix=47 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc47/include/c++/ --with-ld=/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --disable-libgcj --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc47 --build=x86_64-portbld-freebsd9.0 Thread model: posix gcc version 4.7.0 20111217 (experimental) (FreeBSD Ports Collection) = the complete command line that triggers the bug % gcc47 -O2 g.c&&./a.out # type "\u0061" \u0061 1 '' The resulted output must be following and works with -O0: 1 'a????' = the compiler output (error messages, warnings, etc.) Using built-in specs. COLLECT_GCC=gcc47 COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/lto-wrapper Target: x86_64-portbld-freebsd9.0 Configured with: ./../gcc-4.7-20111217/configure --disable-nls --enable-languages=c,c++,fortran --li bdir=/usr/local/lib/gcc47 --libexecdir=/usr/local/libexec/gcc47 --program-suffix=47 --with-as=/usr/l ocal/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc47/include/c++/ --with-ld =/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-pkgversion='FreeBSD Ports Collection' -- with-system-zlib --disable-libgcj --prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/i nfo/gcc47 --build=x86_64-portbld-freebsd9.0 Thread model: posix gcc version 4.7.0 20111217 (experimental) (FreeBSD Ports Collection) COLLECT_GCC_OPTIONS='-O2' '-save-temps' '-v' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/cc1 -E -quiet -v g.c -mtune=generic -m arch=x86-64 -O2 -fpch-preprocess -o g.i ignoring nonexistent directory "/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../../.. /../x86_64-portbld-freebsd9.0/include" #include "..." search starts here: #include <...> search starts here: /usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/include /usr/local/include /usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-O2' '-save-temps' '-v' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/cc1 -fpreprocessed g.i -quiet -dumpbase g.c -mtune=generic -march=x86-64 -auxbase g -O2 -version -o g.s GNU C (FreeBSD Ports Collection) version 4.7.0 20111217 (experimental) (x86_64-portbld-freebsd9.0) compiled by GNU C version 4.7.0 20111217 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 GNU C (FreeBSD Ports Collection) version 4.7.0 20111217 (experimental) (x86_64-portbld-freebsd9.0) compiled by GNU C version 4.7.0 20111217 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 7130d1c9d6c474bcedaf92254d46803f COLLECT_GCC_OPTIONS='-O2' '-save-temps' '-v' '-mtune=generic' '-march=x86-64' /usr/local/bin/as -v -o g.o g.s GNU assembler version 2.22 (x86_64-portbld-freebsd9.0) using BFD version (GNU Binutils) 2.22 COMPILER_PATH=/usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/:/usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/:/usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/:/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/:/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/:/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../../../../x86_64-portbld-freebsd9.0/bin/ LIBRARY_PATH=/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/:/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../../../../x86_64-portbld-freebsd9.0/lib/:/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-O2' '-save-temps' '-v' '-mtune=generic' '-march=x86-64' /usr/local/libexec/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/collect2 --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0 -L/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../../../../x86_64-portbld-freebsd9.0/lib -L/usr/local/lib/gcc47/gcc/x86_64-portbld-freebsd9.0/4.7.0/../../.. g.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o GNU ld (GNU Binutils) 2.22 Supported emulations: elf_x86_64_fbsd elf_i386_fbsd elf_x86_64 elf_i386 elf_l1om elf_l1om_fbsd elf_k1om elf_k1om_fbsd = the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command attached.