public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35719]  New: pointer to zero sized array not associated
@ 2008-03-27 16:14 dick dot hendrickson at gmail dot com
  2008-03-27 16:54 ` [Bug fortran/35719] " burnus at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: dick dot hendrickson at gmail dot com @ 2008-03-27 16:14 UTC (permalink / raw)
  To: gcc-bugs

The ASSOCIATED function returns FALSE when its argument is a
pointer to a zero-sized array.

Dick Hendrickson

      program try_mf1053

! fails on Windows XP
! gcc version 4.4.0 20080312 (experimental) [trunk revision 133139]

      call       mf1053 (  1,   2,   3,   4)
      end

      SUBROUTINE MF1053 (nf1, nf2, nf3, nf4)
      INTEGER, pointer :: ILA(:,:)
      INTEGER, target  :: ILA1(NF2,NF4:NF3)

      ILA => ILA1

      if (ASSOCIATED (ILA, ILA1(NF1:NF2,NF4:NF3) ) ) print *, "1 bad"
      if ( .not. ASSOCIATED(ILA) )  print *, "2 bad"

      END SUBROUTINE

C:\g_experiments\gfortran>gfortran mf1053.f

C:\g_experiments\gfortran>a
 2 bad


-- 
           Summary: pointer to zero sized array not associated
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dick dot hendrickson at gmail dot com


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
@ 2008-03-27 16:54 ` burnus at gcc dot gnu dot org
  2008-05-04 21:29 ` tkoenig at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-03-27 16:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-03-27 16:53 -------
Confirm. Thanks for finding this bug.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-03-27 16:53:24
               date|                            |


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
  2008-03-27 16:54 ` [Bug fortran/35719] " burnus at gcc dot gnu dot org
@ 2008-05-04 21:29 ` tkoenig at gcc dot gnu dot org
  2008-05-05  5:47 ` burnus at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-04 21:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tkoenig at gcc dot gnu dot org  2008-05-04 21:29 -------
