]> gcc.gnu.org Git - gcc.git/commitdiff
re PR libfortran/22143 (missing kinds 1 and 2 for eoshift and cshift)
authorThomas Koenig <Thomas.Koenig@online.de>
Wed, 10 Aug 2005 20:16:29 +0000 (20:16 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Wed, 10 Aug 2005 20:16:29 +0000 (20:16 +0000)
2005-08-10  Thomas Koenig  <Thomas.Koenig@online.de>

PR libfortran/22143
gfortran.h:  Declare new function gfc_resolve_dim_arg.
resolve.c:  New function gfc_resolve_dim_arg.
iresolve.c (gfc_resolve_all):  Use gfc_resolve_dim_arg.
(gfc_resolve_any):  Likewise.
(gfc_resolve_count):  Likewise.
(gfc_resolve_cshift):  Likewise.  If the kind of shift is less
gfc_default_integer_kind, convert it to default integer type.
(gfc_resolve_eoshift):  Likewise.
(gfc_resolve_maxloc):  Use gfc_resolve_dim_arg.
(gfc_resolve_maxval):  Likewise.
(gfc_resolve_minloc):  Likewise.
(gfc_resolve_minval):  Likewise.
(gfc_resolve_product):  Likewise.
(gfc_resolve_spread):  Likewise.
(gfc_resolve_sum):  Likewise.

2005-08-10  Thomas Koenig  <Thomas.Koenig@online.de>

PR libfortran/22143
gfortran.dg/shift-kind.f90:  New testcase.

From-SVN: r102957

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/iresolve.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/shift-kind.f90 [new file with mode: 0644]

index e19247f9b4fb76dcd0cdeb148f5d2711e3c3f28a..bbbda8df05f429327ec9afbbdcfc1f4a914f32dd 100644 (file)
@@ -1,3 +1,22 @@
+2005-08-10  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       PR libfortran/22143
+       gfortran.h:  Declare new function gfc_resolve_dim_arg.
+       resolve.c:  New function gfc_resolve_dim_arg.
+       iresolve.c (gfc_resolve_all):  Use gfc_resolve_dim_arg.
+       (gfc_resolve_any):  Likewise.
+       (gfc_resolve_count):  Likewise.
+       (gfc_resolve_cshift):  Likewise.  If the kind of shift is less
+       gfc_default_integer_kind, convert it to default integer type.
+       (gfc_resolve_eoshift):  Likewise.
+       (gfc_resolve_maxloc):  Use gfc_resolve_dim_arg.
+       (gfc_resolve_maxval):  Likewise.
+       (gfc_resolve_minloc):  Likewise.
+       (gfc_resolve_minval):  Likewise.
+       (gfc_resolve_product):  Likewise.
+       (gfc_resolve_spread):  Likewise.
+       (gfc_resolve_sum):  Likewise.
+
 2005-08-09  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        * check.c (gfc_check_ttynam_sub, gfc_check_isatty): Add check
index ac271054b056c705e74b9d3f4c8954dc721a1d29..cb68ad49cb2e7cd906e380f942cf7926e1ad3881 100644 (file)
@@ -1779,6 +1779,7 @@ int gfc_pure (gfc_symbol *);
 int gfc_elemental (gfc_symbol *);
 try gfc_resolve_iterator (gfc_iterator *, bool);
 try gfc_resolve_index (gfc_expr *, int);
+try gfc_resolve_dim_arg (gfc_expr *);
 
 /* array.c */
 void gfc_free_array_spec (gfc_array_spec *);
index a6f7f27776e586c8c55149489308368e158999d2..ef43946a55b571836234cc044227fde5a197de0b 100644 (file)
@@ -129,7 +129,7 @@ gfc_resolve_all (gfc_expr * f, gfc_expr * mask, gfc_expr * dim)
 
   if (dim != NULL)
     {
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
       f->rank = mask->rank - 1;
       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
     }
@@ -167,7 +167,7 @@ gfc_resolve_any (gfc_expr * f, gfc_expr * mask, gfc_expr * dim)
 
   if (dim != NULL)
     {
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
       f->rank = mask->rank - 1;
       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
     }
@@ -359,7 +359,7 @@ gfc_resolve_count (gfc_expr * f, gfc_expr * mask, gfc_expr * dim)
   if (dim != NULL)
     {
       f->rank = mask->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
     }
 
@@ -385,9 +385,19 @@ gfc_resolve_cshift (gfc_expr * f, gfc_expr * array,
   else
     n = 0;
 
+  /* Convert shift to at least gfc_default_integer_kind, so we don't need
+     kind=1 and kind=2 versions of the library functions.  */
+  if (shift->ts.kind < gfc_default_integer_kind)
+    {
+      gfc_typespec ts;
+      ts.type = BT_INTEGER;
+      ts.kind = gfc_default_integer_kind;
+      gfc_convert_type_warn (shift, &ts, 2, 0);
+    }
+
   if (dim != NULL)
     {
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
       /* Convert dim to shift's kind, so we don't need so many variations.  */
       if (dim->ts.kind != shift->ts.kind)
        gfc_convert_type_warn (dim, &shift->ts, 2, 0);
@@ -474,10 +484,23 @@ gfc_resolve_eoshift (gfc_expr * f, gfc_expr * array,
   if (boundary && boundary->rank > 0)
     n = n | 2;
 
-  /* Convert dim to the same type as shift, so we don't need quite so many
-     variations.  */
-  if (dim != NULL && dim->ts.kind != shift->ts.kind)
-    gfc_convert_type_warn (dim, &shift->ts, 2, 0);
+  /* Convert shift to at least gfc_default_integer_kind, so we don't need
+     kind=1 and kind=2 versions of the library functions.  */
+  if (shift->ts.kind < gfc_default_integer_kind)
+    {
+      gfc_typespec ts;
+      ts.type = BT_INTEGER;
+      ts.kind = gfc_default_integer_kind;
+      gfc_convert_type_warn (shift, &ts, 2, 0);
+    }
+
+  if (dim != NULL)
+    {
+      gfc_resolve_dim_arg (dim);
+      /* Convert dim to shift's kind, so we don't need so many variations.  */
+      if (dim->ts.kind != shift->ts.kind)
+       gfc_convert_type_warn (dim, &shift->ts, 2, 0);
+    }
 
   f->value.function.name =
     gfc_get_string (PREFIX("eoshift%d_%d"), n, shift->ts.kind);
@@ -921,7 +944,7 @@ gfc_resolve_maxloc (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   else
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   name = mask ? "mmaxloc" : "maxloc";
@@ -940,7 +963,7 @@ gfc_resolve_maxval (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   if (dim != NULL)
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   f->value.function.name =
@@ -982,7 +1005,7 @@ gfc_resolve_minloc (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   else
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   name = mask ? "mminloc" : "minloc";
@@ -1001,7 +1024,7 @@ gfc_resolve_minval (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   if (dim != NULL)
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   f->value.function.name =
@@ -1098,7 +1121,7 @@ gfc_resolve_product (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   if (dim != NULL)
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   f->value.function.name =
@@ -1341,7 +1364,7 @@ gfc_resolve_spread (gfc_expr * f, gfc_expr * source,
   f->rank = source->rank + 1;
   f->value.function.name = PREFIX("spread");
 
-  gfc_resolve_index (dim, 1);
+  gfc_resolve_dim_arg (dim);
   gfc_resolve_index (ncopies, 1);
 }
 
@@ -1388,7 +1411,7 @@ gfc_resolve_sum (gfc_expr * f, gfc_expr * array, gfc_expr * dim,
   if (dim != NULL)
     {
       f->rank = array->rank - 1;
-      gfc_resolve_index (dim, 1);
+      gfc_resolve_dim_arg (dim);
     }
 
   f->value.function.name =
index d855a7fd7b4248861e1391ca146d92c6a798b3eb..ace59588991f6826c9ab4f0e41ddfd311a4729c8 100644 (file)
@@ -1828,6 +1828,40 @@ gfc_resolve_index (gfc_expr * index, int check_scalar)
   return SUCCESS;
 }
 
+/* Resolve a dim argument to an intrinsic function.  */
+
+try
+gfc_resolve_dim_arg (gfc_expr *dim)
+{
+  if (dim == NULL)
+    return SUCCESS;
+
+  if (gfc_resolve_expr (dim) == FAILURE)
+    return FAILURE;
+
+  if (dim->rank != 0)
+    {
+      gfc_error ("Argument dim at %L must be scalar", &dim->where);
+      return FAILURE;
+  
+    }
+  if (dim->ts.type != BT_INTEGER)
+    {
+      gfc_error ("Argument dim at %L must be of INTEGER type", &dim->where);
+      return FAILURE;
+    }
+  if (dim->ts.kind != gfc_index_integer_kind)
+    {
+      gfc_typespec ts;
+
+      ts.type = BT_INTEGER;
+      ts.kind = gfc_index_integer_kind;
+
+      gfc_convert_type_warn (dim, &ts, 2, 0);
+    }
+
+  return SUCCESS;
+}
 
 /* Given an expression that contains array references, update those array
    references to point to the right array specifications.  While this is
index effde2ea49ef4d45ad4db2a67f338d8d435f76ff..7d4d8f2860def58a56917e7dd981ef0849a181fd 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-10  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       PR libfortran/22143
+       gfortran.dg/shift-kind.f90:  New testcase.
+
 2005-08-10  Richard Sandiford  <richard@codesourcery.com>
 
        * gcc.dg/arm-eabi1.c: Test aeabi_idiv, __aeabi_uidiv, __aeabi_uread4,
diff --git a/gcc/testsuite/gfortran.dg/shift-kind.f90 b/gcc/testsuite/gfortran.dg/shift-kind.f90
new file mode 100644 (file)
index 0000000..70d8748
--- /dev/null
@@ -0,0 +1,37 @@
+! { dg-do compile }
+! PR 22143:  We didn' have shift arguments to eoshift of kind=1
+!            and kind=2.
+program main
+  implicit none
+  integer, dimension (3,3) :: a, b, w
+  integer(kind=2), dimension (3) :: sh2
+  integer(kind=1), dimension (3) :: sh1
+  integer, dimension(3) :: bo
+  integer :: i,j
+
+  a = reshape((/(i,i=1,9)/),shape(a))
+  sh1 = (/ -3, -1, 3 /)
+  sh2 = (/ -3, -1, 3 /)
+  bo = (/-999, -99, -9 /)
+  b = cshift(a, shift=sh1)
+  call foo(b)
+  b = cshift(a, shift=sh2)
+  call foo(b)
+
+  b = eoshift(a, shift=sh1)
+  call foo(b)
+  b = eoshift(a, shift=sh1, boundary=bo)
+  call foo(b)
+  b = eoshift(a, shift=sh2)
+  call foo(b)
+  b = eoshift(a, shift=sh2, boundary=bo)
+  call foo(b)
+
+end program main
+
+subroutine foo(b)
+  ! Do nothing but confuse the optimizer into not removing the
+  ! function calls.
+  integer, dimension(3,3) :: b
+end subroutine foo
+
This page took 0.082147 seconds and 5 git commands to generate.