public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102966] New: size() returns 0 for an unallocated array,  no error message or error exit
@ 2021-10-27 17:18 b.j.braams at cwi dot nl
  2021-10-27 19:01 ` [Bug fortran/102966] " kargl at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: b.j.braams at cwi dot nl @ 2021-10-27 17:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

            Bug ID: 102966
           Summary: size() returns 0 for an unallocated array, no error
                    message or error exit
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b.j.braams at cwi dot nl
  Target Milestone: ---

Using GNU Fortran (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1).

The four-line test program is:

PROGRAM test
  integer, allocatable :: ar(:)
  print *, size(ar)
END PROGRAM test

I compile with flags -Wall and -fcheck=all

gfortran -Wall -fcheck=all test.f90

This produces a.out without warning, and then ./a.out just prints 0 without
error message.

The expected result for me, especially with -fcheck=all, is an error exit at
run time. Un unallocated array is not a zero-size array.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
@ 2021-10-27 19:01 ` kargl at gcc dot gnu.org
  2021-10-27 19:20 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-10-27 19:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

kargl at gcc dot gnu.org changed:

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

--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to Bastiaan Braams from comment #0)
> Using GNU Fortran (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1).
> 
> The four-line test program is:
> 
> PROGRAM test
>   integer, allocatable :: ar(:)
>   print *, size(ar)
> END PROGRAM test
> 
> I compile with flags -Wall and -fcheck=all
> 
> gfortran -Wall -fcheck=all test.f90
> 
> This produces a.out without warning, and then ./a.out just prints 0 without
> error message.
> 
> The expected result for me, especially with -fcheck=all, is an error exit at
> run time. Un unallocated array is not a zero-size array.

The code is invalid Fortran.  A compiler can do anything, and
that includes what you think it should do.  To be specific,
from F2018 standard

  9.7.1.3 Allocation of allocatable variables

  The allocation status of an allocatable entity is one of the
  following at any time.

  *  The status of an allocatable variable becomes "allocated" if ...

  * An allocatable variable has a status of "unallocated" if it is not
    allocated.  The status of an allocatable variable becomes unallocated
    if it is deallocated (9.7.3) or if it is given that status by the
    intrinsic subroutine MOVE_ALLOC.  An allocatable variable with
    this status shall not be referenced or defined.  It shall not be
    supplied as an actual argument corresponding to a nonallocatable
    nonoptional dummy argument, except to certain intrinsic inquiry
    functions.  It may be allocated with the ALLOCATE statement.
    Deallocating it causes an error condition in the DEALLOCATE
    statement. The result of the intrinsic function ALLOCATED
    (16.9.11) is false for such a variable.

Those "shall"s that you see apply to the programmer not the processor.

This should be closed with either INVALID, but I'll let someone else
perform the honors.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
  2021-10-27 19:01 ` [Bug fortran/102966] " kargl at gcc dot gnu.org
@ 2021-10-27 19:20 ` anlauf at gcc dot gnu.org
  2021-10-27 21:42 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-27 19:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-10-27
      Known to work|                            |11.2.1, 12.0
             Status|UNCONFIRMED                 |WAITING
                 CC|                            |anlauf at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |10.3.1

--- Comment #2 from anlauf at gcc dot gnu.org ---
This is fixed in mainline for gcc-12 and 11-branch:

% gfc-11 zyx.f90 -fcheck=all -g
% ./a.out 
At line 3 of file zyx.f90
Fortran runtime error: Allocatable argument 'ar' is not allocated

Error termination. Backtrace:
#0  0x4007f8 in test
        at /home/anlauf/gcc-bugs/zyx.f90:3
#1  0x400887 in main
        at /home/anlauf/gcc-bugs/zyx.f90:4

One would need to bisect which patch fixed this.

Recommendation: upgrade to a newer compiler version.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
  2021-10-27 19:01 ` [Bug fortran/102966] " kargl at gcc dot gnu.org
  2021-10-27 19:20 ` anlauf at gcc dot gnu.org
