public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40452]  New: -fbounds-check: False positive due to ignoring storage association
@ 2009-06-15 21:52 burnus at gcc dot gnu dot org
  2009-06-16  8:19 ` [Bug fortran/40452] " burnus at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-15 21:52 UTC (permalink / raw)
  To: gcc-bugs

Follow up to PR 37746 / PR 40383. I believe the following program is valid due
to the storage association/argument association. However, with -fcheck=bounds
one gets:

At line 5 of file aa.f90
Fortran runtime error: Actual string length is shorter than the declared one
for dummy argument 'a' (2/4)

Note: If one changes the actual argument to ["ab"] or ["a","b"] both NAG f95
and gfortran are able to diagnose the problem at compile time. For the program
below, neither compilers gives a compile-time error/warning. (Nor does NAG with
-C=all give a run-time error.)


program test
  implicit none
  call sub(["ab", "cd"])
contains
  subroutine sub(a)
   character(len=4) :: a(1)
   print *, a(1)
  end subroutine sub
end program test



>From the standard (F2003, cf. 16.4.3 Storage association):

"In a storage association context [...] (3) A nonpointer scalar object of type
default character and character length len occupies len contiguous character
storage units; [...] (7) A nonpointer array occupies a sequence of contiguous
storage sequences, one for each array element, in array element order
(6.2.2.2); [...] A sequence of storage sequences forms a storage sequence."

(And a bit further down one finds a bit more to "argument association".)


The challenge is diagnose this properly. The problem is that the array size is
_not_ passed. One solution would be to enable the check only with -std=f95. I
believe the argument association is only allowed since Fortran 2003. Or one
does a proper argument checking by checking whether the argument is an array.
For this one needs -fcheck=call and save the arguments in some external
variable, then one checks whether the current procedure matches the procedure
where the global variable stores the argument information - and then uses this
information for the array check. Sorry, I don't have any better idea at the
moment.

Note: The primary use of the argument association is:
  call c_func("abc")
with
  subroutine c_func(str) bind(C)
    character(len=1,kind=c_char) :: str(*)
as otherwise one had to use 'call c_func(["a","b","c"])' which is awkward!


-- 
           Summary: -fbounds-check: False positive due to ignoring storage
                    association
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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


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

end of thread, other threads:[~2010-06-04 12:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-15 21:52 [Bug fortran/40452] New: -fbounds-check: False positive due to ignoring storage association burnus at gcc dot gnu dot org
2009-06-16  8:19 ` [Bug fortran/40452] " burnus at gcc dot gnu dot org
2009-06-16 21:33 ` burnus at gcc dot gnu dot org
2009-06-18  9:00 ` burnus at gcc dot gnu dot org
2009-06-20 18:07 ` burnus at gcc dot gnu dot org
2010-06-04  7:16 ` tkoenig at gcc dot gnu dot org
2010-06-04 12:22 ` 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).