https://gcc.gnu.org/g:151fc161d0ed640048444ca18f9325e3d2e03e99

commit 151fc161d0ed640048444ca18f9325e3d2e03e99
Author: Chung-Lin Tang <clt...@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 a95b2adc8f8..4b8331c3744 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  <clt...@codesourcery.com>
+
+       * c-typeck.cc (handle_omp_array_sections_1): Robustify non-contiguous
+       array check and reject non-DECL base-pointer cases as unsupported.
+
 2022-02-03  Kwok Cheung Yeung  <k...@codesourcery.com>
 
        * c-parser.ccc (c_parser_omp_clause_map): Update call to
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 7f466b858d9..3fea8185c0a 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -14186,14 +14186,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 bfdc3be2c4e..71b0f57918f 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2021-08-19  Chung-Lin Tang  <clt...@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  <clt...@codesourcery.com>
 
        * semantics.cc (finish_omp_clauses):  Adjust to allow duplicate
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 9c7258989f4..9b8d5ac2ce8 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5824,9 +5824,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_OPERAND (t, 0)) == OMP_ARRAY_SECTION)
@@ -5840,14 +5838,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;
                }
            }
        }

Reply via email to