public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables
@ 2010-10-26 12:17 dominiq at lps dot ens.fr
  2010-10-26 13:18 ` Mikael Morin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2010-10-26 12:17 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Run time check for invalid use of unallocated
                    allocatable variables
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dominiq@lps.ens.fr


While the following code

type b
  integer, allocatable :: i(:)
end type b
type(b), allocatable :: a(:)
!allocate(a(10))
print *, allocated(a)!, allocated(a(1)%i)
!deallocate(a)
end

seems to be a valid f2003 code and gives 'F' at run time, replacing

print *, allocated(a)!, allocated(a(1)%i)

with

print *, allocated(a), allocated(a(1)%i)

gives a "Segmentation fault" at run time (it gives 'T F' if the
allocate/deallocate lines are uncommented).

When asked on IRC about this kind of inquiry of a component of an unallocated
derived type, Tobias Burnus answered immediately that such a use is invalid,
pointing to

2.4.9 Allocatable variables
...
2 An unallocated allocatable variable shall not be referenced or defi\fned.
...

Then he made the comment that (obviously) this restriction does not apply for

13.7.11 ALLOCATED (ARRAY) or ALLOCATED (SCALAR)
1 Description. Query allocation status.
2 Class. Inquiry function.
3 Arguments.
   ARRAY shall be an allocatable array.
  SCALAR shall be an allocatable scalar.
4 Result Characteristics. Default logical scalar.
5 Result Value. The result has the value true if the argument (ARRAY or SCALAR)
is allocated and has the
value false if the argument is unallocated.

but that 'a(1)%i' is not an array but an invalid expression per 2.4.9 that
cannot be a valid argument of allocated. Note that my original problem came
from scalar allocatable and that the above was less obvious for 'a%i'.

It would be nice to have a run time check for such invalid use of unallocated
allocatable variables (such as -fcheck=use_unalloc).


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

* Re: [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables
  2010-10-26 12:17 [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables dominiq at lps dot ens.fr
@ 2010-10-26 13:18 ` Mikael Morin
  2010-10-26 14:07 ` [Bug libfortran/46182] " dominiq at lps dot ens.fr
  2010-10-26 14:29 ` mikael at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: Mikael Morin @ 2010-10-26 13:18 UTC (permalink / raw)
  To: gcc-bugs

> It would be nice to have a run time check for such invalid use of
> unallocated allocatable variables (such as -fcheck=use_unalloc).
If you use an unallocated variable you get a segmentation fault. 
Isn't this a sufficient runtime check ?


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

* [Bug libfortran/46182] Run time check for invalid use of unallocated allocatable variables
  2010-10-26 12:17 [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables dominiq at lps dot ens.fr
  2010-10-26 13:18 ` Mikael Morin
@ 2010-10-26 14:07 ` dominiq at lps dot ens.fr
  2010-10-26 14:29 ` mikael at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2010-10-26 14:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2010-10-26 14:06:55 UTC ---
Forwarded from http://gcc.gnu.org/ml/gcc-bugs/2010-10/msg02167.html
> > It would be nice to have a run time check for such invalid use of
> > unallocated allocatable variables (such as -fcheck=use_unalloc).
> If you use an unallocated variable you get a segmentation fault. 
> Isn't this a sufficient runtime check ?

Well! You can say the same thing for -fcheck=bounds if writing outside array 
bounds gives you a segmentation fault! Nevertheless nobody will argue that this
check is useless: it can save you hours of debugging to locate the line(s) in
which you do it.

Segmentation faults tell you that there is something wrong, but not why and/or
where (not counting gfortran bugs). It took me some time to understand it for a
less than 20 line code in which I had the bad idea of using a copy and paste
from a valid line to an invalid one (this can happen to anybody with kloc!-)


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

* [Bug libfortran/46182] Run time check for invalid use of unallocated allocatable variables
  2010-10-26 12:17 [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables dominiq at lps dot ens.fr
  2010-10-26 13:18 ` Mikael Morin
  2010-10-26 14:07 ` [Bug libfortran/46182] " dominiq at lps dot ens.fr
@ 2010-10-26 14:29 ` mikael at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mikael at gcc dot gnu.org @ 2010-10-26 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.26 14:29:15
                 CC|                            |mikael at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> 2010-10-26 14:29:15 UTC ---
(In reply to comment #1)
> Well! You can say the same thing for -fcheck=bounds if writing outside array 
> bounds gives you a segmentation fault! Nevertheless nobody will argue that this
> check is useless: it can save you hours of debugging to locate the line(s) in
> which you do it.
Well, my point was that an out of bound access doesn't necessarily faults
whereas a NULL pointer access always does. 
Anyway, it can't do any harm. Confirmed.


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

end of thread, other threads:[~2010-10-26 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 12:17 [Bug libfortran/46182] New: Run time check for invalid use of unallocated allocatable variables dominiq at lps dot ens.fr
2010-10-26 13:18 ` Mikael Morin
2010-10-26 14:07 ` [Bug libfortran/46182] " dominiq at lps dot ens.fr
2010-10-26 14:29 ` mikael 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).