This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR fortran/83998 -- fix dot_product on 0-sized arrays
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: sgk at troutmask dot apl dot washington dot edu, fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 25 Jan 2018 08:37:54 +0100
- Subject: Re: [PATCH] PR fortran/83998 -- fix dot_product on 0-sized arrays
- Authentication-results: sourceware.org; auth=none
- References: <20180125021147.GA52679@troutmask.apl.washington.edu>
Hi Steve,
I have a couple of questions before I have to hurry off to work:
First, why is
@@ -2253,22 +2253,19 @@ gfc_simplify_dim (gfc_expr *x, gfc_expr *y)
gfc_expr*
gfc_simplify_dot_product (gfc_expr *vector_a, gfc_expr *vector_b)
{
+ /* If vector_a is a zero-sized array, the result is 0 for INTEGER,
+ REAL, and COMPLEX types and .false. for LOGICAL. */
+ if (vector_a->shape && mpz_get_si (vector_a->shape[0]) == 0)
+ {
+ if (vector_a->ts.type == BT_LOGICAL)
+ return gfc_get_logical_expr (gfc_default_logical_kind, NULL, false);
+ else
+ return gfc_get_int_expr (gfc_default_integer_kind, NULL, 0);
+ }
in front of
- gfc_expr temp;
-
if (!is_constant_array_expr (vector_a)
|| !is_constant_array_expr (vector_b))
return NULL;
and / or why is the test only done for one variable?
Second, why do you remove this
- temp.value.op.op = INTRINSIC_NONE;
- temp.value.op.op1 = vector_a;
- temp.value.op.op2 = vector_b;
- gfc_type_convert_binary (&temp, 1);
block of code? What would happen for code like
integer, dimension(2), parameter :: a = [ 1,2]
real, dimension(2), parameter :: b = [1.0,2.0]
real, parameter :: c = dot_product(a,b)
?
Regards
Thomas