llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Akash Manna (akash-manna-sky)

<details>
<summary>Changes</summary>

After #<!-- -->244591 a `target update` of a section of a pointer to a variable 
length array, such as devito's `int (*u)[x][y][z]` with 
`u[0:t][0:x][0:y][0:z]`, goes through the non-contiguous descriptor path. The 
descriptor code asserted that every dimension but the innermost is based on an 
array type, which a pointer-to-array base is not.

The outermost dimension never needs a size, so the assertion now accepts a 
pointer base there. Builds without assertions already produced the correct 
descriptor. 

---
Full diff: https://github.com/llvm/llvm-project/pull/246794.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+5-4) 
- (modified) clang/test/OpenMP/GH136294.c (+40) 


``````````diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b828b63592cddd..a9a0163def4de5 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8841,10 +8841,11 @@ class MappableExprsHandler {
       auto *CAT = Context.getAsConstantArrayType(Ty);
       auto *VAT = Context.getAsVariableArrayType(Ty);
 
-      // We need all the dimension size except for the last dimension.
-      assert((VAT || CAT || &Component == &*Components.begin()) &&
-             "Should be either ConstantArray or VariableArray if not the "
-             "first Component");
+      // We need all the dimension size except for the last dimension. A
+      // pointer base (e.g. 'int (*u)[y][z]') is only the outermost dimension,
+      // which needs no size either.
+      assert((VAT || CAT || Ty->isAnyPointerType()) &&
+             "Should be either ConstantArray, VariableArray or a pointer");
 
       // Get element size if CurCounts is empty.
       if (CurCounts.empty()) {
diff --git a/clang/test/OpenMP/GH136294.c b/clang/test/OpenMP/GH136294.c
index f7bc8475fee266..969564d8f2b826 100644
--- a/clang/test/OpenMP/GH136294.c
+++ b/clang/test/OpenMP/GH136294.c
@@ -361,4 +361,44 @@ void pointer_array(double **pp, int n) {
 #pragma omp target update to((([n])pp)[0:n][1])
 }
 
+// A pointer to a variable length array: the pointer is the outermost dimension
+// and needs no size of its own.
+// CHECK-LABEL: define {{.*}}void @pointer_to_vla(
+// CHECK:       store ptr %u, ptr [[PV_U_ADDR:%.+]],
+void pointer_to_vla(int t, int x, int y, int z, int (*u)[x][y][z]) {
+  // CHECK:      [[PV_U:%.+]] = load ptr, ptr [[PV_U_ADDR]],
+  // CHECK:      store ptr [[PV_U]], ptr
+  // CHECK:      getelementptr inbounds [5 x %struct.descriptor_dim{{.*}}], 
ptr %{{.+}}, i64 0, i64 0
+  // CHECK:      call void @__tgt_target_data_update_mapper(ptr @{{.+}}, i64 
-1, i32 1, ptr %{{.+}}, ptr %{{.+}}, ptr @{{.+}}, ptr @{{.+}}, ptr null, ptr 
null)
+#pragma omp target update from(u[0:t][0:x][0:y][0:z])
+}
+
+// A pointer to a constant size array: the same descriptor as for double[3][4].
+// CHECK-LABEL: define {{.*}}void @pointer_to_array(
+void pointer_to_array(double (*b)[4]) {
+  // CHECK:      [[PB_DIM0:%.+]] = getelementptr inbounds [3 x 
[[PB_DESC:%struct.descriptor_dim[.0-9]*]]], ptr [[PB_DIMS:%.+]], i64 0, i64 0
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM0]], i32 0, i32 0
+  // CHECK-NEXT: store i64 0, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM0]], i32 0, i32 1
+  // CHECK-NEXT: store i64 3, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM0]], i32 0, i32 2
+  // CHECK-NEXT: store i64 32, ptr [[F]],
+  // CHECK-NEXT: [[PB_DIM1:%.+]] = getelementptr inbounds [3 x [[PB_DESC]]], 
ptr [[PB_DIMS]], i64 0, i64 1
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM1]], i32 0, i32 0
+  // CHECK-NEXT: store i64 8, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM1]], i32 0, i32 1
+  // CHECK-NEXT: store i64 1, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM1]], i32 0, i32 2
+  // CHECK-NEXT: store i64 8, ptr [[F]],
+  // CHECK-NEXT: [[PB_DIM2:%.+]] = getelementptr inbounds [3 x [[PB_DESC]]], 
ptr [[PB_DIMS]], i64 0, i64 2
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM2]], i32 0, i32 0
+  // CHECK-NEXT: store i64 0, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM2]], i32 0, i32 1
+  // CHECK-NEXT: store i64 8, ptr [[F]],
+  // CHECK-NEXT: [[F:%.+]] = getelementptr inbounds nuw [[PB_DESC]], ptr 
[[PB_DIM2]], i32 0, i32 2
+  // CHECK-NEXT: store i64 1, ptr [[F]],
+  // CHECK:      call void @__tgt_target_data_update_mapper(ptr @{{.+}}, i64 
-1, i32 1, ptr %{{.+}}, ptr %{{.+}}, ptr @{{.+}}, ptr @{{.+}}, ptr null, ptr 
null)
+#pragma omp target update from(b[0:3][1])
+}
+
 #endif // HEADER

``````````

</details>


https://github.com/llvm/llvm-project/pull/246794
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to