* [PATCH] PR fortran/83900 -- follow-up to set type
@ 2018-01-20 21:35 Steve Kargl
2018-01-20 23:53 ` Jerry DeLisle
0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2018-01-20 21:35 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 542 bytes --]
The attache patch is a follow-up to my patch for
PR fortran/83900, which removed a bogus assert.
This allowed gfc_simplify_matmul to do its job,
except it did not properly set the type of the
result. The attach fixes that issue.
Regression tested on x86_64-*-freebsd.
OK to commit?
2018-01-20 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/83900
* simplify.c (gfc_simplify_matmul): Set return type correctly.
2018-01-20 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/83900
* gfortran.dg/matmul_18.f90: New test.
--
Steve
[-- Attachment #2: z.diff --]
[-- Type: text/x-diff, Size: 1478 bytes --]
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c (revision 256912)
+++ gcc/fortran/simplify.c (working copy)
@@ -4590,9 +4590,23 @@ gfc_simplify_matmul (gfc_expr *matrix_a, gfc_expr *mat
|| !is_constant_array_expr (matrix_b))
return NULL;
- result = gfc_get_array_expr (matrix_a->ts.type,
- matrix_a->ts.kind,
- &matrix_a->where);
+ /* MATMUL should do mixed-mode arithmetic. Set the result type. */
+ if (matrix_a->ts.type != matrix_b->ts.type)
+ {
+ gfc_expr e;
+ e.expr_type = EXPR_OP;
+ gfc_clear_ts (&e.ts);
+ e.value.op.op = INTRINSIC_NONE;
+ e.value.op.op1 = matrix_a;
+ e.value.op.op2 = matrix_b;
+ gfc_type_convert_binary (&e, 1);
+ result = gfc_get_array_expr (e.ts.type, e.ts.kind, &matrix_a->where);
+ }
+ else
+ {
+ result = gfc_get_array_expr (matrix_a->ts.type, matrix_a->ts.kind,
+ &matrix_a->where);
+ }
if (matrix_a->rank == 1 && matrix_b->rank == 2)
{
Index: gcc/testsuite/gfortran.dg/matmul_18.f90
===================================================================
--- gcc/testsuite/gfortran.dg/matmul_18.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/matmul_18.f90 (working copy)
@@ -0,0 +1,8 @@
+! { dg-do run }
+program p
+ integer, parameter :: a(3,2) = 1
+ real, parameter :: b(2,3) = 2
+ real d(3,3)
+ d = 4
+ if (any(d /= matmul(a,b))) call abort
+end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/83900 -- follow-up to set type
2018-01-20 21:35 [PATCH] PR fortran/83900 -- follow-up to set type Steve Kargl
@ 2018-01-20 23:53 ` Jerry DeLisle
0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2018-01-20 23:53 UTC (permalink / raw)
To: sgk, fortran, gcc-patches
On 01/20/2018 12:19 PM, Steve Kargl wrote:
> The attache patch is a follow-up to my patch for
> PR fortran/83900, which removed a bogus assert.
> This allowed gfc_simplify_matmul to do its job,
> except it did not properly set the type of the
> result. The attach fixes that issue.
>
> Regression tested on x86_64-*-freebsd.
> OK to commit?
>
>
> 2018-01-20 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/83900
> * simplify.c (gfc_simplify_matmul): Set return type correctly.
>
> 2018-01-20 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/83900
> * gfortran.dg/matmul_18.f90: New test.
>
OK, thanks for fix.
Jerry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-20 20:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-20 21:35 [PATCH] PR fortran/83900 -- follow-up to set type Steve Kargl
2018-01-20 23:53 ` Jerry DeLisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).