[gcc/devel/omp/gcc-13] openacc: fix ICE for non-decl expression in non-contiguous array base-pointer

Kwok Yeung kcy@gcc.gnu.org
Fri May 19 16:43:16 GMT 2023


https://gcc.gnu.org/g:a7da4348366fda68935de36b6ce3c7efec3fc6ab

commit a7da4348366fda68935de36b6ce3c7efec3fc6ab
Author: Chung-Lin Tang <cltang@codesourcery.com>
Date:   Thu Aug 19 16:17:02 2021 +0800

    openacc: fix ICE for non-decl expression in non-contiguous array base-pointer
    
    Currently, we do not support cases like struct-members as the base-pointer
    for an OpenACC non-contiguous array. Mark such cases as unsupported in the
    C/C++ front-ends, instead of ICEing on them.
    
    gcc/c/ChangeLog:
    
            * c-typeck.cc (handle_omp_array_sections_1): Robustify non-contiguous
            array check and reject non-DECL base-pointer cases as unsupported.
    
    gcc/cp/ChangeLog:
    
            * semantics.cc (handle_omp_array_sections_1): Robustify non-contiguous
            array check and reject non-DECL base-pointer cases as unsupported.

Diff:
---
 gcc/c/ChangeLog.omp  |  5 +++++
 gcc/c/c-typeck.cc    | 19 ++++++++++++++++---
 gcc/cp/ChangeLog.omp |  5 +++++
 gcc/cp/semantics.cc  | 23 +++++++++++++++++------
 4 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 52af6cf6316..1b33bef45ec 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  <cltang@codesourcery.com>
+
+	* c-typeck.cc (handle_omp_array_sections_1): Robustify non-contiguous
+	array check and reject non-DECL base-pointer cases as unsupported.
+
 2020-08-19  Sandra Loosemore  <sandra@codesourcery.com>
 
 	Add a "combined" flag for "acc kernels loop" etc directives.
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 8bf20e70232..7cff12a342a 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -14006,14 +14006,27 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
 	      if (d_length == NULL_TREE || !integer_onep (d_length))
 		{
 		  if (ort == C_ORT_ACC)
-		    non_contiguous = true;
-		  else
 		    {
+		      while (TREE_CODE (d) == TREE_LIST)
+			d = TREE_CHAIN (d);
+		      if (DECL_P (d))
+			{
+			  /* Note that OpenACC does accept these kinds of
+			     non-contiguous pointer based arrays.  */
+			  non_contiguous = true;
+			  break;
+			}
 		      error_at (OMP_CLAUSE_LOCATION (c),
-				"array section is not contiguous in %qs clause",
+				"base-pointer expression in %qs clause not "
+				"supported for non-contiguous arrays",
 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 		      return error_mark_node;
 		    }
+
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "array section is not contiguous in %qs clause",
+			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		  return error_mark_node;
 		}
 	    }
 	}
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 1c7df9a15a0..9ceee986906 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  <cltang@codesourcery.com>
+
+	* semantics.cc (handle_omp_array_sections_1): Robustify non-contiguous
+	array check and reject non-DECL base-pointer cases as unsupported.
+
 2021-02-01  Chung-Lin Tang  <cltang@codesourcery.com>
 
 	* semantics.cc (finish_omp_clauses):  Adjust to allow duplicate
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 250b3002680..584cf974447 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5474,9 +5474,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
 	  return error_mark_node;
 	}
       /* If there is a pointer type anywhere but in the very first
-	 array-section-subscript, the array section could be non-contiguous.
-	 Note that OpenACC does accept these kinds of non-contiguous pointer
-	 based arrays.  */
+	 array-section-subscript, the array section could be non-contiguous.  */
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_AFFINITY
 	  && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
 	  && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST)
@@ -5490,14 +5488,27 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
 	      if (d_length == NULL_TREE || !integer_onep (d_length))
 		{
 		  if (ort == C_ORT_ACC)
-		    non_contiguous = true;
-		  else
 		    {
+		      while (TREE_CODE (d) == TREE_LIST)
+			d = TREE_CHAIN (d);
+		      if (DECL_P (d))
+			{
+			  /* Note that OpenACC does accept these kinds of
+			     non-contiguous pointer based arrays.  */
+			  non_contiguous = true;
+			  break;
+			}
 		      error_at (OMP_CLAUSE_LOCATION (c),
-				"array section is not contiguous in %qs clause",
+				"base-pointer expression in %qs clause not "
+				"supported for non-contiguous arrays",
 				omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
 		      return error_mark_node;
 		    }
+
+		  error_at (OMP_CLAUSE_LOCATION (c),
+			    "array section is not contiguous in %qs clause",
+			    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+		  return error_mark_node;
 		}
 	    }
 	}


More information about the Gcc-cvs mailing list