Re: Ping: [patch, fortran] KIND arguments for MINLOC and MAXLOC

2017-11-03 Thread Steve Kargl
On Fri, Nov 03, 2017 at 10:04:21PM +0100, Thomas Koenig wrote:
> Am 28.10.2017 um 23:57 schrieb Thomas Koenig:
> 
> Ping?
> 

Ok.  (I thought you had already committed this.)

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Ping: [patch, fortran] KIND arguments for MINLOC and MAXLOC

2017-11-03 Thread Thomas Koenig

Am 28.10.2017 um 23:57 schrieb Thomas Koenig:

Ping?


the attached patch allows KIND arguments to MINLOC and MAXLOC.
There was a bit of a choice to make here. Originally, I wanted to
run the calculation using index_type only and convert to another
integer kind if that was required. This ran into the issue that
bounds checking fails for this approach if there is a conversion
( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82660 ), and I
got regressions for that.

On the other hand, I wanted to avoid adding kind=1 and kind=2 versions
to the library. This approach had been rejected some time ago,
in 2009.

So, I chose a third path by using only pre-existing library
functions for kind=4, kind=8 and kind=16 and by doing a conversion
if the user specified kind=1 or kind=2.

This introduces a bug (array bounds violation not caught) if the user

- specifies bounds checking
- choses kind=1 or kind=2 for minloc or maxloc (it escapes me why
   anybody would want to do that)
- uses an array as return value whose bounds cannot be determined
   at compile-time, and gets the dimension of that array wrong

Frankly, if anybody would do this, the expression "deserves to lose"
comes to mind.

This would not be a regression, because kind=1 and kind=2 are
not supported at the moment.  This bug would be fixed together
with 82660.

Regression-tested. OK for trunk?

Regards

 Thomas

2017-10-28  Thomas Koenig  

     PR fortran/29600
     * gfortran.h (gfc_check_f): Replace fm3l with fm4l.
     * intrinsic.h (gfc_resolve_maxloc): Add gfc_expr * to argument
     list in protoytpe.
     (gfc_resolve_minloc): Likewise.
     * check.c (gfc_check_minloc_maxloc): Handle kind argument.
     * intrinsic.c (add_sym_3_ml): Rename to
     (add_sym_4_ml): and handle kind argument.
     (add_function): Replace add_sym_3ml with add_sym_4ml and add
     extra arguments for maxloc and minloc.
     (check_specific): Change use of check.f3ml with check.f4ml.
     * iresolve.c (gfc_resolve_maxloc): Handle kind argument. If
     the kind is smaller than the smallest library version available,
     use gfc_default_integer_kind and convert afterwards.
     (gfc_resolve_minloc): Likewise.

2017-10-28  Thomas Koenig  

     PR fortran/29600
     * gfortran.dg/minmaxloc_8.f90: New test.




[patch, fortran] KIND arguments for MINLOC and MAXLOC

2017-10-28 Thread Thomas Koenig

Hello world,

the attached patch allows KIND arguments to MINLOC and MAXLOC.
There was a bit of a choice to make here. Originally, I wanted to
run the calculation using index_type only and convert to another
integer kind if that was required. This ran into the issue that
bounds checking fails for this approach if there is a conversion
( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82660 ), and I
got regressions for that.

On the other hand, I wanted to avoid adding kind=1 and kind=2 versions
to the library. This approach had been rejected some time ago,
in 2009.

So, I chose a third path by using only pre-existing library
functions for kind=4, kind=8 and kind=16 and by doing a conversion
if the user specified kind=1 or kind=2.

This introduces a bug (array bounds violation not caught) if the user

- specifies bounds checking
- choses kind=1 or kind=2 for minloc or maxloc (it escapes me why
  anybody would want to do that)
- uses an array as return value whose bounds cannot be determined
  at compile-time, and gets the dimension of that array wrong

Frankly, if anybody would do this, the expression "deserves to lose"
comes to mind.

This would not be a regression, because kind=1 and kind=2 are
not supported at the moment.  This bug would be fixed together
with 82660.

Regression-tested. OK for trunk?

Regards

Thomas

2017-10-28  Thomas Koenig  

PR fortran/29600
* gfortran.h (gfc_check_f): Replace fm3l with fm4l.
* intrinsic.h (gfc_resolve_maxloc): Add gfc_expr * to argument
list in protoytpe.
(gfc_resolve_minloc): Likewise.
* check.c (gfc_check_minloc_maxloc): Handle kind argument.
* intrinsic.c (add_sym_3_ml): Rename to
(add_sym_4_ml): and handle kind argument.
(add_function): Replace add_sym_3ml with add_sym_4ml and add
extra arguments for maxloc and minloc.
(check_specific): Change use of check.f3ml with check.f4ml.
* iresolve.c (gfc_resolve_maxloc): Handle kind argument. If
the kind is smaller than the smallest library version available,
use gfc_default_integer_kind and convert afterwards.
(gfc_resolve_minloc): Likewise.

2017-10-28  Thomas Koenig  

PR fortran/29600
* gfortran.dg/minmaxloc_8.f90: New test.
Index: gfortran.h
===
--- gfortran.h	(Revision 253768)
+++ gfortran.h	(Arbeitskopie)
@@ -1989,7 +1989,7 @@ gfc_intrinsic_arg;
argument lists of intrinsic functions. fX with X an integer refer
to check functions of intrinsics with X arguments. f1m is used for
the MAX and MIN intrinsics which can have an arbitrary number of
-   arguments, f3ml is used for the MINLOC and MAXLOC intrinsics as
+   arguments, f4ml is used for the MINLOC and MAXLOC intrinsics as
these have special semantics.  */
 
 typedef union
@@ -1999,7 +1999,7 @@ typedef union
   bool (*f1m)(gfc_actual_arglist *);
   bool (*f2)(struct gfc_expr *, struct gfc_expr *);
   bool (*f3)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *);
-  bool (*f3ml)(gfc_actual_arglist *);
+  bool (*f4ml)(gfc_actual_arglist *);
   bool (*f3red)(gfc_actual_arglist *);
   bool (*f4)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
 	struct gfc_expr *);
Index: intrinsic.h
===
--- intrinsic.h	(Revision 253768)
+++ intrinsic.h	(Arbeitskopie)
@@ -537,7 +537,7 @@ void gfc_resolve_logical (gfc_expr *, gfc_expr *,
 void gfc_resolve_lstat (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_matmul (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_max (gfc_expr *, gfc_actual_arglist *);
-void gfc_resolve_maxloc (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
+void gfc_resolve_maxloc (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_maxval (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_mclock (gfc_expr *);
 void gfc_resolve_mclock8 (gfc_expr *);
@@ -545,7 +545,7 @@ void gfc_resolve_mask (gfc_expr *, gfc_expr *, gfc
 void gfc_resolve_merge (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_merge_bits (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_min (gfc_expr *, gfc_actual_arglist *);
-void gfc_resolve_minloc (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
+void gfc_resolve_minloc (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_minval (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_mod (gfc_expr *, gfc_expr *, gfc_expr *);
 void gfc_resolve_modulo (gfc_expr *, gfc_expr *, gfc_expr *);
Index: check.c
===
--- check.c	(Revision 253768)
+++ check.c	(Arbeitskopie)
@@ -3179,7 +3179,7 @@ gfc_check_matmul (gfc_expr *matrix_a, gfc_expr *ma
 bool
 gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
 {
-  gfc_expr *a, *m,