public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35299]  New: scope of variables in statement function do not acquire rank from host
@ 2008-02-22 23:31 kargl at gcc dot gnu dot org
  2008-02-22 23:33 ` [Bug fortran/35299] " kargl at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-02-22 23:31 UTC (permalink / raw)
  To: gcc-bugs

In a statement function, only the type and kind are determined from the host.
gfortran fails to compile 

troutmask:kargl[205] cat n.f
      SUBROUTINE PHTOD(E,N,I,H)
      DIMENSION E(N)
      HSTAR(E,B)=B**.4*((1.25*FUN(-E/40)+.18)) ! Doesn't work.
C     HSTAR(X,Y)=Y**.4*((1.25*FUN(-X/40)+.18)) ! Works.
      A = 1.
      H = HSTAR(E(I-1), A)
      END

troutmask:kargl[207] ftnchek n.f

FTNCHEK Version 3.3 November 2004

File n.f:
 0 syntax errors detected in file n.f
No main program found
Warning: Subprogram FUN never defined
    Invoked in module PHTOD line 3 file n.f
    (possibly it is an array which was not declared)
troutmask:kargl[208] gfc -c n.f
n.f:1.24:

      SUBROUTINE PHTOD(E,N,I,H)                                         
                       1
Error: Argument 'e' of statement function at (1) must be scalar

If the reference to FUN in statement function is changed to an
elemental function, then one gets an additional error.  Changing
FUN to SIN yields

troutmask:kargl[210] gfc -c n.f
n.f:1.24:

      SUBROUTINE PHTOD(E,N,I,H)                                         
                       1
Error: Argument 'e' of statement function at (1) must be scalar
n.f:3.11:

      HSTAR(E,B)=B**.4*((1.25*SIN(-E/40)+.18)) ! Doesn't work.          
          1
Error: Incompatible ranks 0 and 1 in assignment at (1)

Because statement functions are obselscent in Fortran 95, this should be
considered a very low priority bug.


-- 
           Summary: scope of variables in statement function do not acquire
                    rank from host
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kargl at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
@ 2008-02-22 23:33 ` kargl at gcc dot gnu dot org
  2008-02-23 20:23 ` tkoenig at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-02-22 23:33 UTC (permalink / raw)
  To: gcc-bugs



-- 

kargl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.2.3 4.4.0
           Priority|P3                          |P5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
  2008-02-22 23:33 ` [Bug fortran/35299] " kargl at gcc dot gnu dot org
@ 2008-02-23 20:23 ` tkoenig at gcc dot gnu dot org
  2008-02-29 17:54 ` fxcoudert at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-02-23 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from tkoenig at gcc dot gnu dot org  2008-02-23 20:22 -------
Confirmed.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkoenig at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2008-02-23 20:22:34
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
  2008-02-22 23:33 ` [Bug fortran/35299] " kargl at gcc dot gnu dot org
  2008-02-23 20:23 ` tkoenig at gcc dot gnu dot org
@ 2008-02-29 17:54 ` fxcoudert at gcc dot gnu dot org
  2008-02-29 20:15 ` sgk at troutmask dot apl dot washington dot edu
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-02-29 17:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2008-02-29 17:53 -------
I disagree. In Fortran 2003 12.5.4, C1263/R1238 says "The function-name and
each dummy-arg-name shall be specified, explicitly or implicitly, to be
scalar.". Intel accepts it, but IBM, g95 and (most importantly) Lahey think
it's invalid.


However, the error message should point to the statement function. The patch
below gives, in my opinion, a better error message:

      HSTAR(E,B)=B**.4*((1.25*FUN(-E/40)+.18)) ! Doesn't work.          
          1
Error: Argument 'e' of statement function 'hstar' at (1) must be scalar


