[Bug fortran/86837] Optimization breaks an unformatted read with implicit loop on Mac OS X

2018-08-03 Thread tmp147 at neuf dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86837

--- Comment #2 from Pascal  ---
(In reply to Harald Anlauf from comment #1)
> If I add "-fno-frontend-optimize", the test case runs properly.
> 
> There have been other cases where front-end optimization fell over
> nested loops.  You were lucky to find another one that's not yet covered.

This option will help, I can live with the other optimizations only.

Hope you can fix the problem I was so lucky to find ;>)

[Bug fortran/86837] New: Optimization breaks an unformatted read with implicit loop on Mac OS X

2018-08-02 Thread tmp147 at neuf dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86837

Bug ID: 86837
   Summary: Optimization breaks an unformatted read with implicit
loop on Mac OS X
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: tmp147 at neuf dot fr
  Target Milestone: ---

Created attachment 44497
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44497=edit
minimal standalone program showing the problem

The attached code compiles and runs fine with -O0, but gives an inappropriate
warning and crashes at least with -O1 and -O2. In close variants, I've also had
no message when compiling, no error at runtime, but no read either.

OS : Mac OS X High Sierra 10.13.6
Version: gfortran 8.2.0 installed by an up-to-date brew
 same problem with gcc@5, gcc@6, gcc@7

The results are ok at least on some linux, tested on
   - CentOS 6.5 / gcc 4.4.7 20120313 (Red Hat 4.4.7-4)
   - Mageia 4   / gcc 4.8.2
   - Mageia 6   / gcc 5.4 (or 5.5, not at work anymore...)


 Run ok
gfortran -O0 -Wall -Wextra -fcheck=all read_loop.f90 -o read_loop &&
./read_loop
  1.
 11. 12.
 21. 22. 23. 24.

 Full array two_d:
  1. 11. 21.
 -9. 12. 22.
 -9. -9. 23.
 -9. -9. 24.


 Run ko (only changed -O0 to -O1)
gfortran -O1 -Wall -Wextra -fcheck=all read_loop.f90 -o read_loop &&
./read_loop
read_loop.f90:40:0:

 read(10) ((two_d(i,j), i=1,nvalues(j)), j=1,3)

Warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
At line 40 of file read_loop.f90
Fortran runtime error: Index '0' of dimension 1 of array 'nvalues' below lower
bound of 1

Error termination. Backtrace:
#0  0x1006e61ac
#1  0x1006e6e45
#2  0x1006e71ea
#3  0x1006debfe
#4  0x1006dec1d