The problem is that we set ila1 to a null pointer if its
size is zero:

    D.647 = size.6 * 4;
    if (D.647 < 0)
      {
        _gfortran_runtime_error (&"Attempt to allocate a negative amount of
memory."[1]{lb: 1 sz: 1});
      }
    if (D.647 == 0)
      {
        D.648 = 0B;
      }
    else
      {
        D.648 = __builtin_malloc (D.647);
        if (D.648 == 0B)
          {
            _gfortran_os_error (&"Memory allocation failed"[1]{lb: 1 sz: 1});
          }
      }
    ila1 = (integer(kind=4)[0:D.644] *) D.648;

It isn't clear to me why we do this (maybe as a debugging aid?).


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
  2008-03-27 16:54 ` [Bug fortran/35719] " burnus at gcc dot gnu dot org
  2008-05-04 21:29 ` tkoenig at gcc dot gnu dot org
@ 2008-05-05  5:47 ` burnus at gcc dot gnu dot org
  2008-05-05 18:24 ` tkoenig at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-05-05  5:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2008-05-05 05:46 -------
(In reply to comment #2)
> The problem is that we set ila1 to a null pointer if its
> size is zero: [...]
> It isn't clear to me why we do this (maybe as a debugging aid?).

Well, if we don't assign anything, the memory content is not well defined.
Doing than   associated(ptr[, otherPtr])  gives then a random result including
not-associated.  Currently, ptr.data == NULL -> unassociated and ptr.data !=
NULL => associated works well, except for zero-sized arrays.

One possibility is to allocate something for zero-sized arrays, e.g. one
element. The array bounds ensure than that the program still knows that the
size of the array is zero. The extra allocation wastes memory, but usually one
element is quite small and zero-sized arrays are not very common.


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (2 preceding siblings ...)
  2008-05-05  5:47 ` burnus at gcc dot gnu dot org
@ 2008-05-05 18:24 ` tkoenig at gcc dot gnu dot org
  2008-05-06 21:25 ` tkoenig at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-05 18:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from tkoenig at gcc dot gnu dot org  2008-05-05 18:24 -------
(In reply to comment #3)

> One possibility is to allocate something for zero-sized arrays, e.g. one
> element. The array bounds ensure than that the program still knows that the
> size of the array is zero. The extra allocation wastes memory, but usually one
> element is quite small and zero-sized arrays are not very common.

I agree in principle; but we could also allocate a single array,
like we do for ALLOCATE.

This is probably the cleanest solution.


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (3 preceding siblings ...)
  2008-05-05 18:24 ` tkoenig at gcc dot gnu dot org
@ 2008-05-06 21:25 ` tkoenig at gcc dot gnu dot org
  2008-05-09  6:16 ` jb at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-06 21:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from tkoenig at gcc dot gnu dot org  2008-05-06 21:24 -------
Created an attachment (id=15587)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15587&action=view)
Trial patch

Here's an attempt at a patch, which should do the
right thing at least for this case.


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (4 preceding siblings ...)
  2008-05-06 21:25 ` tkoenig at gcc dot gnu dot org
@ 2008-05-09  6:16 ` jb at gcc dot gnu dot org
  2008-05-09 18:35 ` tkoenig at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jb at gcc dot gnu dot org @ 2008-05-09  6:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jb at gcc dot gnu dot org  2008-05-09 06:15 -------
Another solution is to have status flags for allocated and associated in the
descriptor, IIRC at least Pathscale does this.

Aren't there actually free bits left in the dtype flag that gfortran could use,
without requiring to change the descriptor?


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (5 preceding siblings ...)
  2008-05-09  6:16 ` jb at gcc dot gnu dot org
@ 2008-05-09 18:35 ` tkoenig at gcc dot gnu dot org
  2008-05-11 20:30 ` tkoenig at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-09 18:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from tkoenig at gcc dot gnu dot org  2008-05-09 18:34 -------
(In reply to comment #6)
> Another solution is to have status flags for allocated and associated in the
> descriptor, IIRC at least Pathscale does this.
> 
> Aren't there actually free bits left in the dtype flag that gfortran could use,
> without requiring to change the descriptor?

We will need to change the descriptor to fix PR 35718.  Unfortunately,
dtype shares space with the size, so by introducing additional bits
we would be incompatible, and restrict the size of derived types further.

Time for a "what we want to fix with the new array descriptor"
meta-PR?


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (6 preceding siblings ...)
  2008-05-09 18:35 ` tkoenig at gcc dot gnu dot org
@ 2008-05-11 20:30 ` tkoenig at gcc dot gnu dot org
  2008-05-11 20:40 ` tkoenig at gcc dot gnu dot org
  2008-05-12 11:28 ` jb at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-11 20:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from tkoenig at gcc dot gnu dot org  2008-05-11 20:29 -------
Subject: Bug 35719

Author: tkoenig
Date: Sun May 11 20:28:52 2008
New Revision: 135187

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135187
Log:
2008-05-11  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/35719
        * trans.c (gfc_call_malloc): If size equals zero, allocate one
        byte; don't return a null pointer.

2008-05-11  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/35719
        * gfortran.dg/associated_5.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/associated_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (7 preceding siblings ...)
  2008-05-11 20:30 ` tkoenig at gcc dot gnu dot org
@ 2008-05-11 20:40 ` tkoenig at gcc dot gnu dot org
  2008-05-12 11:28 ` jb at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-05-11 20:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from tkoenig at gcc dot gnu dot org  2008-05-11 20:39 -------
Fixed on trunk.

I don't think this really needs to be fixed on 4.3, so
I am closing this.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to fail|                            |4.3.1
      Known to work|                            |4.4.0
         Resolution|                            |FIXED


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


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

* [Bug fortran/35719] pointer to zero sized array not associated
  2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
                   ` (8 preceding siblings ...)
  2008-05-11 20:40 ` tkoenig at gcc dot gnu dot org
@ 2008-05-12 11:28 ` jb at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jb at gcc dot gnu dot org @ 2008-05-12 11:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jb at gcc dot gnu dot org  2008-05-12 11:27 -------
>Time for a "what we want to fix with the new array descriptor"
>meta-PR?

I started a wiki page for this, with a few issues from the top of my head:
http://gcc.gnu.org/wiki/ArrayDescriptorUpdate


-- 


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


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

end of thread, other threads:[~2008-05-12 11:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-27 16:14 [Bug fortran/35719] New: pointer to zero sized array not associated dick dot hendrickson at gmail dot com
2008-03-27 16:54 ` [Bug fortran/35719] " burnus at gcc dot gnu dot org
2008-05-04 21:29 ` tkoenig at gcc dot gnu dot org
2008-05-05  5:47 ` burnus at gcc dot gnu dot org
2008-05-05 18:24 ` tkoenig at gcc dot gnu dot org
2008-05-06 21:25 ` tkoenig at gcc dot gnu dot org
2008-05-09  6:16 ` jb at gcc dot gnu dot org
2008-05-09 18:35 ` tkoenig at gcc dot gnu dot org
2008-05-11 20:30 ` tkoenig at gcc dot gnu dot org
2008-05-11 20:40 ` tkoenig at gcc dot gnu dot org
2008-05-12 11:28 ` jb 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).