[fortran] Fix handling of assumed-size arrays in inline matmul

Message ID 4c520b3f-0645-edac-0eda-e19621407f78@netcologne.de
State New
Headers show
Series
  • [fortran] Fix handling of assumed-size arrays in inline matmul
Related show

Commit Message

Thomas Koenig Feb. 12, 2018, 10:46 a.m.
Hello world,

the attached patch fixes a regression where a rejects-valid would
be issued.

OK for the affected branches, trunk and gcc-7?

Regards

	Thomas

2018-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/84270
         * frontend-passes (scalarized_expr):  If the expression
         is an assumed size array, leave in the last reference
         and pass AR_SECTION instead of AR_FULL to gfc_resolve
         in order to avoid an error.

2018-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/84270
         * gfortran.dg/inline_matmul_22.f90: New test.

Comments

Thomas Koenig Feb. 17, 2018, 2:22 p.m. | #1
Am 12.02.2018 um 11:46 schrieb Thomas Koenig:
> Hello world,
> 
> the attached patch fixes a regression where a rejects-valid would
> be issued.
> 
> OK for the affected branches, trunk and gcc-7?

PING ** (5.D0/7.D0) ?
Jerry DeLisle Feb. 17, 2018, 3:27 p.m. | #2
On 02/17/2018 06:22 AM, Thomas Koenig wrote:
> Am 12.02.2018 um 11:46 schrieb Thomas Koenig:
>> Hello world,
>>
>> the attached patch fixes a regression where a rejects-valid would
>> be issued.
>>
>> OK for the affected branches, trunk and gcc-7?
> 
> PING ** (5.D0/7.D0) ?
> 
> 

Yes, OK

Jerry

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 257347)
+++ frontend-passes.c	(Arbeitskopie)
@@ -3567,11 +3567,27 @@  scalarized_expr (gfc_expr *e_in, gfc_expr **index,
 			 is the lbound of a full ref.  */
 		      int j;
 		      gfc_array_ref *ar;
+		      int to;
 
 		      ar = &ref->u.ar;
-		      ar->type = AR_FULL;
-		      for (j = 0; j < ar->dimen; j++)
+
+		      /* For assumed size, we need to keep around the final
+			 reference in order not to get an error on resolution
+			 below, and we cannot use AR_FULL.  */
+			 
+		      if (ar->as->type == AS_ASSUMED_SIZE)
 			{
+			  ar->type = AR_SECTION;
+			  to = ar->dimen - 1;
+			}
+		      else
+			{
+			  to = ar->dimen;
+			  ar->type = AR_FULL;
+			}
+
+		      for (j = 0; j < to; j++)
+			{
 			  gfc_free_expr (ar->start[j]);
 			  ar->start[j] = NULL;
 			  gfc_free_expr (ar->end[j]);