[fortran] Fix Bug 102430 - [13/14/15/16 Regression] ICE in fold_convert_loc, at fold-const.c

Message ID 4d1ac989-15c1-4278-8542-7e3d5a70e0a6@gmail.com
State New
Headers
Series [fortran] Fix Bug 102430 - [13/14/15/16 Regression] ICE in fold_convert_loc, at fold-const.c |

Commit Message

Jerry D April 7, 2026, 5:48 p.m. UTC
  Hello all,

The attached patch resolves this by issueing a sorry error.

This fix is also relatively simple.

I will also commit this one later today.

Regression tested on x86_64.

I dont think this one is worth backporting later. Let me know if anyone thinks 
otherwise.

Regards,

Jerry
---

commit 396a6f28d770b27844cb7a340249d78f3f391649 (HEAD -> master)
Author: Christopher Albert <albert@tugraz.at>
Date:   Sun Dec 21 00:33:11 2025 +0100

     fortran: Reject array/allocatable LINEAR on DO [PR102430]

     The middle-end does not implement array/allocatable LINEAR for OpenMP
     worksharing loops, which can ICE during OpenMP expansion.  Diagnose this
     case in the Fortran front end with a sorry message instead.

             PR fortran/102430

     gcc/fortran/ChangeLog:

      * openmp.cc (resolve_omp_clauses): Reject array/allocatable LINEAR on
       worksharing-loop constructs.

     gcc/testsuite/ChangeLog:

       * gfortran.dg/gomp/pr102430.f90: New test.

     Signed-off-by: Christopher Albert <albert@tugraz.at>
  

Comments

Paul Richard Thomas April 7, 2026, 9:26 p.m. UTC | #1
Hi Jerry,

I think that a "sorry" is better than an ICE on all the affected
branches. By all means push it to mainline and I will put it on the
schedule for backporting.

Thanks

Paul

On Tue, 7 Apr 2026 at 18:48, Jerry D <jvdelisle2@gmail.com> wrote:
>
> Hello all,
>
> The attached patch resolves this by issueing a sorry error.
>
> This fix is also relatively simple.
>
> I will also commit this one later today.
>
> Regression tested on x86_64.
>
> I dont think this one is worth backporting later. Let me know if anyone thinks
> otherwise.
>
> Regards,
>
> Jerry
> ---
>
> commit 396a6f28d770b27844cb7a340249d78f3f391649 (HEAD -> master)
> Author: Christopher Albert <albert@tugraz.at>
> Date:   Sun Dec 21 00:33:11 2025 +0100
>
>      fortran: Reject array/allocatable LINEAR on DO [PR102430]
>
>      The middle-end does not implement array/allocatable LINEAR for OpenMP
>      worksharing loops, which can ICE during OpenMP expansion.  Diagnose this
>      case in the Fortran front end with a sorry message instead.
>
>              PR fortran/102430
>
>      gcc/fortran/ChangeLog:
>
>       * openmp.cc (resolve_omp_clauses): Reject array/allocatable LINEAR on
>        worksharing-loop constructs.
>
>      gcc/testsuite/ChangeLog:
>
>        * gfortran.dg/gomp/pr102430.f90: New test.
>
>      Signed-off-by: Christopher Albert <albert@tugraz.at>
  

Patch

From 5424fef298bff8b69a351dde8ab2a6b7c46af9ab Mon Sep 17 00:00:00 2001
From: Christopher Albert <albert@tugraz.at>
Date: Sun, 21 Dec 2025 00:33:11 +0100
Subject: [PATCH] fortran: Reject array/allocatable LINEAR on DO [PR102430]

The middle-end does not implement array/allocatable LINEAR for OpenMP
worksharing loops, which can ICE during OpenMP expansion.  Diagnose this
case in the Fortran front end with a sorry message instead.

	PR fortran/102430

gcc/fortran/ChangeLog:

	* openmp.cc (resolve_omp_clauses): Reject array/allocatable LINEAR on
	worksharing-loop constructs.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/pr102430.f90: New test.

Signed-off-by: Christopher Albert <albert@tugraz.at>
---
 gcc/fortran/openmp.cc                       | 35 +++++++++++++++++++++
 gcc/testsuite/gfortran.dg/gomp/pr102430.f90 | 11 +++++++
 2 files changed, 46 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr102430.f90

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 76c601952a7..71bbce13758 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -10435,6 +10435,41 @@  resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
 		      }
 		    break;
 		  case OMP_LIST_LINEAR:
+		    if (code)
+		      {
+			bool is_worksharing_for = false;
+			switch (code->op)
+			  {
+			  case EXEC_OMP_DO:
+			  case EXEC_OMP_PARALLEL_DO:
+			  case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
+			  case EXEC_OMP_TARGET_PARALLEL_DO:
+			  case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
+			  case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
+			    is_worksharing_for = true;
+			    break;
+			  default:
+			    break;
+			  }
+
+			if (is_worksharing_for
+			    && (n->sym->attr.dimension
+				|| n->sym->attr.allocatable))
+			  {
+			    if (n->sym->attr.allocatable)
+			      gfc_error ("Sorry, ALLOCATABLE object %qs in "
+					 "LINEAR clause on worksharing-loop "
+					 "construct at %L is not yet supported",
+					 n->sym->name, &n->where);
+			    else
+			      gfc_error ("Sorry, array %qs in LINEAR clause "
+					 "on worksharing-loop construct at %L "
+					 "is not yet supported",
+					 n->sym->name, &n->where);
+			    break;
+			  }
+		      }
+
 		    if (code
 			&& n->u.linear.op != OMP_LINEAR_DEFAULT
 			&& n->u.linear.op != linear_op)
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr102430.f90 b/gcc/testsuite/gfortran.dg/gomp/pr102430.f90
new file mode 100644
index 00000000000..73c8c3f1dec
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr102430.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! { dg-options "-fopenmp" }
+! PR fortran/102430
+
+program p
+  integer :: a(2)
+  !$omp parallel do linear(a)  ! { dg-error "Sorry, array" }
+  do i = 1, 8
+    a = a + 1
+  end do
+end program p
-- 
2.52.0