public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/39230]  New: ASSOCIATED & undefined pointers
@ 2009-02-18 10:36 janus at gcc dot gnu dot org
  2009-02-18 17:28 ` [Bug fortran/39230] " burnus at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-02-18 10:36 UTC (permalink / raw)
  To: gcc-bugs

Consider the following snippet:

implicit none
integer, pointer :: p
print *,associated(p)
end

This is actually invalid and should probably trigger a runtime error. Section
13.7.13 of the Fortran 2003 standard says that the pointer argument of
ASSOCIATED should not be undefined, which it is in the case above (cf. section
16.4.2).

Also see the discussion in http://gcc.gnu.org/ml/fortran/2006-06/msg00235.html
and follow-ups.

Right now the above program simply prints "T". This is kind of dangerous, since
it looks like the pointer is associated with some target, while in fact it is
not. ifort prints "F". I didn't check other compilers.


-- 
           Summary: ASSOCIATED & undefined pointers
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


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


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

* [Bug fortran/39230] ASSOCIATED & undefined pointers
  2009-02-18 10:36 [Bug fortran/39230] New: ASSOCIATED & undefined pointers janus at gcc dot gnu dot org
@ 2009-02-18 17:28 ` burnus at gcc dot gnu dot org
  2009-02-18 17:33 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-02-18 17:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2009-02-18 17:28 -------
> This is actually invalid
Yes, but this is a requirement to the program(mer) not to the compiler.

> and should probably trigger a runtime error. 
Yes, but only with some checking option, otherwise it really gets too slow.
Especially in the general case, you cannot easily check this. Setting
by default "ptr = NULL" only hides the problem.

 * * *

I think what you want is some -fcheck=pointer option (I think there is a PR
about his). That option would initialize pointer with some bogus value, e.g.

  extern intptr_t _gfortran_bogus_pointer;
  integer *p, *bogus_local;
  bogus_local = &_gfortran_bogus_pointer; 
  p = bogus_local
  {
     logical D14;
     if (p == &_gfortran_bogus_pointer)
       _gfortran_runtime_error("Bogus pointer at %C");
     D14 = (p == NULL)
     print *, D14
  }

_gfortran_bogus_pointer is in libgfortran and the advantage is that one can
also check called arguments, e.g.
  call foo(ptr)
...
subroutine foo(ptr)
   if(associated(ptr)) ...
Disadvantage is the speed, but that should not matter for a checking option.

The checking has to be done before:
- ASSOCIATED, DEALLOCATE
- Actual arguments, which don't expect a pointer argument
- Expressions which use the pointer (esp. "var = ptr"; is "ptr => uninit_ptr"
valid?)
- BUT: Not for allocate, NULL(uninitialized_pointer) or ptr => NULL(),
nullify(ptr), ...

I was once about to implement this, but especially if you want to get all cases
right, it is a bigger patch. One could presumably start by initializing the
pointer by "bogus_pointer" and add the checking before associate and
deallocate, which should cover the most common problems.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org


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


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

* [Bug fortran/39230] ASSOCIATED & undefined pointers
  2009-02-18 10:36 [Bug fortran/39230] New: ASSOCIATED & undefined pointers janus at gcc dot gnu dot org
  2009-02-18 17:28 ` [Bug fortran/39230] " burnus at gcc dot gnu dot org
@ 2009-02-18 17:33 ` burnus at gcc dot gnu dot org
  2009-02-19  5:53 ` pault at gcc dot gnu dot org
  2009-02-19  7:08 ` burnus at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-02-18 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2009-02-18 17:32 -------
The other bug is PR 29616.


-- 


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


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

* [Bug fortran/39230] ASSOCIATED & undefined pointers
  2009-02-18 10:36 [Bug fortran/39230] New: ASSOCIATED & undefined pointers janus at gcc dot gnu dot org
  2009-02-18 17:28 ` [Bug fortran/39230] " burnus at gcc dot gnu dot org
  2009-02-18 17:33 ` burnus at gcc dot gnu dot org
@ 2009-02-19  5:53 ` pault at gcc dot gnu dot org
  2009-02-19  7:08 ` burnus at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pault at gcc dot gnu dot org @ 2009-02-19  5:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pault at gcc dot gnu dot org  2009-02-19 05:52 -------
I wonder if this should not be fixed ultimately by:
(i) Allowing allocatable scalars, which should allow rank 0 descriptors to take
the field; and
(ii) Once we have array descriptors that flag the status of the data, include
pointers in the club?

Confirmed and marked as accepts-invalid.

Paul 


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid
   Last reconfirmed|0000-00-00 00:00:00         |2009-02-19 05:52:54
               date|                            |


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


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

* [Bug fortran/39230] ASSOCIATED & undefined pointers
  2009-02-18 10:36 [Bug fortran/39230] New: ASSOCIATED & undefined pointers janus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2009-02-19  5:53 ` pault at gcc dot gnu dot org
@ 2009-02-19  7:08 ` burnus at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-02-19  7:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2009-02-19 07:08 -------
> (ii) Once we have array descriptors that flag the status of the data, include
> pointers in the club?

I prefer to have simple pointers for scalars and use the descriptor only for
arrays/strings/dimension(..) for performance reasons; though one could use the
descriptor with -fcheck=pointers.


-- 


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


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

end of thread, other threads:[~2009-02-19  7:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-18 10:36 [Bug fortran/39230] New: ASSOCIATED & undefined pointers janus at gcc dot gnu dot org
2009-02-18 17:28 ` [Bug fortran/39230] " burnus at gcc dot gnu dot org
2009-02-18 17:33 ` burnus at gcc dot gnu dot org
2009-02-19  5:53 ` pault at gcc dot gnu dot org
2009-02-19  7:08 ` burnus at gcc dot gnu dot 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).