Re: [Patch] C++: Handle OpenMP/OpenACC array sections [: / :] with C++26

Tobias Burnus <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
Jakub Jelinek wrote:
> Note, OpenMP has not just these, but also var[low:len:stride] where all
> 3 are optional, so it is also about var[::] and var[:len:] etc.

True, but we still need to get those patches into mainline (Julian wrote 
them; the are also on the OG branch) – and my idea is to the C++ 
handling as part of doing this. [1]


> I'm not excited about this change, but agree I can't think of
> cases ambiguous right now, but please give Jason time to think of some.

Hence, I also CCed him.

[It also still needs to be discussed as OpenMP spec level as well, but 
it seems as if no one sees issues at the moment.]


> It would be certainly useful to have testsuite coverage that shows
> that valid splice expressions etc. are parsed correctly even in array
> sections with c++26/-freflection, say

I plan to include the attached testcase with the commit. Being a non-expert
on reflections, I would prefer if someone else could write those, if
more tested are deemed to be necessary.

Tobias

[1] Namely, the OG16 (devel/omp/gcc-16 branch) forward ported version is:

2a5fe5c4b3f OpenMP: Support strided and shaped-array updates for C++
40617ea1249 OpenMP: Array shaping operator and strided "target update" for C
1b6460d9eb6 OpenMP: Noncontiguous "target update" for Fortran
omp-cxx26-add.diff (text/x-patch, 1.8 KB)
diff --git a/gcc/testsuite/g++.dg/gomp/array-section-4.C b/gcc/testsuite/g++.dg/gomp/array-section-4.C
new file mode 100644
index 00000000000..2ece1ac9e61
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/array-section-4.C
@@ -0,0 +1,43 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection -fdump-tree-original" }
+
+void f()
+{
+  constexpr int a = 42;
+  constexpr auto b = ^^a;
+  int c[128];
+
+  #pragma omp target enter data map(to : c[[:b:]])
+
+  #pragma omp target enter data map(to : c[[:b:]:])
+
+  #pragma omp target enter data map(to : c[:[:b:]])
+
+  #pragma omp target enter data map(to : c[[:b:]:2])
+
+  #pragma omp target enter data map(to : c[2:[:b:]])
+
+
+  #pragma omp task affinity( c[[:b:]])
+    ;
+
+  #pragma omp task affinity( c[[:b:]:2])
+    ;
+  #pragma omp task affinity( c[2:[:b:]])
+    ;
+
+  #pragma omp task affinity( c[[:b:]:])
+    ;
+  #pragma omp task affinity( c[:[:b:]])
+    ;
+}
+
+// { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:c\\\[42\\\] \\\[len: 4\\\]\\)" 1 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:c\\\[42\\\] \\\[len: 344\\\]\\)" 1 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:c\\\[0\\\] \\\[len: 168\\\]\\)" 1 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:c\\\[42\\\] \\\[len: 8\\\]\\)" 1 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:c\\\[2\\\] \\\[len: 168\\\]\\)" 1 "original" } }
+
+// { dg-final { scan-tree-dump-times "#pragma omp task affinity\\(c\\\[42\\\]\\)" 3 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp task affinity\\(c\\\[2\\\]\\)" 1 "original" } }
+// { dg-final { scan-tree-dump-times "#pragma omp task affinity\\(c\\\[0\\\]\\)" 1 "original" } }
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.