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

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
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 <[email protected]>
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 <[email protected]>
pr102430.diff (text/x-patch, 2.7 KB)
From 5424fef298bff8b69a351dde8ab2a6b7c46af9ab Mon Sep 17 00:00:00 2001
From: Christopher Albert <[email protected]>
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 <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.