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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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 ` burnus at gcc dot gnu dot org
  2009-06-16 21:33 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-16  8:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2009-06-16 08:19 -------
(In reply to comment #0)
> 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.

And for scalar dummy arguments: As one may not pass an array (section) actual
argument to a scalar dummy argument, that should work.

TODO 1: Confirm that the argument storage association is indeed new in F2003
and decide whether the result of -fbounds-check should really depend on
-std=f95.

TODO 2: Check whether the -std=f95 dependence should be noted somehow in the
-fcheck section of invoke.texi.

TODO 3: Add test cases - one with -fno-whole-file ;-)

Draft patch (sorry, tabs don't paste):

Index: trans-decl.c
===================================================================
--- trans-decl.c        (revision 148518)
+++ trans-decl.c        (working copy)
@@ -3835,7 +3835,11 @@ add_argument_checking (stmtblock_t *bloc

        /* For POINTER, ALLOCATABLE and assumed-shape dummy arguments, the
           string lengths must match exactly.  Otherwise, it is only required
-          that the actual string length is *at least* the expected one.  */
+          that the actual string length is *at least* the expected one.
+          Fortran 2003 allows for argument storage association thus for the
+          latter case we only add the test for -std=f95 or if the dummy
+          argument is not an array, which implies that the actual argument
+          is also a scalar.  */
        if (fsym->attr.pointer || fsym->attr.allocatable
            || (fsym->as && fsym->as->type == AS_ASSUMED_SHAPE))
          {
@@ -3843,6 +3847,9 @@ add_argument_checking (stmtblock_t *bloc
            message = _("Actual string length does not match the declared one"
                        " for dummy argument '%s' (%ld/%ld)");
          }
+       else if ((fsym->as && fsym->as->rank != 0)
+                && (gfc_option.allow_std & GFC_STD_F2003) != 0)
+         continue;
        else
          {
            comparison = LT_EXPR;


-- 


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


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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-16 21:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2009-06-16 21:32 -------
Wrong quote - and wrong statement. It is not a F2003 change, but already in
F95.

Fortran 95 has (12.4.1.4 Sequence association)

"If the actual argument is of type default character and is an array
 expression, array element, or array element substring designator, the
 element sequence consists of the character storage units beginning with
 the first storage unit of the actual argument and continuing to the end
 of the array. The character storage units of an array element substring
 designator are viewed as array elements consisting of consecutive groups
 of character storage units having the character length of the dummy
 array."

Fortran 2003 has in 12.4.1.5 the same (except of allowing C_CHAR) and
then continues with

"If the actual argument is of type default character or of type character
 with the C character kind, and is a scalar that is not an array element
 or array element substring designator, the element sequence consists of
 the storage units of the actual argument."

(The addition is not important for us, but it allows to pass "a string"
 to a BIND(C) procedure which has "character(len=1):: str(*)".)

 * * *

The crucial part is the "dummy array" at the end of the first excerpt.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |burnus at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-06-16 21:33:00
               date|                            |


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


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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-18  9:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2009-06-18 09:00 -------
Patch: http://gcc.gnu.org/ml/fortran/2009-06/msg00188.html


-- 


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


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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-20 18:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2009-06-20 18:07 -------
Subject: Bug 40452

Author: burnus
Date: Sat Jun 20 18:07:10 2009
New Revision: 148750

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148750
Log:
2009-06-20  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40452
        * trans-decl.c (add_argument_checking): Disable bounds check
        for allowed argument storage association.

2009-06-20  Tobias Burnus  <burnus@net-b.de>

        PR fortran/40452
        * gfortran.dg/bounds_check_strlen_9.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_strlen_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2010-06-04  7:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from tkoenig at gcc dot gnu dot org  2010-06-04 07:15 -------
Can we close this?


-- 


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


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

* [Bug fortran/40452] -fbounds-check: False positive due to ignoring storage association
  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
                   ` (4 preceding siblings ...)
  2010-06-04  7:16 ` tkoenig at gcc dot gnu dot org
@ 2010-06-04 12:22 ` burnus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-06-04 12:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2010-06-04 12:22 -------
Yes, we can CLOSE the bug as FIXED.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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).