[gcc/devel/omp/gcc-16] C++, OpenMP: Handle ARRAY_TYPE array sections, not just pointers

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:1c5e4c4984afb9007876cde47569a533ea205403

commit 1c5e4c4984afb9007876cde47569a533ea205403
Author: Sandra Loosemore <[email protected]>
Date:   Thu May 28 15:37:11 2026 +0000

    C++, OpenMP: Handle ARRAY_TYPE array sections, not just pointers
    
    This patch is a bug fix for commit gcc-17-202-g3f8c7483112, 'OpenMP:
    Expand "declare mapper" mappers for target {enter,exit,} data
    directives'.  The ChangeLog for that patch indicated that
    cxx_omp_map_array_section was supposed to accept both arrays and
    pointers as the base expression, but the code actually only allowed
    pointers.  OTOH, both the error-checking in handle_omp_array_sections_1
    and the code generation in build_array_ref allow ARRAY_TYPE, and code with
    such expressions is actually coming in to the function.
    
    There is no test case included with this patch, but I ran across this
    in the two new test cases included with the OpenMP iterators patch
    https://gcc.gnu.org/pipermail/gcc-patches/2025-July/689071.html which
    I am preparing to resubmit.
    
    gcc/cp/ChangeLog
            * semantics.cc (cxx_omp_map_array_section): Allow ARRAY_TYPE
            expressions, not just pointers.
    
    (cherry picked from commit 12fc7c1ecd34c2e77a1ef6daefea8d16cd3106d0)

Diff:
---
 gcc/cp/semantics.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 072b5d10108f..d0a48ff85260 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -6950,9 +6950,11 @@ cxx_omp_map_array_section (location_t loc, tree t)
       if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
 	t = convert_from_reference (t);
 
-      if (TYPE_PTR_P (TREE_TYPE (t)))
+      if (TYPE_PTR_P (TREE_TYPE (t))
+	  || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
 	t = build_array_ref (loc, t, low);
       else
+	/* handle_omp_array_sections_1 has already diagnosed the error.  */
 	t = error_mark_node;
     }
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.