[Patch,Fortran] PR 40383 false positive with -fcheck=bounds

Tobias Burnus burnus@net-b.de
Mon Jun 15 21:28:00 GMT 2009


Since the fix of PR 37746, gfortran's -fbounds-check is
able to diagnose actual arguments with too short string lengths
if the dummy argument has an explicit length, e.g. passing

  call proc("abc")
to
  subroutine sub(a)
    character(len=4) :: a

The testing is done by comparing the argument:
  if (_a < 4) runtime_error
For optional arguments, there is an additional condition.

That works quite nice, but it fails for:

  subroutine sub(a,b)
    character(len=4), optional :: a, b

The reason is that the argument checking is done by saving
the tree of the hidden length as formal->ts.cl->passed_length.
However, in the example above the a->ts.cl and b->ts.cl is
exactly the same. Thus only _b is saved as
formal->ts.cl->passed_length. Consequently, there will be two
checks for _b but none for _a. That way one misses bound
violations - and if optional arguments are involved (see PR)
one also gets false positives.

Solution: One needs to copy cl. One could do this relatively
early, but to reduce the number of backend declarations
(which are bad as the types are the same), I did it quite late
in trans-decl.c. One could guard it with a check for -fcheck=bounds
as it is only used with this flag.

Bootstrapped and regtested on x86-64-linux.
OK for the trunk?

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: passed-charlen.diff
Type: text/x-patch
Size: 2403 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090615/7324b36a/attachment.bin>


More information about the Fortran mailing list