[Bug fortran/69360] loop optimization produces invalid code when a common array has dimension 1 in some files

2021-04-22 Thread johnnorthall263 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69360

--- Comment #6 from John Northall  ---
It's deliberate!  I think with this level of understanding of fortran use
in the real world commercial compilers have a bright future!  If it works
with dimension set to 2 (whatever the background true value) then it must
be easy to make it do so with dimension 1?
Cheers, John

On Sat, Apr 17, 2021 at 2:48 AM kargl at gcc dot gnu.org <
gcc-bugzi...@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69360
>
> kargl at gcc dot gnu.org changed:
>
>What|Removed |Added
>
> 
>  CC||kargl at gcc dot gnu.org
>
> --- Comment #5 from kargl at gcc dot gnu.org ---
> (In reply to John Northall from comment #4)
> > O dear - that makes gfortran unusable on many existing codes - not really
> > satisfactory is it?
> > John
> >
>
>
> gfortran is fairly good at finding bugs in a user's program if
> one asks gfortran to do so.  Add -fcheck=all to your options.
>
> At line 21 of file setmid.f
> Fortran runtime error: Index '155' of dimension 1 of array 'xym' above
> upper
> bound of 1
>
> Now, you have an opportunity to fix your code.
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.

[Bug fortran/69360] loop optimization produces invalid code when a common array has dimension 1 in some files

2021-04-16 Thread johnnorthall263 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69360

--- Comment #4 from John Northall  ---
O dear - that makes gfortran unusable on many existing codes - not really
satisfactory is it?
John

On Fri, Apr 16, 2021 at 11:08 PM pinskia at gcc dot gnu.org <
gcc-bugzi...@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69360
>
> Andrew Pinski  changed:
>
>What|Removed |Added
>
> 
>  CC||johnnorthall263 at gmail
> dot com
>
> --- Comment #3 from Andrew Pinski  ---
> *** Bug 100123 has been marked as a duplicate of this bug. ***
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.

[Bug fortran/100123] New: -ftree-fre gives incorrect result in subroutine with array declared as length 1

2021-04-16 Thread johnnorthall263 at gmail dot com via Gcc-bugs
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=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.00  1.00  3.00  5.00  7.00  9.00 11.00
13.00
but -Og gives:-
 -1.00  1.00  3.00  5.00  7.00  9.00 11.00
11.00
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