Bug 36313 - [F03] {MIN,MAX}{LOC,VAL} should accept character arguments
Summary: [F03] {MIN,MAX}{LOC,VAL} should accept character arguments
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: rejects-valid
: 38951 43006 (view as bug list)
Depends on: 82856
Blocks: F2003
  Show dependency treegraph
 
Reported: 2008-05-23 12:46 UTC by Francois-Xavier Coudert
Modified: 2017-12-03 21:39 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-11-05 00:00:00


Attachments
patch doing maxloc0* at least. (3.93 KB, patch)
2011-08-26 00:06 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2008-05-23 12:46:51 UTC
Starting with Fortran 2003, MINVAL, MAXVAL, MINLOC and MAXLOC accept character arguments. (Also, when implementing this, please remember to support wide characters!)
Comment 1 Thomas Koenig 2008-05-25 20:03:26 UTC
This should be fun :-)
Comment 2 Thomas Koenig 2008-06-04 19:06:14 UTC
No time for now (Real Time is catching up with me big time).

Unassigning (for now).
Comment 3 Daniel Franke 2009-01-03 23:02:57 UTC
Patch at
    http://gcc.gnu.org/ml/fortran/2009-01/msg00010.html
impliments simplifiers for MINVAL/MAXVAL and character arguments.
Comment 4 Daniel Franke 2009-01-24 09:51:13 UTC
*** Bug 38951 has been marked as a duplicate of this bug. ***
Comment 5 Daniel Franke 2010-02-09 13:10:14 UTC
*** Bug 43006 has been marked as a duplicate of this bug. ***
Comment 6 Thomas Koenig 2011-08-26 00:06:48 UTC
Created attachment 25108 [details]
patch doing maxloc0* at least.

Still missing: A lot, like minloc*, maxloc1*, etc.

Also: Don't forget the inlined versions, that should be fun too.
Comment 7 Bil Kleb 2014-12-09 18:26:57 UTC
Hi,

Regression or documentation skew?

Per 4.4.5 documentation, viz.,

  https://gcc.gnu.org/onlinedocs/gcc-4.4.5/gfortran/MINLOC.html

the MINLOC ARRAY argument could be INTEGER, REAL, or CHARACTER;
but as of 4.9.1, this is no longer the case?

$ cat > test_char_maxloc.f90 << EOF
program test_f2003_minloc_char
  character(20), dimension(5) :: strings
  data strings / 'close', 'closer', 'find_my_index', 'far', 'farther' /
  print*,sum(minloc(strings,strings=='find_my_index'))
end program
EOF

$ gfortran --version | head -1
GNU Fortran (Homebrew gcc 4.9.1) 4.9.1

$ gfortran test_char_maxloc.f90
test_char_maxloc.f90:4.20:

  print*,sum(minloc(strings,strings=='find_my_index'))
                    1
Error: 'array' argument of 'minloc' intrinsic at (1) must be INTEGER or REAL

And wasn't the case at 4.4.7:

$ gfortran --version | head -1
GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)

$ gfortran test_char_maxloc.f90 
test_char_maxloc.f90:4.20:

  print*,sum(minloc(strings,strings=='find_my_index'))
                    1
Error: 'array' argument of 'minloc' intrinsic at (1) must be INTEGER or REAL
Comment 8 Dominique d'Humieres 2014-12-09 18:57:30 UTC
> Regression or documentation skew?
>
> Per 4.4.5 documentation, viz.,

This has been changed starting at 4.5.4 up to trunk (5.0):

ARRAY	Shall be an array of type INTEGER or REAL. 

Note that I did not have the patience to check all the revisions in between for the four combinations of {MIN,MAX}{LOC,VAL} (if you want to do it, be my guest!-).

