Re: [PATCH] Fortran - Error compiling PDT Type-bound Procedures [PR82943/86148/86268]

2024-02-27 Thread Alexander Westbrooks
Harald,

Jerry helped me figure out my editor settings so that I could fix
whitespace and formatting issues in my code. With my editor configured
correctly, I saw that my code was not conforming to coding standards
as I previously thought it was. I have fixed those things and updated
my patch. Thank you for your patience.

Let me know if this is okay to push to the trunk.

Thanks,

Alexander Westbrooks

On Sun, Feb 25, 2024 at 2:40 PM Alexander Westbrooks
 wrote:
>
> Harald,
>
> Thank you for reviewing my code. I've been doing research and debugging to 
> investigate the error thrown by Intel and NAG for the deferred parameter in 
> the dummy variable declaration. I found where the problem was and added the 
> fix as part of my patch. I've attached the patch as a file, which also 
> includes your feedback and suggested fixes. I've updated the test case 
> pdt_37.f03 to check for the POINTER or ALLOCATABLE error as you suggested.
>
> All regression tests pass, including the new ones, after including the fix 
> for the POINTER or ALLOCATABLE error for CLASS declarations of PDTs when 
> deferred length parameters are used. This was tested on WSL 2, with Ubuntu 
> 20.04 distro.
>
> Is this okay to push to the trunk?
>
> Thanks,
>
> Alexander Westbrooks
>
>
> On Sun, Feb 11, 2024 at 2:11 PM Harald Anlauf  wrote:
>>
>> Hi Alex,
>>
>> I've been unable to apply your patch to my local trunk, likely due to
>> whitespace issues my newsreader handles differently from your site.
>> I see it inline instead of attached.
>>
>> A few general remarks:
>>
>> Please follow the general recommendation regarding style if possible,
>> see https://www.gnu.org/prep/standards/standards.html#Formatting
>> regarding formatting/whitespace use (5.1) and comments (5.2)
>>
>> Also, when an error message text spans multiple lines, please place the
>> whitespace at the end of a line, not at the beginning of the new one:
>>
>> > +  if ( resolve_bindings_derived->attr.pdt_template &&
>> > +   !gfc_pdt_is_instance_of(resolve_bindings_derived,
>> > +   CLASS_DATA(me_arg)->ts.u.derived))
>> > +{
>> > +  gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of"
>> > +" the parametric derived-type %qs", me_arg->name, proc->name,
>>
>>gfc_error ("Argument %qs of %qs with PASS(%s) at %L must be of "
>>   "the parametric derived-type %qs", me_arg->name,
>> proc->name,
>>
>> > +me_arg->name, , resolve_bindings_derived->name);
>> > +  goto error;
>> > +}
>>
>> The following change is almost unreadable: the lnegthy comment is split
>> over three parts and almost hides the code.  Couldn't this be combined
>> into one comment before the function?
>>
>> > diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
>> > index fddf68f8398..11f4bac0415 100644
>> > --- a/gcc/fortran/symbol.cc
>> > +++ b/gcc/fortran/symbol.cc
>> > @@ -5172,6 +5172,35 @@ gfc_type_is_extension_of (gfc_symbol *t1, gfc_symbol
>> > *t2)
>> > return gfc_compare_derived_types (t1, t2);
>> >   }
>> >
>> > +/* Check if a parameterized derived type t2 is an instance of a PDT
>> > template t1 */
>> > +
>> > +bool
>> > +gfc_pdt_is_instance_of(gfc_symbol *t1, gfc_symbol *t2)
>> > +{
>> > +  if ( !t1->attr.pdt_template || !t2->attr.pdt_type )
>> > +return false;
>> > +
>> > +  /*
>> > +in decl.cc, gfc_get_pdt_instance, a pdt instance is given a 3
>> > character prefix "Pdt", followed
>> > +by an underscore list of the kind parameters, up to a maximum of 8.
>> > +
>> > +So to check if a PDT Type corresponds to the template, extract the
>> > core derive_type name,
>> > +and then see if it is type compatible by name...
>> > +
>> > +For example:
>> > +
>> > +Pdtf_2_2 -> extract out the 'f' -> see if the derived type 'f' is
>> > compatible with symbol t1
>> > +  */
>> > +
>> > +  // Starting at index 3 of the string in order to skip past the 'Pdt'
>> > prefix
>> > +  // Also, here the length of the template name is used in order to avoid
>> > the
>> > +  // kind parameter suffixes that are placed at the end of PDT instance
>> > names.
>> > +  if ( !(strncmp(&(t2->name[3]), t1->name, strlen(t1->name)) == 0) )
>> > +return false;
>> > +
>> > +  return true;
>> > +}
>> > +
>> >
>> >   /* Check if two typespecs are type compatible (F03:5.1.1.2):
>> >  If ts1 is nonpolymorphic, ts2 must be the same type.
>>
>> The following testcase tests for errors.  I tried Intel and NAG on it
>> after commenting the 'contains' section of the type desclaration.
>> Both complained about subroutine deferred_len_param, e.g.
>>
>> Intel:
>> A colon may only be used as a type parameter value in the declaration of
>> an object that has the POINTER or ALLOCATABLE attribute.   [THIS]
>>  class(param_deriv_type(:)), intent(inout) :: this
>>
>> NAG:
>> Entity THIS of type PARAM_DERIV_TYPE(A=:) has a deferred length type
>> parameter but is not a data pointer or allocatable
>>
>> Do we 

Re: [PATCH] Fortran testsuite: fix invalid Fortran in testcase

2024-02-27 Thread Jerry D

On 2/27/24 1:00 PM, Harald Anlauf wrote:

Dear all,

the attached patch fixes invalid Fortran in testcase
gfortran.dg/pr101026.f, which might prohibit progress
in fixing pr111781.  (Note that the testcase was for a
tree-optimizer issue, not the Fortran frontend.)

OK for mainline?

Will commit within 24h unless there are comments.

Thanks,
Harald



OK, simple.


Rejects ASSOCIATE and a complex part%ref when target is a function

2024-02-27 Thread Steve Kargl
All,

Consider,

! { dg-do run }
program foo
   implicit none
   real y
   associate (x => log(cmplx(-1,0)))
  y = x%im
  if (int(100*y)-314 /= 0) stop 1
   end associate
end program

% gfcx -c a.f90
a.f90:6:13:

6 |   y = x%im
  | 1
Error: Symbol 'x' at (1) has no IMPLICIT type


'x' has the type of thi selector, which is COMPLEX.
I have created the following bug report

https://gcc.gnu.org/pipermail/gcc-bugs/2024-February/855452.html

and attached a patch that fixes the problem.  The patch has been
regression tested against x86_64-*-freebsd.  Please commit.

-- 
Steve


[PATCH] Fortran testsuite: fix invalid Fortran in testcase

2024-02-27 Thread Harald Anlauf
Dear all,

the attached patch fixes invalid Fortran in testcase
gfortran.dg/pr101026.f, which might prohibit progress
in fixing pr111781.  (Note that the testcase was for a
tree-optimizer issue, not the Fortran frontend.)

OK for mainline?

Will commit within 24h unless there are comments.

Thanks,
Harald

From 75724b6b42a1c46383d8e6deedbfb8d2ebd0fa12 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Tue, 27 Feb 2024 21:51:53 +0100
Subject: [PATCH] Fortran testsuite: fix invalid Fortran in testcase

gcc/testsuite/ChangeLog:

	* gfortran.dg/pr101026.f: Let variables used in specification
	expression be passed as dummy arguments
---
 gcc/testsuite/gfortran.dg/pr101026.f | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gfortran.dg/pr101026.f b/gcc/testsuite/gfortran.dg/pr101026.f
index 9576d8802ca..e05e21c898a 100644
--- a/gcc/testsuite/gfortran.dg/pr101026.f
+++ b/gcc/testsuite/gfortran.dg/pr101026.f
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! { dg-options "-Ofast -frounding-math" }
-  SUBROUTINE PASSB4 (CC,CH)
+  SUBROUTINE PASSB4 (CC,CH,IDO,L1)
   DIMENSION CC(IDO,4,L1), CH(IDO,L1,*)
  DO 103 I=2,IDO,2
 TI4 = CC0-CC(I,4,K)
--
2.35.3