public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
       [not found] ` <20211016182354.GE64164@kam.mff.cuni.cz>
@ 2021-10-16 18:48   ` Tobias Burnus
  2021-10-16 18:54     ` Jan Hubicka
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2021-10-16 18:48 UTC (permalink / raw)
  To: Jan Hubicka, sunil.k.pandey, fortran; +Cc: gcc-regression, gcc-patches, tobias

[-- 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++] = ' ';
 	}
     }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
  2021-10-16 18:48   ` [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64) Tobias Burnus
@ 2021-10-16 18:54     ` Jan Hubicka
  2021-10-19 14:49       ` [Patch, committed] Fortran: Fix 'fn spec' for deferred character length " Tobias Burnus
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Hubicka @ 2021-10-16 18:54 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: sunil.k.pandey, fortran, gcc-patches, gcc-regression

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

> 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++] = ' ';

Thanks a lot! I was just looking into that function and was quite
confused on what is going there. Are you going to commit the patch?
Also escaping is quite important bit of information so it would be
good to figure out if it really can escape rather than playing safe.

Honza
>  	}
>      }


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64
       [not found] ` <20211016182354.GE64164@kam.mff.cuni.cz>
  2021-10-16 18:48   ` [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64) Tobias Burnus
@ 2021-10-18  9:51   ` Richard Biener
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Biener @ 2021-10-18  9:51 UTC (permalink / raw)
  To: Jan Hubicka, fortran
  Cc: sunil.k.pandey, gcc-regression, GCC Patches, Tobias Burnus

On Sat, Oct 16, 2021 at 8:24 PM Jan Hubicka via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
> >
> > 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)
> {
>   # PT = nonlocal
>   character(kind=1)[1:..__result] * & __result_3(D) = __result;
>   # PT = nonlocal null
>   integer(kind=8) * .__result_5(D) = .__result;
>   integer(kind=4) _1;
>
>   <bb 2> [local count: 1073741824]:
>   *__result_3(D) = &fifec;
>   # USE = nonlocal escaped { D.4230 } (nonlocal, escaped)
>   _1 = _gfortran_compare_string (5, &fifec, 5, &"FIVEC"[1]{lb: 1 sz: 1});
>   if (_1 != 0)
>     goto <bb 3>; [0.04%]
>   else
>     goto <bb 4>; [99.96%]
>
>   <bb 3> [local count: 429496]:
>   # USE = nonlocal escaped null
>   # CLB = nonlocal escaped null
>   _gfortran_stop_numeric (10, 0);
>
>   <bb 4> [local count: 1073312329]:
>   *.__result_5(D) = 5;
>   return;
> }
>
> The fnspec ". . R " specifies that .__result is readonly however we
> have:
>   *.__result_5(D) = 5;
>
> I am not sure I understand fortran FE well enough to figure out why
> it is set so.  The function is declared as:
>
>   function subfunc() result(res)
>     character(len=:), pointer :: res
>     res => fifec
>     if (len(res) /= 5) STOP 9
>     if (res /= "FIVEC") STOP 10
>   end function subfunc
>
> and we indeed optimize load of the result:
> -  # USE = nonlocal escaped { D.4252 D.4254 } (nonlocal, escaped)
> -  # CLB = nonlocal escaped { D.4254 } (escaped)
> +  # USE = nonlocal escaped
> +  # CLB = { D.4254 }
>    subfunc (&pstr.5, &slen.4);
> -  .s2_34 = slen.4;
> -  # PT = nonlocal escaped null { D.4254 } (escaped)
> -  s2_35 = pstr.5;
>    pstr.5 ={v} {CLOBBER};
>
> and I think tat is what breaks the testcase (I also verified that
> ignoring the fnspec 'R' fixes it).

The FE code adding the fnspec probably fails to consider the
separately passed length of the string result?

Can you open a bugreport please?

Richard.

> Honza
> >
> > with GCC configured with
> >
> > ../../gcc/configure --prefix=/local/skpandey/gccwork/toolwork/gcc-bisect-master/master/r12-4457/usr --enable-clocale=gnu --with-system-zlib --with-demangler-in-ld --with-fpmath=sse --enable-languages=c,c++,fortran --enable-cet --without-isl --enable-libmpx x86_64-linux --disable-bootstrap
> >
> > To reproduce:
> >
> > $ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=gfortran.dg/deferred_type_param_6.f90 --target_board='unix{-m32}'"
> > $ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=gfortran.dg/deferred_type_param_6.f90 --target_board='unix{-m32\ -march=cascadelake}'"
> > $ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=gfortran.dg/deferred_type_param_6.f90 --target_board='unix{-m64}'"
> > $ cd {build_dir}/gcc && make check RUNTESTFLAGS="dg.exp=gfortran.dg/deferred_type_param_6.f90 --target_board='unix{-m64\ -march=cascadelake}'"
> >
> > (Please do not reply to this email, for question about this report, contact me at skpgkp2 at gmail dot com)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Patch, committed] Fortran: Fix 'fn spec' for deferred character length (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
  2021-10-16 18:54     ` Jan Hubicka
