public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression )
@ 2010-11-15 14:49 burnus at gcc dot gnu.org
  2010-11-15 14:55 ` [Bug fortran/46484] " burnus at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Should reject ALLOCATED(non-variable expression )
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


gfortran should reject non-variable expressions for ALLOCATED:

"13.7.11 ALLOCATED (ARRAY) or ALLOCATED (SCALAR)
Description. Query allocation status.
Class. Inquiry function.
Arguments.
  ARRAY shall be an allocatable array.
  SCALAR shall be an allocatable scalar."

Test case:

implicit none
logical :: ll
ll = allocated (f())
contains
  function f()
    integer, allocatable :: f
  end function f
end


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

* [Bug fortran/46484] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
@ 2010-11-15 14:55 ` burnus at gcc dot gnu.org
  2010-11-15 15:38 ` [Bug fortran/46484] [4.5/4.6 Regression] " burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-15 14:46:53 UTC ---
Longer test case is gfortran.dg/allocatable_scalar_5.f90 (cf. 46485).

This can be seen if one uses valgrind on the file: No error and 3*4 bytes = 12
bytes are losts:

4 bytes in 1 blocks are definitely lost in loss record 1 of 3
  at 0x4C26C36: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
  by 0x400A3F: func.1513 (allocatable_scalar_5.f90:39)


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

* [Bug fortran/46484] [4.5/4.6 Regression] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
  2010-11-15 14:55 ` [Bug fortran/46484] " burnus at gcc dot gnu.org
