diff mbox series

[fortran] PR97694 - ICE with optional assumed rank class(*) argument (and PR97723)

Message ID CAGkQGiLymqvz=TrfHLXLsDZ-vZQofPQK_OD1FBGa9sy0sMGFPA@mail.gmail.com
State New
Headers show
Series [fortran] PR97694 - ICE with optional assumed rank class(*) argument (and PR97723) | expand

Commit Message

Paul Richard Thomas Dec. 12, 2020, 10:38 a.m. UTC
Fortran: Fix some select rank issues [PR97694 and 97723].

Hi All,

Unlike select type, select rank selectors retain the allocatable attribute.
This is corrected by the chunk in check.c. Note the trailing whitespace
corrections. Resolution of select rank construct must be done in the same
way as select type and so the break has been added to ensure that the block
is resolved in resolve_select_rank. The final chunk prevents segfaults for
class associate variables that are optional dummies, since these apparently
are not adorned with the GFC_DECL_SAVED_DESCRIPTOR.

Regtests OK on FC31/x86_64 - OK for master?

Cheers

Paul

2020-12-12  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/97694
PR fortran/97723
* check.c (allocatable_check): Select rank temporaries are
permitted even though they are treated as associate variables.
* resolve.c (gfc_resolve_code): Break on select rank as well as
select type so that the block os resolved.
* trans-stmt.c (trans_associate_var): Class associate variables
that are optional dummies must use the backend_decl.

gcc/testsuite/
PR fortran/97694
PR fortran/97723
* gfortran.dg/select_rank_5.f90: New test.

Comments

Paul Richard Thomas Dec. 26, 2020, 4:37 p.m. UTC | #1
Ping!

On Sat, 12 Dec 2020 at 10:38, Paul Richard Thomas <
paul.richard.thomas@gmail.com> wrote:

> Fortran: Fix some select rank issues [PR97694 and 97723].
>
> Hi All,
>
> Unlike select type, select rank selectors retain the allocatable
> attribute. This is corrected by the chunk in check.c. Note the trailing
> whitespace corrections. Resolution of select rank construct must be done in
> the same way as select type and so the break has been added to ensure that
> the block is resolved in resolve_select_rank. The final chunk prevents
> segfaults for class associate variables that are optional dummies, since
> these apparently are not adorned with the GFC_DECL_SAVED_DESCRIPTOR.
>
> Regtests OK on FC31/x86_64 - OK for master?
>
> Cheers
>
> Paul
>
> 2020-12-12  Paul Thomas  <pault@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/97694
> PR fortran/97723
> * check.c (allocatable_check): Select rank temporaries are
> permitted even though they are treated as associate variables.
> * resolve.c (gfc_resolve_code): Break on select rank as well as
> select type so that the block os resolved.
> * trans-stmt.c (trans_associate_var): Class associate variables
> that are optional dummies must use the backend_decl.
>
> gcc/testsuite/
> PR fortran/97694
> PR fortran/97723
> * gfortran.dg/select_rank_5.f90: New test.
>
>
Thomas Koenig Dec. 26, 2020, 7:01 p.m. UTC | #2
Hi Paul,

> Ping!

OK.

Thanks a lot!

Best regards

	Thomas
Paul Richard Thomas Dec. 27, 2020, 3:02 p.m. UTC | #3
Hi Thomas,

Thanks for the OK. Pushed as to master as commit
r11-6346-gc4a678981572c12d158709ace0d3f23dd04cf217

Cheers

Paul


On Sat, 26 Dec 2020 at 19:01, Thomas Koenig <tkoenig@netcologne.de> wrote:

> Hi Paul,
>
> > Ping!
>
> OK.
>
> Thanks a lot!
>
> Best regards
>
>         Thomas
>
Jerry D Dec. 28, 2020, 2:13 a.m. UTC | #4
LGTM Paul, go for it.