@ 2021-10-19 14:49       ` Tobias Burnus
  2021-10-30 23:33         ` Bernhard Reutner-Fischer
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Burnus @ 2021-10-19 14:49 UTC (permalink / raw)
  To: Jan Hubicka, Tobias Burnus
  Cc: sunil.k.pandey, fortran, gcc-patches, gcc-regression

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

On 16.10.21 20:54, Jan Hubicka wrote:
> I wrote:
>> 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.
>> ...
>> +      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';
> Also escaping is quite important bit of information so it would be
> good to figure out if it really can escape rather than playing safe.

The pointer to the string length variable itself does not escape,
only its integer string value:

subroutine foo(x)
   character(len=:), pointer :: x
   character(len=:), pointer :: y
   y => x
has in the dump:
   .y = *_x;
   y = (character(kind=1)[1:.y] *) *x;

Thus, 'w' can always be used.

Committed as obvious as r12-4511-gff0eec94e87dfb7dc387f120ca5ade2707aecf50

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: committed.diff --]
[-- Type: text/x-patch, Size: 1135 bytes --]

commit ff0eec94e87dfb7dc387f120ca5ade2707aecf50
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Oct 19 16:38:56 2021 +0200

    Fortran: Fix 'fn spec' for deferred character length
    
    Shows now up with gfortran.dg/deferred_type_param_6.f90 due to more ME
    optimizations, causing fails without this commit.
    
    gcc/fortran/ChangeLog:
    
            * trans-types.c (create_fn_spec): For allocatable/pointer
            character(len=:), use 'w' not 'R' as fn spec for the length dummy
            argument.
---
 gcc/fortran/trans-types.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 50fceebc941..42778067dbe 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3014,7 +3014,11 @@ 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.pointer))
+	    spec[spec_len++] = 'w';
+	  else
+	    spec[spec_len++] = 'R';
 	  spec[spec_len++] = ' ';
 	}
     }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch, committed] Fortran: Fix 'fn spec' for deferred character length (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64)
  2021-10-19 14:49       ` [Patch, committed] Fortran: Fix 'fn spec' for deferred character length " Tobias Burnus
@ 2021-10-30 23:33         ` Bernhard Reutner-Fischer
  0 siblings, 0 replies; 5+ messages in thread
From: Bernhard Reutner-Fischer @ 2021-10-30 23:33 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: rep.dot.nop, fortran

On Tue, 19 Oct 2021 16:49:02 +0200
Tobias Burnus <tobias@codesourcery.com> wrote:

> On 16.10.21 20:54, Jan Hubicka wrote:
> > I wrote:
> >> 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.
> >> ...
> >> +      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';
> > Also escaping is quite important bit of information so it would be
> > good to figure out if it really can escape rather than playing safe.
> 
> The pointer to the string length variable itself does not escape,
> only its integer string value:
> 
> subroutine foo(x)
>    character(len=:), pointer :: x
>    character(len=:), pointer :: y
>    y => x
> has in the dump:
>    .y = *_x;
>    y = (character(kind=1)[1:.y] *) *x;
> 
> Thus, 'w' can always be used.
> 
> Committed as obvious as r12-4511-gff0eec94e87dfb7dc387f120ca5ade2707aecf50

I guess we don't have intrinsics with allocatable or pointer character
types?
Just asking because this fix went to trans-types.c::create_fn_spec but
we also construct fn spec strings in trans-intrinsic.c::intrinsic_fnspec

In the former, the if (spec_len < sizeof (spec)) looks like it's
suboptimal, I'd rather not have this went unnoticed?

Maybe it would be worthwhile to have just one fnspec generator which is
used in both spots?
thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-30 23:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211016161130.731AF286470F@gskx-2.sc.intel.com>
     [not found] ` <20211016182354.GE64164@kam.mff.cuni.cz>
2021-10-16 18:48   ` [Patch] (was: Re: [r12-4457 Regression] FAIL: gfortran.dg/deferred_type_param_6.f90 -Os execution test on Linux/x86_64) Tobias Burnus
2021-10-16 18:54     ` Jan Hubicka
2021-10-19 14:49       ` [Patch, committed] Fortran: Fix 'fn spec' for deferred character length " Tobias Burnus
2021-10-30 23:33         ` Bernhard Reutner-Fischer
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

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