@ 2010-11-15 15:38 ` burnus at gcc dot gnu.org
  2010-11-15 17:31 ` kargl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
   Target Milestone|---                         |4.6.0
            Summary|Should reject               |[4.5/4.6 Regression] Should
                   |ALLOCATED(non-variable      |reject
                   |expression )                |ALLOCATED(non-variable
                   |                            |expression )

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-15 15:25:48 UTC ---
(In reply to comment #1)
> Longer test case is gfortran.dg/allocatable_scalar_5.f90 (cf. 46485).

PR 46485


Mark as 4.5/4.6 regression. It is not true regression as 4.3/4.4 rejected it
with "just" with
  Internal Error at (1):
  gfc_variable_attr(): Expression isn't a variable
but still ...

The reason for the failure is that check.c's variable_check accepts:
   || (e->expr_type == EXPR_FUNCTION

which at a glance does not make sense. Currently, I can only imagine a Fortran
2008 case, which allows pointer-returning functions in place of variables. Cf.
PR 40054 (and PR 46100).

I traced the line back to:
  Rev. 81764: "Merge tree-ssa-20020619-branch into mainline." (2004-05-13)

Thus, it seems as if this line was never valid.

  * * *

Draft patch: The following seems to be sensible and some incomplete regtesting
suggests that it probably works:

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 51ea877..cc36fea 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -491,10 +491,8 @@ variable_check (gfc_expr *e, int n)
       return FAILURE;
     }

-  if ((e->expr_type == EXPR_VARIABLE
+  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;

   gfc_error ("'%s' argument of '%s' intrinsic at %L must be a variable",


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

* [Bug fortran/46484] [4.5/4.6 Regression] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
  2010-11-15 14:55 ` [Bug fortran/46484] " burnus at gcc dot gnu.org
  2010-11-15 15:38 ` [Bug fortran/46484] [4.5/4.6 Regression] " burnus at gcc dot gnu.org
@ 2010-11-15 17:31 ` kargl at gcc dot gnu.org
  2010-11-15 18:08 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: kargl at gcc dot gnu.org @ 2010-11-15 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #3 from kargl at gcc dot gnu.org 2010-11-15 16:48:24 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > Longer test case is gfortran.dg/allocatable_scalar_5.f90 (cf. 46485).
> 
> PR 46485
> 
> 
> Mark as 4.5/4.6 regression. It is not true regression as 4.3/4.4 rejected it
> with "just" with
>   Internal Error at (1):
>   gfc_variable_attr(): Expression isn't a variable
> but still ...
> 
> The reason for the failure is that check.c's variable_check accepts:
>    || (e->expr_type == EXPR_FUNCTION
> 
> which at a glance does not make sense. Currently, I can only imagine a Fortran
> 2008 case, which allows pointer-returning functions in place of variables. Cf.
> PR 40054 (and PR 46100).
> 

I think you may have trimmed too much of the condition.

      || (e->expr_type == EXPR_FUNCTION
      && e->symtree->n.sym->result == e->symtree->n.sym))

Doesn't the second part apply to RESULT variables, ie.,

  funtion foo(x) result(this_should_be_a_variable(not_a function))

I haven't checked if this where it would apply.


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

* [Bug fortran/46484] [4.5/4.6 Regression] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2010-11-15 17:31 ` kargl at gcc dot gnu.org
@ 2010-11-15 18:08 ` burnus at gcc dot gnu.org
  2010-11-15 20:48 ` burnus at gcc dot gnu.org
  2010-11-15 21:04 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 18:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-15 17:41:19 UTC ---
(In reply to comment #3)
> I think you may have trimmed too much of the condition.
>       || (e->expr_type == EXPR_FUNCTION
>       && e->symtree->n.sym->result == e->symtree->n.sym))
> Doesn't the second part apply to RESULT variables, ie.,
>   funtion foo(x) result(this_should_be_a_variable(not_a function))
> I haven't checked if this where it would apply.

No, it doesn't. That still counts as EXPR_VARIABLE:

  function f()
    integer, allocatable :: f
    print *, allocated(f)

Or at least: It still works with this patch. I find it more interesting that
   external proc
   print *, loc(proc)
still works.


Actually, the patch is incomplete as the following program still compiles:
  integer, allocatable :: x
  print *, allocated(f)  ! <<< invalid, "f" is not a variable
  contains
  function f()
    integer, allocatable :: f
    print *, loc(f)
    print *, allocated(f)
  end function
  end


I will update the patch - to reject the code above but such that it still
allows "loc(proc_name)".


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

* [Bug fortran/46484] [4.5/4.6 Regression] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2010-11-15 18:08 ` burnus at gcc dot gnu.org
@ 2010-11-15 20:48 ` burnus at gcc dot gnu.org
  2010-11-15 21:04 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-15 20:44:29 UTC ---
Author: burnus
Date: Mon Nov 15 20:44:26 2010
New Revision: 166769

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166769
Log:
2010-11-15  Tobias Burnus  <burnus@net.b.de>

        PR fortran/46484
        * check.c (variable_check): Don't treat functions calls as
        * variables;
        optionally accept function themselves.
        (gfc_check_all_any, gfc_check_loc, gfc_check_move_alloc,
        gfc_check_null, gfc_check_present, gfc_check_cpu_time,
        gfc_check_date_and_time, gfc_check_mvbits, gfc_check_random_number,
        gfc_check_random_seed, gfc_check_system_clock,
        gfc_check_dtime_etime, gfc_check_dtime_etime_sub,
        gfc_check_itime_idate,gfc_check_ltime_gmtime): Update call.

2010-11-15  Tobias Burnus  <burnus@net.b.de>

        PR fortran/46484
        * gfortran.dg/allocatable_scalar_11.f90: New.
        * gfortran.dg/allocatable_scalar_5.f90: Make test case standard
        * conform.


Added:
    trunk/gcc/testsuite/gfortran.dg/allocatable_scalar_11.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/allocatable_scalar_5.f90


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

* [Bug fortran/46484] [4.5/4.6 Regression] Should reject ALLOCATED(non-variable expression )
  2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2010-11-15 20:48 ` burnus at gcc dot gnu.org
@ 2010-11-15 21:04 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-15 21:04 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-15 20:45:31 UTC ---
FIXED on the trunk (4.6).


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

end of thread, other threads:[~2010-11-15 20:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-15 14:49 [Bug fortran/46484] New: Should reject ALLOCATED(non-variable expression ) burnus at gcc dot gnu.org
2010-11-15 14:55 ` [Bug fortran/46484] " burnus at gcc dot gnu.org
2010-11-15 15:38 ` [Bug fortran/46484] [4.5/4.6 Regression] " burnus at gcc dot gnu.org
2010-11-15 17:31 ` kargl at gcc dot gnu.org
2010-11-15 18:08 ` burnus at gcc dot gnu.org
2010-11-15 20:48 ` burnus at gcc dot gnu.org
2010-11-15 21:04 ` burnus at gcc dot gnu.org

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).