https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116107
Bug ID: 116107 Summary: [OpenMP] Array-section mapping with 'declare target' link accesses the wrong data Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: openmp, wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org Target Milestone: --- See also PR 115559 – which contains a Fortran testcase. The problem is that the map does: #pragma omp target enter data map(to:arr[5] [len: 40]) and stores the resulting memory address on the device side. But it should store it with the offset of -sizeof(arr[0])*5 bytes to ensure that arr[5] on the device side accesses the right element … * * * int arr[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; #pragma omp declare target link(arr) #pragma omp begin declare target void f(int *res) { __builtin_memcpy (res, &arr[5], sizeof(int)*10); } #pragma omp end declare target int main() { int res[10], res2; #pragma omp target enter data map(arr[5:10]) #pragma omp target map(from:res) f(res); for (int i = 0; i < 10; i++) __builtin_printf("%d\n", res[i]); #pragma omp target map(from:res2) res2 = arr[5]; __builtin_printf("res2 = %d\n", res2); }