@ 2021-10-27 21:42 ` jakub at gcc dot gnu.org
  2021-10-28 18:24 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-27 21:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This was added in r11-5064-g0c81ccc3d87098b93b0e6a2dd76815e4d6e78ff0

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
                   ` (2 preceding siblings ...)
  2021-10-27 21:42 ` jakub at gcc dot gnu.org
@ 2021-10-28 18:24 ` anlauf at gcc dot gnu.org
  2021-10-28 18:45 ` kargl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-28 18:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #3)
> This was added in r11-5064-g0c81ccc3d87098b93b0e6a2dd76815e4d6e78ff0

Right, thanks.  There were a couple of regressions introduced by this patch,
and these are not yet completely resolved on mainline and on 11-branch.

I'd say this is not something that can be easily backported.

The best option for the reporter is to upgrade to a newer gcc.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
                   ` (3 preceding siblings ...)
  2021-10-28 18:24 ` anlauf at gcc dot gnu.org
@ 2021-10-28 18:45 ` kargl at gcc dot gnu.org
  2021-10-28 19:07 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-10-28 18:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #4)
> (In reply to Jakub Jelinek from comment #3)
> > This was added in r11-5064-g0c81ccc3d87098b93b0e6a2dd76815e4d6e78ff0
> 
> Right, thanks.  There were a couple of regressions introduced by this patch,
> and these are not yet completely resolved on mainline and on 11-branch.
> 
> I'd say this is not something that can be easily backported.
> 
> The best option for the reporter is to upgrade to a newer gcc.

Then this should probably be closed as WONTFIX.  Although
INVALID would also apply as the code is invalid Fortran.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
                   ` (4 preceding siblings ...)
  2021-10-28 18:45 ` kargl at gcc dot gnu.org
@ 2021-10-28 19:07 ` anlauf at gcc dot gnu.org
  2021-10-29  9:39 ` b.j.braams at cwi dot nl
  2021-10-29  9:45 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-28 19:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #6 from anlauf at gcc dot gnu.org ---
Closing then.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
                   ` (5 preceding siblings ...)
  2021-10-28 19:07 ` anlauf at gcc dot gnu.org
@ 2021-10-29  9:39 ` b.j.braams at cwi dot nl
  2021-10-29  9:45 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: b.j.braams at cwi dot nl @ 2021-10-29  9:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

--- Comment #7 from Bastiaan Braams <b.j.braams at cwi dot nl> ---
Pleased to see that the run-time error is properly diagnosed in version 11.2.1
and later, and agreed that the matter is outside the fortran language standard.
Just one comment on the discussion in view of the WONTFIX label: the failure to
generate a run-time error for this code may be viewed, I think, as a bug
against the specification of the -fcheck=all option, which includes
-fcheck=pointer with the description "Enable generation of run-time checks for
pointers and allocatables." It appears that an appropriate run-time check was
not generated.

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

* [Bug fortran/102966] size() returns 0 for an unallocated array, no error message or error exit
  2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
                   ` (6 preceding siblings ...)
  2021-10-29  9:39 ` b.j.braams at cwi dot nl
@ 2021-10-29  9:45 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-29  9:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102966

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What checks are emitted evolves over time...

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

end of thread, other threads:[~2021-10-29  9:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 17:18 [Bug fortran/102966] New: size() returns 0 for an unallocated array, no error message or error exit b.j.braams at cwi dot nl
2021-10-27 19:01 ` [Bug fortran/102966] " kargl at gcc dot gnu.org
2021-10-27 19:20 ` anlauf at gcc dot gnu.org
2021-10-27 21:42 ` jakub at gcc dot gnu.org
2021-10-28 18:24 ` anlauf at gcc dot gnu.org
2021-10-28 18:45 ` kargl at gcc dot gnu.org
2021-10-28 19:07 ` anlauf at gcc dot gnu.org
2021-10-29  9:39 ` b.j.braams at cwi dot nl
2021-10-29  9:45 ` jakub 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).