On 12/26/20 8:37 AM, Paul Richard Thomas via Fortran wrote:
> Ping!
>
> On Sat, 12 Dec 2020 at 10:38, Paul Richard Thomas <
> paul.richard.thomas@gmail.com> wrote:
>
>> Fortran: Fix some select rank issues [PR97694 and 97723].
>>
>> Hi All,
>>
>> Unlike select type, select rank selectors retain the allocatable
>> attribute. This is corrected by the chunk in check.c. Note the trailing
>> whitespace corrections. Resolution of select rank construct must be done in
>> the same way as select type and so the break has been added to ensure that
>> the block is resolved in resolve_select_rank. The final chunk prevents
>> segfaults for class associate variables that are optional dummies, since
>> these apparently are not adorned with the GFC_DECL_SAVED_DESCRIPTOR.
>>
>> Regtests OK on FC31/x86_64 - OK for master?
>>
>> Cheers
>>
>> Paul
>>
>> 2020-12-12  Paul Thomas  <pault@gcc.gnu.org>
>>
>> gcc/fortran
>> PR fortran/97694
>> PR fortran/97723
>> * check.c (allocatable_check): Select rank temporaries are
>> permitted even though they are treated as associate variables.
>> * resolve.c (gfc_resolve_code): Break on select rank as well as
>> select type so that the block os resolved.
>> * trans-stmt.c (trans_associate_var): Class associate variables
>> that are optional dummies must use the backend_decl.
>>
>> gcc/testsuite/
>> PR fortran/97694
>> PR fortran/97723
>> * gfortran.dg/select_rank_5.f90: New test.
>>
>>
diff mbox series

Patch

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 1e64fab3401..d8829e42b18 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -289,7 +289,7 @@  bin2real (gfc_expr *x, int kind)
 }
 
 
-/* Fortran 2018 treats a BOZ as simply a string of bits.  gfc_boz2real () 
+/* Fortran 2018 treats a BOZ as simply a string of bits.  gfc_boz2real ()
    converts the string into a REAL of the appropriate kind.  The treatment
    of the sign bit is processor dependent.  */
 
@@ -377,12 +377,12 @@  gfc_boz2real (gfc_expr *x, int kind)
 }
 
 
-/* Fortran 2018 treats a BOZ as simply a string of bits.  gfc_boz2int () 
+/* Fortran 2018 treats a BOZ as simply a string of bits.  gfc_boz2int ()
    converts the string into an INTEGER of the appropriate kind.  The
    treatment of the sign bit is processor dependent.  If the  converted
    value exceeds the range of the type, then wrap-around semantics are
    applied.  */
- 
+
 bool
 gfc_boz2int (gfc_expr *x, int kind)
 {
@@ -975,7 +975,8 @@  allocatable_check (gfc_expr *e, int n)
   symbol_attribute attr;
 
   attr = gfc_variable_attr (e, NULL);
-  if (!attr.allocatable || attr.associate_var)
+  if (!attr.allocatable
+     || (attr.associate_var && !attr.select_rank_temporary))
     {
       gfc_error ("%qs argument of %qs intrinsic at %L must be ALLOCATABLE",
 		 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic,
@@ -3232,7 +3233,7 @@  gfc_check_intconv (gfc_expr *x)
       || strcmp (gfc_current_intrinsic, "long") == 0)
     {
       gfc_error ("%qs intrinsic subprogram at %L has been deprecated.  "
-		 "Use INT intrinsic subprogram.", gfc_current_intrinsic, 
+		 "Use INT intrinsic subprogram.", gfc_current_intrinsic,
 		 &x->where);
       return false;
     }
@@ -3965,7 +3966,7 @@  gfc_check_findloc (gfc_actual_arglist *ap)
   /* Check the kind of the characters argument match.  */
   if (a1 && v1 && a->ts.kind != v->ts.kind)
     goto incompat;
-	 
+
   d = ap->next->next->expr;
   m = ap->next->next->next->expr;
   k = ap->next->next->next->next->expr;
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 0a8f90775ab..891571c0864 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -11776,8 +11776,9 @@  gfc_resolve_code (gfc_code *code, gfc_namespace *ns)
 	      gfc_resolve_omp_do_blocks (code, ns);
 	      break;
 	    case EXEC_SELECT_TYPE:
-	      /* Blocks are handled in resolve_select_type because we have
-		 to transform the SELECT TYPE into ASSOCIATE first.  */
+	    case EXEC_SELECT_RANK:
+	      /* Blocks are handled in resolve_select_type/rank because we
+		 have to transform the SELECT TYPE into ASSOCIATE first.  */
 	      break;
             case EXEC_DO_CONCURRENT:
 	      gfc_do_concurrent_flag = 1;
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index adc6b8fefb5..ab99e579461 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -1784,7 +1784,7 @@  trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block)
       if (e->ts.type == BT_CLASS)
 	{
 	  /* Go straight to the class data.  */
-	  if (sym2->attr.dummy)
+	  if (sym2->attr.dummy && !sym2->attr.optional)
 	    {
 	      class_decl = DECL_LANG_SPECIFIC (sym2->backend_decl) ?
 			   GFC_DECL_SAVED_DESCRIPTOR (sym2->backend_decl) :