This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Tobias Burnus wrote:
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?

Ok, thanks for the patch! I think it is better to leave it without -fbounds-check test as you did in the patch.


Yours,
Daniel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]