public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function
@ 2011-05-11  8:09 thenlich at users dot sourceforge.net
  2015-10-14 21:45 ` [Bug libfortran/48958] " anlauf at gmx dot de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: thenlich at users dot sourceforge.net @ 2011-05-11  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Add runtime diagnostics for SIZE intrinsic function
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: thenlich@users.sourceforge.net


As has been brought up before (Bug 20406), the SIZE intrinsic returns an
unpredictable result if the argument is an unallocated allocatable or a pointer
that is not associated.

While this is perfectly standard-conforming behaviour, it would be helpful in
program development to have SIZE throw a runtime error if this condition
occurs.

I.e. SIZE should first check if an array is ALLOCATED or a pointer is
ASSOCIATED and abort with a runtime error if that is not the case.

Fortran 2008:

13.7.156 SIZE (ARRAY [, DIM, KIND])
3 Arguments.
ARRAY shall be an array of any type. It shall not be an unallocated allocatable
variable or a pointer that is not associated. If ARRAY is an assumed-size
array, DIM shall be present with a value less than the rank of ARRAY.


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

* [Bug libfortran/48958] Add runtime diagnostics for SIZE intrinsic function
  2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
@ 2015-10-14 21:45 ` anlauf at gmx dot de
  2015-10-15  9:36 ` dominiq at lps dot ens.fr
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gmx dot de @ 2015-10-14 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #2 from Harald Anlauf <anlauf at gmx dot de> ---
There are a few inquiry functions (SIZE, SHAPE, (L,U)BOUND) where such
a diagnostic might be useful.  It could be hidden behind one of the
-fcheck options.

However:

Depending on the implementation, it might work only for ALLOCATABLE,
where there is no undefined allocation status.  For a POINTER, the
status could be undefined, and it is not possible to discover this.
(It is even nice to be able to find out what the last size was
before deallocating the target of the pointer...)

NAG does the following:

% cat pr48958.f90
!integer, allocatable :: a(:)
integer, pointer :: a(:)
print *, size (a)
end
% nagfor -C pr48958.f90 && ./a.out 
NAG Fortran Compiler Release 5.3.1(907)
[NAG Fortran Compiler normal termination]
Runtime Error: pr48958.f90, line 3: Reference to undefined POINTER A
Program terminated by fatal error
Abort

Not sure whether there are other compilers which can handle this.


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

* [Bug libfortran/48958] Add runtime diagnostics for SIZE intrinsic function
  2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
  2015-10-14 21:45 ` [Bug libfortran/48958] " anlauf at gmx dot de
@ 2015-10-15  9:36 ` dominiq at lps dot ens.fr
  2020-11-14 22:16 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-10-15  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
This PR is related to pr46182. While I agree that it would be nice to have run
time errors for invalid use of unallocated variables/not associated pointers, I
doubt it will ever happen.


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

* [Bug libfortran/48958] Add runtime diagnostics for SIZE intrinsic function
  2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
  2015-10-14 21:45 ` [Bug libfortran/48958] " anlauf at gmx dot de
  2015-10-15  9:36 ` dominiq at lps dot ens.fr
@ 2020-11-14 22:16 ` anlauf at gcc dot gnu.org
  2020-11-16 21:01 ` cvs-commit at gcc dot gnu.org
  2020-11-16 22:31 ` [Bug fortran/48958] " anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-11-14 22:16 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #5 from anlauf at gcc dot gnu.org ---
Incomplete patch:
https://gcc.gnu.org/pipermail/fortran/2020-November/055300.html

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

* [Bug libfortran/48958] Add runtime diagnostics for SIZE intrinsic function
  2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2020-11-14 22:16 ` anlauf at gcc dot gnu.org
@ 2020-11-16 21:01 ` cvs-commit at gcc dot gnu.org
  2020-11-16 22:31 ` [Bug fortran/48958] " anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-16 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:0c81ccc3d87098b93b0e6a2dd76815e4d6e78ff0

commit r11-5064-g0c81ccc3d87098b93b0e6a2dd76815e4d6e78ff0
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Nov 16 22:00:58 2020 +0100

    PR fortran/48958 - Add runtime diagnostics for SIZE intrinsic function

    Add code for runtime checking of status of ALLOCATABLE and POINTER
    arguments to the SIZE intrinsic when -fcheck=pointer is specified.

    gcc/fortran/ChangeLog:

            * trans-intrinsic.c (gfc_conv_intrinsic_size): Generate runtime
            checking code for status of argument.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/pr48958.f90: New test.

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

* [Bug fortran/48958] Add runtime diagnostics for SIZE intrinsic function
  2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2020-11-16 21:01 ` cvs-commit at gcc dot gnu.org
@ 2020-11-16 22:31 ` anlauf at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-11-16 22:31 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P5
             Status|SUSPENDED                   |NEW
                 CC|anlauf at gmx dot de               |
          Component|libfortran                  |fortran

--- Comment #7 from anlauf at gcc dot gnu.org ---
The question on what to do with runtime checks and possibly undefined pointers,
which has been repeated by Thomas on the ML, could be solved by initializing
the data component when -fcheck=pointer is specified.

A somewhat hackish solution which regtests cleanly:

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index b2c39aa32de..6e1f27ead45 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -10668,7 +10668,9 @@ gfc_trans_deferred_array (gfc_symbol * sym,
gfc_wrapped_block * block)
     }

   /* NULLIFY the data pointer, for non-saved allocatables.  */
-  if (GFC_DESCRIPTOR_TYPE_P (type) && !sym->attr.save &&
sym->attr.allocatable)
+  if (GFC_DESCRIPTOR_TYPE_P (type) && !sym->attr.save
+      && (sym->attr.allocatable
+         || (sym->attr.pointer && (gfc_option.rtcheck &
GFC_RTCHECK_POINTER))))
     {
       gfc_conv_descriptor_data_set (&init, descriptor, null_pointer_node);
       if (flag_coarray == GFC_FCOARRAY_LIB && sym->attr.codimension)

Still need to learn weather this is the right solution, but it does the job.

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

end of thread, other threads:[~2020-11-16 22:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-11  8:09 [Bug libfortran/48958] New: Add runtime diagnostics for SIZE intrinsic function thenlich at users dot sourceforge.net
2015-10-14 21:45 ` [Bug libfortran/48958] " anlauf at gmx dot de
2015-10-15  9:36 ` dominiq at lps dot ens.fr
2020-11-14 22:16 ` anlauf at gcc dot gnu.org
2020-11-16 21:01 ` cvs-commit at gcc dot gnu.org
2020-11-16 22:31 ` [Bug fortran/48958] " anlauf 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).