public inbox for gcc-regression@sourceware.org
help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: Jan Hubicka <hubicka@kam.mff.cuni.cz>,
	sunil.k.pandey <skpandey@sc.intel.com>,
	fortran <fortran@gcc.gnu.org>
Cc: <gcc-regression@gcc.gnu.org>, <gcc-patches@gcc.gnu.org>,
	<tobias@codesourcery.com>
Subject: [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
Date: Sat, 16 Oct 2021 20:48:00 +0200	[thread overview]
Message-ID: <bd183830-0e3f-a1c9-9c6c-97005cced372@codesourcery.com> (raw)
In-Reply-To: <20211016182354.GE64164@kam.mff.cuni.cz>

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

Hi Honza,

On 16.10.21 20:23, Jan Hubicka via Gcc-patches wrote:
>> FAIL: gfortran.dg/deferred_type_param_6.f90   -O1  execution test
>> FAIL: gfortran.dg/deferred_type_param_6.f90   -Os  execution test
> Sorry for the breakage.  This time it seems like bug in Fortran FE
> which was previously latent:
>
> __attribute__((fn spec (". . R ")))
> void subfunc (character(kind=1)[1:..__result] * & __result, integer(kind=8) * .__result)

...

Fortran has for a long time 'character(len=5), allocatable" or
"character(len=*)". In the first case, the "5" can be ignored as both
caller and callee know the length. In the second case, the length is
determined by the argument, but it cannot be changed.

Since a not-that-short while, 'len=:' together with allocatable/pointer
is supported.

In the latter case, the value can be change when the array
association/allocation is changed.

I attached a patch, which was not tested. I am not quite sure whether
the pointer address can actually escape or not - I think cannot but I
played safe.

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

[-- Attachment #2: fnspec.diff --]
[-- Type: text/x-patch, Size: 910 bytes --]

Fortran: Fix fn spec for character-returning functions

gcc/fortran/ChangeLog
	* trans-types.c (create_fn_spec): For character-returning functions,
	set the hidden string-length argument to 'R' only when the "len=:",
	i.e. deferred length which goes alongside with allocatable/pointer.

diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 220976babb8..637d2c71d01 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3008,7 +3008,14 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
 	}
       if (sym->ts.type == BT_CHARACTER)
 	{
-	  spec[spec_len++] = 'R';
+	  if (!sym->ts.u.cl->length
+	      && ((sym->attr.allocatable && sym->attr.target)
+		  || sym->attr.pointer))
+	    spec[spec_len++] = '.';
+	  if (!sym->ts.u.cl->length && sym->attr.allocatable)
+	    spec[spec_len++] = 'w';
+	  else
+	    spec[spec_len++] = 'R';
 	  spec[spec_len++] = ' ';
 	}
     }

  reply	other threads:[~2021-10-16 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16 16:11 [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64 sunil.k.pandey
2021-10-16 18:23 ` Jan Hubicka
2021-10-16 18:48   ` Tobias Burnus [this message]
2021-10-16 18:54     ` [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64) Jan Hubicka
2021-10-19 14:49       ` [Patch, committed] Fortran: Fix 'fn spec' for deferred character length " Tobias Burnus
2021-10-18  9:51   ` [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64 Richard Biener

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=bd183830-0e3f-a1c9-9c6c-97005cced372@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc-regression@gcc.gnu.org \
    --cc=hubicka@kam.mff.cuni.cz \
    --cc=skpandey@sc.intel.com \
    /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).