Bug 54613 - [F03] [F08] Add FINDLOC plus support MAXLOC/MINLOC with KIND=/BACK=
Summary: [F03] [F08] Add FINDLOC plus support MAXLOC/MINLOC with KIND=/BACK=
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on: 54633
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-18 07:40 UTC by Tobias Burnus
Modified: 2016-11-18 17:59 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-09-18 00:00:00


Attachments
Very preliminary patch for MAXLOC/MINLOC (3.67 KB, text/plain)
2012-09-18 09:17 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-09-18 07:40:45 UTC
Fortran 2003 (cf. PR 29600) added KIND= to MINLOC/MAXLOC, Fortran 2008 added BACK=. Additionally, Fortran 2008 added FINDLOC with a similar syntax.

See also James' post in "binary data" https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/GpaACNKn0Ds

"As can be seen from the commented out code, gfortran does not yet
 implement the BACK= argument for the MAXLOC and MINLOC intrinsics,
 doesn't yet implement MAXLOC, MAXVAL, MINLOC, MINVAL for constant
 expressions and doesn't implement FINDLOC at all."

See also his comments in https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/5eAz5ns6AG0



The first step is to implement the run-time version, i.e. extending MINLOC/MAXLOC and adding FINDLOC.

(trans-intrinsic.c version, frontend-optimization.c and the library version, possibly such that one doesn't cause an explosion of the intrinsics, e.g. only returning default + index-type? If so, one needs to have a RANGE_REF copy for the array results - and for the MASK argument.)


As a next step, one has to think of the compile-time simplification of {MIN,MAX}{VAL,LOC},FINDLOC.
Comment 1 Tobias Burnus 2012-09-18 09:17:25 UTC
Created attachment 28211 [details]
Very preliminary patch for MAXLOC/MINLOC

Very preliminary patch for the MAXLOC/MINLOC support; i.e. documentation and resolving plus identifying the spot (and needed changes) for trans-intrinsic.c. Implementing the latter and in particular the library support are still lacking. (As is FINDLOC.)
Comment 2 Dominique d'Humieres 2012-09-18 09:25:36 UTC
This PR seems related to pr25104 and pr45689.
Comment 3 Dominique d'Humieres 2016-11-18 17:59:47 UTC
At https://gcc.gnu.org/ml/fortran/2016-11/msg00179.html I wrote 

pr54613, sixth and eighth tests,

Actually the tests were extracted from https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/5eAz5ns6AG0, i.e.,

module m2procs 
   implicit none 
   contains 
      recursive function fun(depth) result(r) 
         integer r 
         integer depth 
         integer x(minval([1],mask=[.TRUE.])) 
         integer y 
         save 

         x = 0 
         if(depth > 0) y = fun(depth-1) 
         x = x+1 
         r = x(1) 
      end function fun 
end module m2procs 

program minval2 
   use m2procs 
   implicit none 

   write(*,*) fun(1) 
end program minval2 

and

[Book15] f90/bug% diff -up pr54613_5.f90 pr54613_7.f90
--- pr54613_5.f90	2012-09-18 10:43:48.000000000 +0200
+++ pr54613_7.f90	2012-09-18 10:44:56.000000000 +0200
@@ -4,7 +4,7 @@ module m2procs 
       recursive function fun(depth) result(r) 
          integer r 
          integer depth 
-         integer x(minval([1],mask=[.TRUE.])) 
+         integer x(sum(minloc([1]))) 
          integer y 
          save 
 
@@ -15,9 +15,9 @@ module m2procs 
       end function fun 
 end module m2procs 
 
-program minval2 
+program minloc2 
    use m2procs 
    implicit none 
 
    write(*,*) fun(1) 
-end program minval2 
+end program minloc2