public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: <sgk@troutmask.apl.washington.edu>,
	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 12:07:43 +0100	[thread overview]
Message-ID: <34e0f9e6-ebb8-ce86-ea11-08b37e5be1f8@codesourcery.com> (raw)
In-Reply-To: <CAFiYyc0e0ES-Tp5bPuMwBT1FxRf2+QEtQzz+9dLr7VHr-ArwCg@mail.gmail.com>

On 20.02.23 11:41, Richard Biener wrote:
> Generally SAVE_EXPR is used to make sure an expression is only evaluated
> once.  It's DECL_EXPR that ensures something is evaluated early
> and available.  So generally "unwrapping" a SAVE_EXPR looks dangerous
> to me unless the SAVE_EXPR is really never necessary.

For VLA-kind of variables, SAVE_EXPR makes sense
(code wise: if '!deferred') - and that use in gfortran
should remain unchanged.


However, Fortran also has deferred-length variables where one has:

character(len=:), pointer :: str
! ...
allocate(character(len=42) :: str)
!...
end


which has the dump:

   integer(kind=8) .str;
   character(kind=1)[1:.str] * str;

   str = (character(kind=1)[1:.str] *) __builtin_malloc (42);
   .str = 42;

The length variable is - a bit oddly - linked to the
data variable its TREE_TYPE - i.e. via the upper bound for
the domain / TYPE_SIZE / TYPE_SIZE_UNIT.

Currently, it happens that the SAVE_EXPR is used, e.g.
   size = D.1234;  // which D.1234 is the SAVE_EXPR
instead of the current value
   size = .str;
which leads to wrong results. As '.str' is an aritificial
variable, the issue of a user modifying the value does not exist.

* * *

As mentioned in the TODO for 'deferred', I think we really want
to have NULL as upper value for the domain for the type, but that
requires literally hundred of changes to the compiler, which
I do not want to due during Stage 4, but that are eventually
required.* — In any case, this patch fixes some of the issues
in the meanwhile.

Tobias

* The number of deferred-length bugs is really huge; especially when
used with derived types.

-----------------
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

  reply	other threads:[~2023-02-20 11:07 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
2023-02-20  7:24     ` Steve Kargl
2023-02-20 10:41     ` Richard Biener
2023-02-20 11:07       ` Tobias Burnus [this message]
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=34e0f9e6-ebb8-ce86-ea11-08b37e5be1f8@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=paul.richard.thomas@gmail.com \
    --cc=richard.guenther@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).