AFAICT these F2003 intrinsics have never been implemented. If you have the man power to do it, please feel free to contribute.
Comment 9 Thomas Koenig 2017-11-05 21:58:33 UTC
Let's see if we can make some progress here.
Comment 10 Thomas Koenig 2017-11-05 23:07:38 UTC
Hope PR 82856 gets resolved soon - hard to do anything with
generated files without a working automake :-(
Comment 11 Thomas Koenig 2017-11-22 18:08:38 UTC
Author: tkoenig
Date: Wed Nov 22 18:08:07 2017
New Revision: 255070

URL: https://gcc.gnu.org/viewcvs?rev=255070&root=gcc&view=rev
Log:
2017-11-22  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* Makefile.am: Add i_maxloc0s_c, i_maxloc1s_c, i_maxloc2s_c,
	i_minloc0s_c, i_minloc1s_c and i_minloc2s_c.
	* Makefile.in: Regenerated.
        * generated/maxloc0_16_s1.c: New file.
        * generated/maxloc0_16_s4.c: New file.
        * generated/maxloc0_4_s1.c: New file.
        * generated/maxloc0_4_s4.c: New file.
        * generated/maxloc0_8_s1.c: New file.
        * generated/maxloc0_8_s4.c: New file.
        * generated/maxloc1_16_s1.c: New file.
        * generated/maxloc1_16_s4.c: New file.
        * generated/maxloc1_4_s1.c: New file.
        * generated/maxloc1_4_s4.c: New file.
        * generated/maxloc1_8_s1.c: New file.
        * generated/maxloc1_8_s4.c: New file.
        * generated/maxloc2_16_s1.c: New file.
        * generated/maxloc2_16_s4.c: New file.
        * generated/maxloc2_4_s1.c: New file.
        * generated/maxloc2_4_s4.c: New file.
        * generated/maxloc2_8_s1.c: New file.
        * generated/maxloc2_8_s4.c: New file.
        * generated/minloc0_16_s1.c: New file.
        * generated/minloc0_16_s4.c: New file.
        * generated/minloc0_4_s1.c: New file.
        * generated/minloc0_4_s4.c: New file.
        * generated/minloc0_8_s1.c: New file.
        * generated/minloc0_8_s4.c: New file.
        * generated/minloc1_16_s1.c: New file.
        * generated/minloc1_16_s4.c: New file.
        * generated/minloc1_4_s1.c: New file.
        * generated/minloc1_4_s4.c: New file.
        * generated/minloc1_8_s1.c: New file.
        * generated/minloc1_8_s4.c: New file.
        * generated/minloc2_16_s1.c: New file.
        * generated/minloc2_16_s4.c: New file.
        * generated/minloc2_4_s1.c: New file.
        * generated/minloc2_4_s4.c: New file.
        * generated/minloc2_8_s1.c: New file.
        * generated/minloc2_8_s4.c: New file.
        * m4/iforeach-s.m4: New file.
        * m4/ifunction-s.m4: New file.
        * m4/maxloc0s.m4: New file.
        * m4/maxloc1s.m4: New file.
        * m4/maxloc2s.m4: New file.
        * m4/minloc0s.m4: New file.
        * m4/minloc1s.m4: New file.
        * m4/minloc2s.m4: New file.
	* gfortran.map: Add new functions.
	* libgfortran.h: Add gfc_array_s1 and gfc_array_s4.

2017-11-22  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* check.c (int_or_real_or_char_check_f2003): New function.
	* iresolve.c (gfc_resolve_maxloc): Add number "2" for
	character arguments and rank-zero return value.
	(gfc_resolve_minloc): Likewise.
	* trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc): Handle case of
	character arguments and rank-zero return value by removing
	unneeded arguments and calling the library function.

2017-11-22  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* gfortran.dg/maxloc_string_1.f90: New test.
	* gfortran.dg/minloc_string_1.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/maxloc_string_1.f90
    trunk/gcc/testsuite/gfortran.dg/minloc_string_1.f90
    trunk/libgfortran/generated/maxloc0_16_s1.c
    trunk/libgfortran/generated/maxloc0_16_s4.c
    trunk/libgfortran/generated/maxloc0_4_s1.c
    trunk/libgfortran/generated/maxloc0_4_s4.c
    trunk/libgfortran/generated/maxloc0_8_s1.c
    trunk/libgfortran/generated/maxloc0_8_s4.c
    trunk/libgfortran/generated/maxloc1_16_s1.c
    trunk/libgfortran/generated/maxloc1_16_s4.c
    trunk/libgfortran/generated/maxloc1_4_s1.c
    trunk/libgfortran/generated/maxloc1_4_s4.c
    trunk/libgfortran/generated/maxloc1_8_s1.c
    trunk/libgfortran/generated/maxloc1_8_s4.c
    trunk/libgfortran/generated/maxloc2_16_s1.c
    trunk/libgfortran/generated/maxloc2_16_s4.c
    trunk/libgfortran/generated/maxloc2_4_s1.c
    trunk/libgfortran/generated/maxloc2_4_s4.c
    trunk/libgfortran/generated/maxloc2_8_s1.c
    trunk/libgfortran/generated/maxloc2_8_s4.c
    trunk/libgfortran/generated/minloc0_16_s1.c
    trunk/libgfortran/generated/minloc0_16_s4.c
    trunk/libgfortran/generated/minloc0_4_s1.c
    trunk/libgfortran/generated/minloc0_4_s4.c
    trunk/libgfortran/generated/minloc0_8_s1.c
    trunk/libgfortran/generated/minloc0_8_s4.c
    trunk/libgfortran/generated/minloc1_16_s1.c
    trunk/libgfortran/generated/minloc1_16_s4.c
    trunk/libgfortran/generated/minloc1_4_s1.c
    trunk/libgfortran/generated/minloc1_4_s4.c
    trunk/libgfortran/generated/minloc1_8_s1.c
    trunk/libgfortran/generated/minloc1_8_s4.c
    trunk/libgfortran/generated/minloc2_16_s1.c
    trunk/libgfortran/generated/minloc2_16_s4.c
    trunk/libgfortran/generated/minloc2_4_s1.c
    trunk/libgfortran/generated/minloc2_4_s4.c
    trunk/libgfortran/generated/minloc2_8_s1.c
    trunk/libgfortran/generated/minloc2_8_s4.c
    trunk/libgfortran/m4/iforeach-s.m4
    trunk/libgfortran/m4/ifunction-s.m4
    trunk/libgfortran/m4/maxloc0s.m4
    trunk/libgfortran/m4/maxloc1s.m4
    trunk/libgfortran/m4/maxloc2s.m4
    trunk/libgfortran/m4/minloc0s.m4
    trunk/libgfortran/m4/minloc1s.m4
    trunk/libgfortran/m4/minloc2s.m4
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/Makefile.am
    trunk/libgfortran/Makefile.in
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/libgfortran.h
    trunk/libgfortran/m4/ifunction.m4
    trunk/libgfortran/m4/iparm.m4
