Bug 42934 - Bogus variable_check
Summary: Bogus variable_check
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-02-02 09:59 UTC by Tobias Burnus
Modified: 2013-06-16 17:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-06-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-02-02 09:59:27 UTC
(Follow up from 41777, comment 10)

The following variable_check in check.c does not make much sense:

  if ((e->expr_type == EXPR_VARIABLE
       && e->symtree->n.sym->attr.flavor != FL_PARAMETER)
      || (e->expr_type == EXPR_FUNCTION
          && e->symtree->n.sym->result == e->symtree->n.sym))
    return SUCCESS;

I think the idea is to support

  function f()
    f = 4.0
  end function f

where this "f" is to regarded as variable. However, the test is also called outside of the function body of "f" (incl. internal procedures of f). In that case it does not make much sense.


The following example shows this: For LOC(f) it prints the address of the function, for LOC(f()) the result of the function call; but it fails for LOC(g()) due to
   e->symtree->n.sym->result == e->symtree->n.sym
(Ditto if "f" had a result variable.)

 * * *

I think the proper fix would be

a) To check whether is in the function body of "f" (incl. internal procedures of f) - and return FAILURE otherwise.

b) Optionally: Also allow LOC() for function (i.e. pointer address of the function itself). Supporting LOC(f()) does not make much sense, except for debugging - if one allows the latter, one also needs to handle generic functions.

 * * *

module m
 interface g
   module procedure f
 end interface g
contains
 function f()
   integer, pointer :: f
   f => null()
 end function f
end module m

use m
print *, loc(f)   ! prints something like 4196132
print *, loc(f()) ! print 0
print *, loc(g()) ! Error: must be a variable
end
Comment 1 Dominique d'Humieres 2012-01-24 11:41:21 UTC
> The following example shows this: For LOC(f) it prints the address of the
> function, for LOC(f()) the result of the function call; but it fails for

This is the case for gfortran 4.4 and 4.5, but 4.6 and trunk gives the following error

pr42934.f90:14.13:

print *, loc(f()) ! print 0
             1
Error: 'x' argument of 'loc' intrinsic at (1) must be a variable

What result do you expect? Is it a 4.6/4.7 regression?
Comment 2 Dominique d'Humieres 2013-06-16 17:35:47 UTC
> What result do you expect? Is it a 4.6/4.7 regression?

Ping!
Comment 3 Dominique d'Humieres 2013-06-16 17:41:08 UTC
No answer since over a year and the code in comment #0 seems to be gone. Finally closing as fixed. Please reopen if I am missing something.