public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/40452] New: -fbounds-check: False positive due to ignoring storage association
Date: Mon, 15 Jun 2009 21:52:00 -0000 [thread overview]
Message-ID: <bug-40452-13404@http.gcc.gnu.org/bugzilla/> (raw)
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
next reply other threads:[~2009-06-15 21:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-15 21:52 burnus at gcc dot gnu dot org [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-40452-13404@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).