Index: openmp/libomptarget/src/device.cpp =================================================================== --- openmp/libomptarget/src/device.cpp +++ openmp/libomptarget/src/device.cpp @@ -321,7 +321,8 @@ // If the target pointer is valid, and we need to transfer data, issue the // data transfer. - if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways)) { + if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways) && + Size) { // Lock the entry before releasing the mapping table lock such that another // thread that could issue data movement will get the right result. std::lock_guard LG(*Entry); Index: openmp/libomptarget/src/omptarget.cpp =================================================================== --- openmp/libomptarget/src/omptarget.cpp +++ openmp/libomptarget/src/omptarget.cpp @@ -1028,7 +1028,7 @@ // Move data back to the host const bool HasAlways = ArgTypes[I] & OMP_TGT_MAPTYPE_ALWAYS; const bool HasFrom = ArgTypes[I] & OMP_TGT_MAPTYPE_FROM; - if (HasFrom && (HasAlways || IsLast) && !IsHostPtr) { + if (HasFrom && (HasAlways || IsLast) && !IsHostPtr && DataSize) { DP("Moving %" PRId64 " bytes (tgt:" DPxMOD ") -> (hst:" DPxMOD ")\n", DataSize, DPxPTR(TgtPtrBegin), DPxPTR(HstPtrBegin)); Index: openmp/libomptarget/test/mapping/data_member_ref.cpp =================================================================== --- openmp/libomptarget/test/mapping/data_member_ref.cpp +++ openmp/libomptarget/test/mapping/data_member_ref.cpp @@ -1,8 +1,5 @@ // RUN: %libomptarget-compilexx-run-and-check-generic -// Wrong results on amdgpu -// XFAIL: amdgcn-amd-amdhsa - #include struct View { @@ -26,42 +23,55 @@ int Data = 123456; V1.Data = &Data; Foo Baz(V1); + int D1, D2; // CHECK: Host 123456. printf("Host %d.\n", Bar.VRef.Data); -#pragma omp target map(Bar.VRef) +#pragma omp target map(Bar.VRef) map(from : D1, D2) { // CHECK: Device 123456. - printf("Device %d.\n", Bar.VRef.Data); + D1 = Bar.VRef.Data; + printf("Device %d.\n", D1); V.Data = 654321; // CHECK: Device 654321. - printf("Device %d.\n", Bar.VRef.Data); + D2 = Bar.VRef.Data; + printf("Device %d.\n", D2); } + printf("Device %d.\n", D1); + printf("Device %d.\n", D2); // CHECK: Host 654321 654321. printf("Host %d %d.\n", Bar.VRef.Data, V.Data); V.Data = 123456; // CHECK: Host 123456. printf("Host %d.\n", Bar.VRef.Data); -#pragma omp target map(Bar) map(Bar.VRef) +#pragma omp target map(Bar) map(Bar.VRef) map(from : D1, D2) { // CHECK: Device 123456. - printf("Device %d.\n", Bar.VRef.Data); + D1 = Bar.VRef.Data; + printf("Device %d.\n", D1); V.Data = 654321; // CHECK: Device 654321. - printf("Device %d.\n", Bar.VRef.Data); + D2 = Bar.VRef.Data; + printf("Device %d.\n", D2); } + printf("Device %d.\n", D1); + printf("Device %d.\n", D2); // CHECK: Host 654321 654321. printf("Host %d %d.\n", Bar.VRef.Data, V.Data); // CHECK: Host 123456. printf("Host %d.\n", *Baz.VRef.Data); -#pragma omp target map(*Baz.VRef.Data) +#pragma omp target map(*Baz.VRef.Data) map(from : D1, D2) { // CHECK: Device 123456. - printf("Device %d.\n", *Baz.VRef.Data); + D1 = *Baz.VRef.Data; + printf("Device %d.\n", D1); *V1.Data = 654321; // CHECK: Device 654321. - printf("Device %d.\n", *Baz.VRef.Data); + D2 = *Baz.VRef.Data; + printf("Device %d.\n", D2); } + printf("Device %d.\n", D1); + printf("Device %d.\n", D2); // CHECK: Host 654321 654321 654321. printf("Host %d %d %d.\n", *Baz.VRef.Data, *V1.Data, Data); return 0;