llvm-project/clang/test/OpenMP/target_update_strided_multiple_messages.c
Amit Tiwari 2074e1320f
[Clang][OpenMP] Non-contiguous strided update (#144635)
This patch handles the strided update in the `#pragma omp target update
from(data[a🅱️c])` directive where 'c' represents the strided access
leading to non-contiguous update in the `data` array when the offloaded
execution returns the control back to host from device using the `from`
clause.

Issue: Clang CodeGen where info is generated for the particular
`MapType` (to, from, etc), it was failing to detect the strided access.
Because of this, the `MapType` bits were incorrect when passed to
runtime. This led to incorrect execution (contiguous) in the
libomptarget runtime code.

Added a minimal testcase that verifies the working of the patch.
2025-08-12 19:32:15 +05:30

46 lines
1.3 KiB
C

// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
void foo(void) {}
typedef struct {
int len;
double data[12];
} S;
int main(int argc, char **argv) {
int len = 12;
double data1[len], data2[len];
S s;
// Valid multiple strided array sections
#pragma omp target update from(data1[0:4:2], data2[0:2:5]) // OK
{}
#pragma omp target update to(data1[1:2:3], data2[2:3:2]) // OK
{}
// Mixed strided and regular array sections
#pragma omp target update from(data1[0:len], data2[0:4:2]) // OK
{}
// Struct member arrays with strides
#pragma omp target update from(s.data[0:4:2]) // OK
{}
#pragma omp target update from(s.data[0:s.len/2:2]) // OK
{}
// Invalid stride in one of multiple sections
#pragma omp target update from(data1[0:3:4], data2[0:2:0]) // expected-error {{section stride is evaluated to a non-positive value 0}}
// Complex expressions in multiple arrays
int stride1 = 2, stride2 = 3;
#pragma omp target update from(data1[0:len/2:stride1], data2[1:len/3:stride2]) // OK
{}
// Missing colon
#pragma omp target update from(data1[0:4:2], data2[0:3 4]) // expected-error {{expected ']'}} expected-note {{to match this '['}}
return 0;
}