https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89282
Bug ID: 89282 Summary: Garbage arithmetics results in fortran with -O3 and overloaded operators Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: perini at wisc dot edu Target Milestone: --- Created attachment 45654 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45654&action=edit Small test program reproducing the error Hi, I'm getting garbage results out of simple arithmetics (i.e., A minus B) when called in from a derived type, and defined using array-based notation. The problem only appears when compiling using -O3 optimization flag I am not sure whether this issue comes from wrong array bounds checking or its related with the processor's cacheline. It seems that the error appears only for some specific array sizes, i.e., n=5. Anyway, the attached program reproduces the error with gcc/gfortran 6.2.0 on Windows: The program is trying to compute 3.d0 - [(1.d0, j=1,5)], where the data array is contained in a derived type, and the "scalar minus array" operation is performed using an overloaded operator. All array elements from the test should return 2.d0. Compiled using: gfortran -O3 test_gcc_overloaded.f90 it returns: $ a.exe type(t) object <r1>, size=5 x(1) = 2.00000E+00 x(2) = 2.00000E+00 x(3) = 2.00000E+00 x(4) = 2.00000E+00 x(5) = 4.46848-317 type(t) object <r1>, size=6 x(1) = 2.00000E+00 x(2) = 2.00000E+00 x(3) = 2.00000E+00 x(4) = 2.00000E+00 x(5) = 2.00000E+00 x(6) = 2.00000E+00 Thanks, Federico