Comment 12 Thomas Koenig 2017-11-23 17:52:37 UTC
Author: tkoenig
Date: Thu Nov 23 17:52:05 2017
New Revision: 255109

URL: https://gcc.gnu.org/viewcvs?rev=255109&root=gcc&view=rev
Log:
2017-11-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* m4/maxloc2s.m4: Replace int for character length by
	gfc_charlen_type.
	* m4/minloc2s.m4: Likewise.
	* generated./maxloc2_16_s1.c: Regenerated.
	* generated./maxloc2_16_s4.c: Regenerated.
	* generated./maxloc2_4_s1.c: Regenerated.
	* generated./maxloc2_4_s4.c: Regenerated.
	* generated./maxloc2_8_s1.c: Regenerated.
	* generated./maxloc2_8_s4.c: Regenerated.
	* generated./minloc2_16_s1.c: Regenerated.
	* generated./minloc2_16_s4.c: Regenerated.
	* generated./minloc2_4_s1.c: Regenerated.
	* generated./minloc2_4_s4.c: Regenerated.
	* generated./minloc2_8_s1.c: Regenerated.
	* generated./minloc2_8_s4.c: Regenerated.


Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/generated/maxloc2_16_s1.c
    trunk/libgfortran/generated/maxloc2_16_s4.c
    trunk/libgfortran/generated/maxloc2_4_s1.c
    trunk/libgfortran/generated/maxloc2_4_s4.c
    trunk/libgfortran/generated/maxloc2_8_s1.c
    trunk/libgfortran/generated/maxloc2_8_s4.c
    trunk/libgfortran/generated/minloc2_16_s1.c
    trunk/libgfortran/generated/minloc2_16_s4.c
    trunk/libgfortran/generated/minloc2_4_s1.c
    trunk/libgfortran/generated/minloc2_4_s4.c
    trunk/libgfortran/generated/minloc2_8_s1.c
    trunk/libgfortran/generated/minloc2_8_s4.c
    trunk/libgfortran/m4/maxloc2s.m4
    trunk/libgfortran/m4/minloc2s.m4
Comment 13 Janne Blomqvist 2017-11-24 08:51:47 UTC
Author: jb
Date: Fri Nov 24 08:51:15 2017
New Revision: 255135

URL: https://gcc.gnu.org/viewcvs?rev=255135&root=gcc&view=rev
Log:
PR 36313 Replace int with gfc_charlen_type, take 3

Still some prototypes that didn't match the implementation.

2017-11-24  Janne Blomqvist  <jb@gcc.gnu.org>
        PR fortran/36313
        * m4/maxloc2s.m4: Replace int with gfc_charlen_type, take 3.
        * m4/minloc2s.m4: Likewise.
        * generated/maxloc2_16_s1.c: Regenerated.
        * generated/maxloc2_16_s4.c: Regenerated.
        * generated/maxloc2_4_s1.c: Regenerated.
        * generated/maxloc2_4_s4.c: Regenerated.
        * generated/maxloc2_8_s1.c: Regenerated.
        * generated/maxloc2_8_s4.c: Regenerated.
        * generated/minloc2_16_s1.c: Regenerated.
        * generated/minloc2_16_s4.c: Regenerated.
        * generated/minloc2_4_s1.c: Regenerated.
        * generated/minloc2_4_s4.c: Regenerated.
        * generated/minloc2_8_s1.c: Regenerated.
        * generated/minloc2_8_s4.c: Regenerated.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/generated/maxloc2_16_s1.c
    trunk/libgfortran/generated/maxloc2_16_s4.c
    trunk/libgfortran/generated/maxloc2_4_s1.c
    trunk/libgfortran/generated/maxloc2_4_s4.c
    trunk/libgfortran/generated/maxloc2_8_s1.c
    trunk/libgfortran/generated/maxloc2_8_s4.c
    trunk/libgfortran/generated/minloc2_16_s1.c
    trunk/libgfortran/generated/minloc2_16_s4.c
    trunk/libgfortran/generated/minloc2_4_s1.c
    trunk/libgfortran/generated/minloc2_4_s4.c
    trunk/libgfortran/generated/minloc2_8_s1.c
    trunk/libgfortran/generated/minloc2_8_s4.c
    trunk/libgfortran/m4/maxloc2s.m4
    trunk/libgfortran/m4/minloc2s.m4
