From: Tobias Burnus <tobias@codesourcery.com>
To: <sgk@troutmask.apl.washington.edu>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>,
fortran <fortran@gcc.gnu.org>,
Paul Richard Thomas <paul.richard.thomas@gmail.com>
Subject: Re: [Patch] Fortran: Avoid SAVE_EXPR for deferred-len char types
Date: Mon, 20 Feb 2023 07:56:14 +0100 [thread overview]
Message-ID: <af158361-68fa-6628-be39-cd8a6ee2b2f8@codesourcery.com> (raw)
In-Reply-To: <Y++q7cf34jsOeRST@troutmask.apl.washington.edu>
On 17.02.23 17:27, Steve Kargl wrote:
> On Fri, Feb 17, 2023 at 12:13:52PM +0100, Tobias Burnus wrote:
>> OK for mainline?
> Short version: no.
Would you mind to write a reasoning beyond only a single word?
>> subroutine foo(n)
>> integer :: n
>> integer :: array(n*5)
>> integer :: my_len
>> ...
>> my_len = 5
>> block
>> character(len=my_len, kind=4) :: str
>>
>> my_len = 99
>> print *, len(str) ! still shows 5 - not 99
>> end block
>> end
> Are you sure about the above comment?
Yes - for three reasons:
* On the what-feels-right side: It does not make any sense to print
any other value than 5 given that 'str' has been declared with len = 5.
* On the GCC side, the SAVE_EXPR ensures that the length is evaluated
early and then "saved" to ensure its original value is available
* The quoted text from the standard implies that this is what
should happen.
Why do you think that printing "5" is wrong? GCC does so since
years; it still does so with my patch.
Hence, can you elaborate? And also state which value you did expect instead?
* * *
The patch itself is about *deferred* length parameters, i.e.
'len=:', and thus for code like:
character(len=:), pointer :: str
...
allocate(character(len=4) :: str)
print *, len(str) ! should print 4
...
allocate(character(len=99) :: str)
print *, len(str) ! should now print 99
...
Currently, the SAVE_EXPR causes that the original value might
get used, which is often 0 (by chance 0 initialized) or some
random value like 57385973, depending what on what was on the
stack before. - There are more issues with deferred strings,
but at least one is solved by not having a SAVE_EXPR for
deferred-length character strings.
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
next prev parent reply other threads:[~2023-02-20 10:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 11:13 Tobias Burnus
2023-02-17 16:27 ` Steve Kargl
2023-02-20 6:56 ` Tobias Burnus [this message]
2023-02-20 7:24 ` Steve Kargl
2023-02-20 10:41 ` Richard Biener
2023-02-20 11:07 ` Tobias Burnus
2023-02-20 11:15 ` Jakub Jelinek
2023-02-20 11:48 ` Tobias Burnus
2023-02-20 11:56 ` Jakub Jelinek
2023-02-20 12:46 ` Richard Biener
2023-02-20 16:23 ` Tobias Burnus
2023-02-21 7:30 ` Richard Biener
2023-02-21 9:44 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af158361-68fa-6628-be39-cd8a6ee2b2f8@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=paul.richard.thomas@gmail.com \
--cc=sgk@troutmask.apl.washington.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).