From 86e03ef911346681949ae6812d64569008936fb4 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sun, 27 Aug 2017 08:01:25 +0000 Subject: [PATCH] re PR fortran/81974 (ICE verify_gimple failed type mismatch in binary expression) 2017-08-27 Thomas Koenig PR fortran/81974 * frontend-passes (inline_matumul_assign): Explicity set typespec for call to CONJG. 2017-08-27 Thomas Koenig PR fortran/81974 * gfortran.dg/inline_matmul_19.f90: New test. From-SVN: r251368 --- gcc/fortran/ChangeLog | 6 ++++ gcc/fortran/frontend-passes.c | 21 +++++++++--- gcc/testsuite/ChangeLog | 5 +++ .../gfortran.dg/inline_matmul_19.f90 | 34 +++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/inline_matmul_19.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1b2b4c93753..61f4a20b5fb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-08-27 Thomas Koenig + + PR fortran/81974 + * frontend-passes (inline_matumul_assign): Explicity + set typespec for call to CONJG. + 2017-08-21 Jerry DeLisle PR fortran/81296 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 7a3d0272d47..2631849743d 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -3837,14 +3837,25 @@ inline_matmul_assign (gfc_code **c, int *walk_subtrees, gcc_unreachable(); } + /* Build the conjg call around the variables. Set the typespec manually + because gfc_build_intrinsic_call sometimes gets this wrong. */ if (conjg_a) - ascalar = gfc_build_intrinsic_call (ns, GFC_ISYM_CONJG, "conjg", - matrix_a->where, 1, ascalar); + { + gfc_typespec ts; + ts = matrix_a->ts; + ascalar = gfc_build_intrinsic_call (ns, GFC_ISYM_CONJG, "conjg", + matrix_a->where, 1, ascalar); + ascalar->ts = ts; + } if (conjg_b) - bscalar = gfc_build_intrinsic_call (ns, GFC_ISYM_CONJG, "conjg", - matrix_b->where, 1, bscalar); - + { + gfc_typespec ts; + ts = matrix_b->ts; + bscalar = gfc_build_intrinsic_call (ns, GFC_ISYM_CONJG, "conjg", + matrix_b->where, 1, bscalar); + bscalar->ts = ts; + } /* First loop comes after the zero assignment. */ assign_zero->next = do_1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70218ab223b..f80aaf2fd9c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-27 Thomas Koenig + + PR fortran/81974 + * gfortran.dg/inline_matmul_19.f90: New test. + 2017-08-25 Steven Munroe * gcc.target/powerpc/m128-check.h: New file. diff --git a/gcc/testsuite/gfortran.dg/inline_matmul_19.f90 b/gcc/testsuite/gfortran.dg/inline_matmul_19.f90 new file mode 100644 index 00000000000..62856a7de44 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/inline_matmul_19.f90 @@ -0,0 +1,34 @@ + ! { dg-do run } + ! { dg-options "-ffrontend-optimize" } + ! PR 81974 - this used to cause an ICE. + + implicit none + COMPLEX(kind=kind(0d0)), DIMENSION(3, 3) :: R + REAL(kind=kind(0d0)), DIMENSION(3, 3) :: M,a,b + complex(8), dimension(3,3) :: res, c + integer :: i, j, k + c = 0 + call random_number(m) + call random_number(a) + call random_number(b) + r = cmplx(a, b, 8) + do k=1,3 + do j=1,3 + do i=1,3 + c(k,j) = c(k,j) + conjg(r(i,k)) * m(i,j) + end do + end do + end do + res = MATMUL(TRANSPOSE(CONJG(R)), M) + if (any(abs(res-c) >= 1e-6)) call abort + c = 0 + do k=1,3 + do j=1,3 + do i=1,3 + c(i,k) = c(i,k) + m(i,j) * conjg(r(k,j)) + end do + end do + end do + res = matmul(m, transpose(conjg(r))) + if (any(abs(res-c) >= 1e-6)) call abort + END -- 2.30.2