Comment 14 Thomas Koenig 2017-12-03 20:14:37 UTC
Author: tkoenig
Date: Sun Dec  3 20:14:05 2017
New Revision: 255367

URL: https://gcc.gnu.org/viewcvs?rev=255367&root=gcc&view=rev
Log:
2017-12-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* check.c (gfc_check_minval_maxval): Use
	int_orLreal_or_char_check_f2003 for array argument.
	* iresolve.c (gfc_resolve_maxval): Insert number in
	function name for character arguments.
	(gfc_resolve_minval): Likewise.
	* trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc):
	Fix comment.
	(gfc_conv_intrinsic_minmaxval): Resort arguments and call library
	function if dealing with a character function.

2017-12-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* Makefile.am: Add new files for character-valued
	maxval and minval.
	* Makefile.in: Regenerated.
	* gfortran.map: Add new functions.
	* m4/iforeach-s2.m4: New file.
	* m4/ifunction-s2.m4: New file.
	* m4/iparm.m4: Add intitval for minval and maxval.
	* m4/maxval0s.m4: New file.
	* m4/maxval1s.m4: New file.
	* m4/minval0s.m4: New file.
	* m4/minval1s.m4: New file.
        * generated/maxval0_s1.c: New file.
        * generated/maxval0_s4.c: New file.
        * generated/maxval1_s1.c: New file.
        * generated/maxval1_s4.c: New file.
        * generated/minval0_s1.c: New file.
        * generated/minval0_s4.c: New file.
        * generated/minval1_s1.c: New file.
        * generated/minval1_s4.c: New file.

2017-12-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/36313
	* gfortran.dg/maxval_char_1.f90: New test.
	* gfortran.dg/maxval_char_2.f90: New test.
	* gfortran.dg/maxval_char_3.f90: New test.
	* gfortran.dg/maxval_char_4.f90: New test.
	* gfortran.dg/minval_char_1.f90: New test.
	* gfortran.dg/minval_char_2.f90: New test.
	* gfortran.dg/minval_char_3.f90: New test.
	* gfortran.dg/minval_char_4.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/maxval_char_1.f90
    trunk/gcc/testsuite/gfortran.dg/maxval_char_2.f90
    trunk/gcc/testsuite/gfortran.dg/maxval_char_3.f90
    trunk/gcc/testsuite/gfortran.dg/maxval_char_4.f90
    trunk/gcc/testsuite/gfortran.dg/minval_char_1.f90
    trunk/gcc/testsuite/gfortran.dg/minval_char_2.f90
    trunk/gcc/testsuite/gfortran.dg/minval_char_3.f90
    trunk/gcc/testsuite/gfortran.dg/minval_char_4.f90
    trunk/libgfortran/generated/maxval0_s1.c
    trunk/libgfortran/generated/maxval0_s4.c
    trunk/libgfortran/generated/maxval1_s1.c
    trunk/libgfortran/generated/maxval1_s4.c
    trunk/libgfortran/generated/minval0_s1.c
    trunk/libgfortran/generated/minval0_s4.c
    trunk/libgfortran/generated/minval1_s1.c
    trunk/libgfortran/generated/minval1_s4.c
    trunk/libgfortran/m4/iforeach-s2.m4
    trunk/libgfortran/m4/ifunction-s2.m4
    trunk/libgfortran/m4/maxval0s.m4
    trunk/libgfortran/m4/maxval1s.m4
    trunk/libgfortran/m4/minval0s.m4
    trunk/libgfortran/m4/minval1s.m4
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/Makefile.am
    trunk/libgfortran/Makefile.in
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/m4/iparm.m4
Comment 15 Thomas Koenig 2017-12-03 21:39:09 UTC
Fixed on trunk, closing.
Comment 16 Thomas Koenig 2017-12-03 21:39:31 UTC
Really closing.