https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100123
Bug ID: 100123 Summary: -ftree-fre gives incorrect result in subroutine with array declared as length 1 Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: johnnorthall263 at gmail dot com Target Milestone: --- Created attachment 50620 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50620&action=edit source makefile and output from -save-temps When compiling a program I found it works fine on -O0 but has problems with -Og in a number of subroutines. By trial and error I found that adding -fno-tree-fre with -Og restores correct execution. Further investigation of one subroutine enabled the following simple example to demonstrate the problem. The subroutine setmid is designed to set a mid-point grid with option for repeat boundary condition. The correct mid-point y-coords are:- -1.000000 1.000000 3.000000 5.000000 7.000000 9.000000 11.000000 13.000000 but -Og gives:- -1.000000 1.000000 3.000000 5.000000 7.000000 9.000000 11.000000 11.000000 Swapping the order in which the repeat is applied simply shifts the error to the other side of the grid. Bizarrely simply changing the declared dimension of XYM to 2 make it work! First output from "gfortran -c -v -Wall -Wextra -Og -save-temps setmid.f" is:- Using built-in specs. COLLECT_GCC=gfortran OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,ada,go,d --enable-offload-targets=nvptx-none=/usr/nvptx-none,amdgcn-amdhsa=/usr/amdgcn-amdhsa, --without-cuda-driver --enable-checking=release --disable-werror --with-gxx-include-dir=/usr/include/c++/10 --enable-ssp --disable-libssp --disable-libvtv --enable-cet=auto --disable-libcc1 --disable-plugin --with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-libphobos --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-10 --without-system-libunwind --enable-multilib --with-arch-32=x86-64 --with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c] (SUSE Linux) COLLECT_GCC_OPTIONS='-c' '-v' '-Wall' '-Wextra' '-Og' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/lib64/gcc/x86_64-suse-linux/10/f951 setmid.f -ffixed-form -quiet -dumpbase setmid.f -mtune=generic -march=x86-64 -auxbase setmid -Og -Wall -Wextra -version -fintrinsic-modules-path /usr/lib64/gcc/x86_64-suse-linux/10/finclude -o setmid.s GNU Fortran (SUSE Linux) version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c] (x86_64-suse-linux) compiled by GNU C version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c], GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU Fortran2008 (SUSE Linux) version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c] (x86_64-suse-linux) compiled by GNU C version 10.2.1 20200825 [revision c0746a1beb1ba073c7981eb09f55b3d993b32e5c], GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 COLLECT_GCC_OPTIONS='-c' '-v' '-Wall' '-Wextra' '-Og' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/as -v --64 -o setmid.o setmid.s GNU assembler version 2.35.1 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE Leap 15.2) 2.35.1.20201123-lp152.4.6 COMPILER_PATH=/usr/lib64/gcc/x86_64-suse-linux/10/:/usr/lib64/gcc/x86_64-suse-linux/10/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/10/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ LIBRARY_PATH=/usr/lib64/gcc/x86_64-suse-linux/10/:/usr/lib64/gcc/x86_64-suse-linux/10/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/10/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-c' '-v' '-Wall' '-Wextra' '-Og' '-save-temps' '-mtune=generic' '-march=x86-64' I will attach the source file, plus a short main to call it and a print to display the result. Also, I believe the output of -save-temps is desirable to I include that, and also the same for XYM declared as size 2. I'm sure some will decry the differing array declarations in the subroutine and calling program - however this is something I used for many years when I worked on large codes in industry it can be very powerful! Apologies if I've missed something vital - I'm new to this website. John