Index: resolve.c
===================================================================
--- resolve.c   (revision 132578)
+++ resolve.c   (working copy)
@@ -240,8 +240,9 @@
        {
          if (sym->as != NULL)
            {
-             gfc_error ("Argument '%s' of statement function at %L must "
-                        "be scalar", sym->name, &sym->declared_at);
+             gfc_error ("Argument '%s' of statement function '%s' at %L "
+                        "must be scalar", sym->name, proc->name,
+                        &proc->declared_at);
              continue;
            }



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
           Keywords|rejects-valid               |diagnostic, patch
   Last reconfirmed|2008-02-23 20:22:34         |2008-02-29 17:53:40
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-02-29 17:54 ` fxcoudert at gcc dot gnu dot org
@ 2008-02-29 20:15 ` sgk at troutmask dot apl dot washington dot edu
  2008-02-29 20:24 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2008-02-29 20:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from sgk at troutmask dot apl dot washington dot edu  2008-02-29 20:15 -------
Subject: Re:  scope of variables in statement function do not acquire rank from
host

On Fri, Feb 29, 2008 at 05:53:40PM -0000, fxcoudert at gcc dot gnu dot org
wrote:
> I disagree. In Fortran 2003 12.5.4, C1263/R1238 says "The function-name and
> each dummy-arg-name shall be specified, explicitly or implicitly, to be
> scalar.". Intel accepts it, but IBM, g95 and (most importantly) Lahey think
> it's invalid.
> 
> 
> However, the error message should point to the statement function. The patch
> below gives, in my opinion, a better error message:
> 
>       HSTAR(E,B)=B**.4*((1.25*FUN(-E/40)+.18)) ! Doesn't work.          
>           1
> Error: Argument 'e' of statement function 'hstar' at (1) must be scalar
> 

I disagree with your disagreement. :-)  Gordon Sande and Richard Maine
also disagrees with you (see c.l.f threads "I've never seen this
before in 30 years - what is this?" and "What is this").

>From Fortran 95, Sec. 12.5.4, lines 38 and 39:

  The dummy arguments have a scope of the statement function.  Each
  dummy argument has the same type and type parameters as the 
  entity of the same name in the scoping unit containing the statement
  function.

Note, this passage does not include rank.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-02-29 20:15 ` sgk at troutmask dot apl dot washington dot edu
@ 2008-02-29 20:24 ` fxcoudert at gcc dot gnu dot org
  2008-02-29 20:42 ` sgk at troutmask dot apl dot washington dot edu
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-02-29 20:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2008-02-29 20:23 -------
(In reply to comment #3)
>   The dummy arguments have a scope of the statement function.  Each
>   dummy argument has the same type and type parameters as the 
>   entity of the same name in the scoping unit containing the statement
>   function.
> 
> Note, this passage does not include rank.

No, but it does not say that they are scalar either. It does not say "Each
dummy argument is a scalar of the same type and type parameters...".

If we follow this interpretation, then what does "The function-name and each
dummy-arg-name shall be specified, explicitly or implicitly, to be scalar"
mean? In your (and Richard Maine's and ...) reading, the dummy arguments are by
definition scalar, and so how can they be "specified, explicitly or implicitly,
to be scalar". Or, to say it the other way around, let's say that I want to
break this particular constraint, how do I explicitly specify one of my dummy
arguments not to be a scalar?

I'm thoroughly confused.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-02-29 20:24 ` fxcoudert at gcc dot gnu dot org
@ 2008-02-29 20:42 ` sgk at troutmask dot apl dot washington dot edu
  2008-02-29 22:56 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2008-02-29 20:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from sgk at troutmask dot apl dot washington dot edu  2008-02-29 20:41 -------
Subject: Re:  scope of variables in statement function do not acquire rank from
host

On Fri, Feb 29, 2008 at 08:23:16PM -0000, fxcoudert at gcc dot gnu dot org
wrote:
> (In reply to comment #3)
> >   The dummy arguments have a scope of the statement function.  Each
> >   dummy argument has the same type and type parameters as the 
> >   entity of the same name in the scoping unit containing the statement
> >   function.
> > 
> > Note, this passage does not include rank.
> 
> No, but it does not say that they are scalar either. It does not say "Each
> dummy argument is a scalar of the same type and type parameters...".
> 
> If we follow this interpretation, then what does "The function-name
> and each dummy-arg-name shall be specified, explicitly or implicitly,
> to be scalar"  mean? In your (and Richard Maine's and ...) reading,
> the dummy arguments are by definition scalar, and so how can they be
> "specified, explicitly or implicitly,
> to be scalar". Or, to say it the other way around, let's say that I want to
> break this particular constraint, how do I explicitly specify one of my dummy
> arguments not to be a scalar?
> 
> I'm thoroughly confused.
> 

Don't worry, I share your confusion (when I read the standard). :)

I think the passage you quote applies to the following code:

  program z
    real :: y = 2.
    real :: x(5) = 1.
    f(x(2:4)) = 2 * sum(x)   ! dummy arg is an array.
    g(y) = y * x             ! function g is an array because of x.
  end program z

I just found the definition of type parameters in 2.4.1.1.
"The type parameters are KIND and LEN."  All other attributes
are irrelevant.

PS: I see you just found the c.l.f threads.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-02-29 20:42 ` sgk at troutmask dot apl dot washington dot edu
@ 2008-02-29 22:56 ` fxcoudert at gcc dot gnu dot org
  2008-02-29 23:06 ` sgk at troutmask dot apl dot washington dot edu
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-02-29 22:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2008-02-29 22:55 -------
I've thought about it more, and it's probably going to be tricky to solve:
after we have matched the formal arglist, we need to fill the namespace with
replacement symbols for all the dummy args (stripping them from their
attributes other than type and kind), then match the body of the statement
function, then remove these symbols and go on with our life. I don't know the
resolution code well enough to do that :(


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|fxcoudert at gcc dot gnu dot|unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW
           Keywords|patch                       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2008-02-29 22:56 ` fxcoudert at gcc dot gnu dot org
@ 2008-02-29 23:06 ` sgk at troutmask dot apl dot washington dot edu
  2008-02-29 23:53 ` sgk at troutmask dot apl dot washington dot edu
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2008-02-29 23:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from sgk at troutmask dot apl dot washington dot edu  2008-02-29 23:05 -------
Subject: Re:  scope of variables in statement function do not acquire rank from
host

On Fri, Feb 29, 2008 at 10:55:31PM -0000, fxcoudert at gcc dot gnu dot org
wrote:
>--- Comment #6 from fxcoudert at gcc dot gnu dot org  2008-02-29 22:55 -------
> I've thought about it more, and it's probably going to be tricky to solve:
> after we have matched the formal arglist, we need to fill the namespace with
> replacement symbols for all the dummy args (stripping them from their
> attributes other than type and kind), then match the body of the statement
> function, then remove these symbols and go on with our life. I don't know the
> resolution code well enough to do that :(

This bug pre-dates gfortran (at least it is also in g95).  gfortran
has compiled a ton of F77 code, and this is the first instance that
I've seen.  I think this bug is way down the priority list.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2008-02-29 23:06 ` sgk at troutmask dot apl dot washington dot edu
@ 2008-02-29 23:53 ` sgk at troutmask dot apl dot washington dot edu
  2008-08-08 21:07 ` jv244 at cam dot ac dot uk
  2008-08-08 23:48 ` sgk at troutmask dot apl dot washington dot edu
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2008-02-29 23:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from sgk at troutmask dot apl dot washington dot edu  2008-02-29 23:52 -------
Subject: Re:  scope of variables in statement function do not acquire rank from
host

> 
> Don't worry, I share your confusion (when I read the standard). :)
> 
> I think the passage you quote applies to the following code:
> 
>   program z
>     real :: y = 2.
>     real :: x(5) = 1.
>     f(x(2:4)) = 2 * sum(x)   ! dummy arg is an array.
>     g(y) = y * x             ! function g is an array because of x.
>   end program z
> 

Well, Richard Maine shot these down from other considerations.
The x(2:4) isn't a dummy-arg-name, so that one's out.  In
'g(y) = y * x', the RHS is not a scal-expr, so that one's 
out.

BTW, I don't use statement function, and I've come to dislike
them even more after thinking about this issue.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2008-02-29 23:53 ` sgk at troutmask dot apl dot washington dot edu
@ 2008-08-08 21:07 ` jv244 at cam dot ac dot uk
  2008-08-08 23:48 ` sgk at troutmask dot apl dot washington dot edu
  10 siblings, 0 replies; 12+ messages in thread
From: jv244 at cam dot ac dot uk @ 2008-08-08 21:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jv244 at cam dot ac dot uk  2008-08-08 21:06 -------
what is the 'rejects-valid' testcase here? apart from ifort, all compilers I
can access right now reject the program in the initial comment.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug fortran/35299] scope of variables in statement function do not acquire rank from host
  2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2008-08-08 21:07 ` jv244 at cam dot ac dot uk
@ 2008-08-08 23:48 ` sgk at troutmask dot apl dot washington dot edu
  10 siblings, 0 replies; 12+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2008-08-08 23:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from sgk at troutmask dot apl dot washington dot edu  2008-08-08 23:46 -------
Subject: Re:  scope of variables in statement function do not acquire rank from
host

On Fri, Aug 08, 2008 at 09:06:37PM -0000, jv244 at cam dot ac dot uk wrote:
> 
> ------- Comment #9 from jv244 at cam dot ac dot uk  2008-08-08 21:06 -------
> what is the 'rejects-valid' testcase here? apart from ifort, all compilers I
> can access right now reject the program in the initial comment.
> -- 
> 

Well, to start with, the code in comment #1 is valid Fortran 95.
See comment #3.  In checking, F2003 the exact same text appears.
I suppose you need to file bug reports with the other compiler
vendors.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35299


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-08-08 23:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-22 23:31 [Bug fortran/35299] New: scope of variables in statement function do not acquire rank from host kargl at gcc dot gnu dot org
2008-02-22 23:33 ` [Bug fortran/35299] " kargl at gcc dot gnu dot org
2008-02-23 20:23 ` tkoenig at gcc dot gnu dot org
2008-02-29 17:54 ` fxcoudert at gcc dot gnu dot org
2008-02-29 20:15 ` sgk at troutmask dot apl dot washington dot edu
2008-02-29 20:24 ` fxcoudert at gcc dot gnu dot org
2008-02-29 20:42 ` sgk at troutmask dot apl dot washington dot edu
2008-02-29 22:56 ` fxcoudert at gcc dot gnu dot org
2008-02-29 23:06 ` sgk at troutmask dot apl dot washington dot edu
2008-02-29 23:53 ` sgk at troutmask dot apl dot washington dot edu
2008-08-08 21:07 ` jv244 at cam dot ac dot uk
2008-08-08 23:48 ` sgk at troutmask dot apl dot washington dot edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).