https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87597
Bug ID: 87597 Summary: wrong result with matmul inlining Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: gallmeister at th dot physik.uni-frankfurt.de Target Milestone: --- Created attachment 44828 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44828&action=edit minimal program Using matmul with a matrix, which is given as a constant, yields a compiler warning and wrong results when compiling with optimization switched on, which uses matmul inlining. the attached minimal program produces folowing output: $ gfortran-8 -O0 -Wall testMatMul.f90 $ ./a.out (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (1.00000000,0.00000000) (2.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (3.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) $ gfortran-8 -O3 -Wall testMatMul.f90 testMatMul.f90:19:0: B = matmul(A,gamma5) Warning: iteration 3 invokes undefined behavior [-Waggressive-loop-optimizations] testMatMul.f90:19:0: B = matmul(A,gamma5) note: within this loop $ ./a.out (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (1.401298464E-45,0.00000000) (2.00000000,0.00000000) (0.00000000,0.00000000) (0.00000000,0.00000000) (8.688050479E-44,6.00000000) (3.00000000,0.00000000) (0.00000000,0.00000000) (2.858648867E-43,3.443410716E-41) (1.681558157E-44,0.00000000)