This is the mail archive of the
mailing list for the GCC project.
Re: [Patch,Fortran] PR 40383 false positive with -fcheck=bounds
- From: Daniel Kraft <d at domob dot eu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: fortran at gcc dot gnu dot org
- Date: Tue, 16 Jun 2009 07:45:10 +0200
- Subject: Re: [Patch,Fortran] PR 40383 false positive with -fcheck=bounds
- References: <20090615212821.GA25881@net-b.de>
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
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:
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.