Request for comment: Character substring lengths

Tobias Schlüter Tobias.Schlueter@physik.uni-muenchen.de
Mon May 7 16:50:00 GMT 2007


Tobias Burnus wrote:
 > -         if (substring)
 > +         /* If the substring has EXPR_CONSTANT size, the substring
 > +            length is set in resolve_substring.  */

Not necessarily, for what I can tell.  Quoting from my patch submission 
for PR31266 <http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00695.html>:
"""
I decided to omit the copying only if a substring reference follows.
I.e. for something like var%comp the string length of the whole
expression would be explicit.  This has the advantage that
LEN(var%comp) can be evaluated in the frontend.  It is noteworthy that
the scalarizer manages to determine the string length even of the
substring reference, i.e. LEN(var%comp(1:2)) would appear unevaluated
in the -fdump-parse-tree dump, but it would be reduced to the value 2
in the -fdump-tree-original dump.  If someone understands where this
happens, I think it would be a good idea to move this evaluation
further to the front, so that e.g. the truncation warnings could be
given in more cases.
"""

> Tobias Schlüter wrote:
> 
>>Indeed, I found about this recently when I prepared my last series of
> 
> patches.
> 
>>I think I wrote something about this in one of my patch submissions
> 
> 
> You don't mean the following, do you? Or do you?
> 
> 
>>I just had the following idea for a beginner's project:  we could get
>>rid of these double-checks by having a global gfc_charlen
>>gfc_empty_cl, whose length member would be initialized to NULL
>>(happens automatically, as it's in global storage).  Then, instead of
>>zeroing ts.cl if the charlen is not known, we would make it point to
>>&gfc_empty_cl.  Then ts.cl would never be NULL, and ts.cl->length ==
>>NULL would be necessary and sufficient for an unknown length. 
> 
> 
> But I don't see how it would help.

No I didn't mean that.  I already followed up that my findings amounted 
to what you said above.  The gfc_empty_cl thing was meant to simplify 
all those checks -- ts.cl would never be NULL and ts.cl == gfc_empty_cl 
would mean just that.

Cheers,
- Tobi



More information about the Fortran mailing list