https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68147
Bug ID: 68147 Summary: Potential incorrect code generation for string self-assignment Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: mar...@mpa-garching.mpg.de Target Milestone: --- Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu Build: x86_64-unknown-linux-gnu Created attachment 36616 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36616&action=edit test case Current gfortran trunk compiles the following testcase into a binary which outputs "a.o", where I would naively expect "a.out". martin@marvin ~ $ gfortran -v -ffree-form test.f Driving: gfortran -v -ffree-form test.f -l gfortran -l m -shared-libgcc Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /home/martin/gcc/configure --disable-multilib --enable-gold --enable-plugins --prefix=/home/martin/ugcc --enable-languages=c++,fortran --enable-target=all --enable-checking=release --disable-bootstrap Thread model: posix gcc version 6.0.0 20150923 (experimental) [trunk revision 3bf38a0:6620841:618c2dcced6864af8a34ed341525c556bb44b375] (GCC) COLLECT_GCC_OPTIONS='-v' '-ffree-form' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/f951 test.f -quiet -dumpbase test.f -mtune=generic -march=x86-64 -auxbase test -version -ffree-form -fintrinsic-modules-path /home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/finclude -o /tmp/cco9Tqxj.s GNU Fortran (GCC) version 6.0.0 20150923 (experimental) [trunk revision 3bf38a0:6620841:618c2dcced6864af8a34ed341525c556bb44b375] (x86_64-pc-linux-gnu) 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=100 --param ggc-min-heapsize=131072 GNU Fortran2008 (GCC) version 6.0.0 20150923 (experimental) [trunk revision 3bf38a0:6620841:618c2dcced6864af8a34ed341525c556bb44b375] (x86_64-pc-linux-gnu) 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=100 --param ggc-min-heapsize=131072 COLLECT_GCC_OPTIONS='-v' '-ffree-form' '-shared-libgcc' '-mtune=generic' '-march=x86-64' as -v --64 -o /tmp/ccwxULsf.o /tmp/cco9Tqxj.s GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.24 Reading specs from /home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../lib64/libgfortran.spec rename spec lib to liborig COLLECT_GCC_OPTIONS='-v' '-ffree-form' '-shared-libgcc' '-mtune=generic' '-march=x86-64' COMPILER_PATH=/home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/:/home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/:/home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/:/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/:/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/ LIBRARY_PATH=/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/:/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-ffree-form' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/collect2 -plugin /home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/liblto_plugin.so -plugin-opt=/home/martin/ugcc/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccCtMKpb.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/crtbegin.o -L/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0 -L/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/../../.. /tmp/ccwxULsf.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /home/martin/ugcc/lib/gcc/x86_64-pc-linux-gnu/6.0.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o martin@marvin ~ $ ./a.out a.o If I remove the if-statement, the code works as expected. Intel ifort 15.0 outputs "a.out". Am I missing some subtleties regarding self-assignment of allocatable strings?