Index: openmp/libomptarget/src/omptarget.cpp =================================================================== --- openmp/libomptarget/src/omptarget.cpp +++ openmp/libomptarget/src/omptarget.cpp @@ -105,7 +105,7 @@ * device will start at 0x200 with the padding (4 bytes), then &s1.b=0x204 and * &s1.p=0x208, as they should be to satisfy the alignment requirements. */ -static const int64_t Alignment = 8; +static const int64_t MaxAlignment = 16; /// Map global data and execute pending ctors static int initLibrary(DeviceTy &Device) { @@ -585,6 +585,7 @@ const int NextI = I + 1; if (getParentIndex(ArgTypes[I]) < 0 && NextI < ArgNum && getParentIndex(ArgTypes[NextI]) == I) { + int64_t Alignment = (int64_t)HstPtrBase % MaxAlignment; Padding = (int64_t)HstPtrBegin % Alignment; if (Padding) { DP("Using a padding of %" PRId64 " bytes for begin address " DPxMOD @@ -932,6 +933,7 @@ } void *HstPtrBegin = Args[I]; + void *HstPtrBase = ArgBases[I]; int64_t DataSize = ArgSizes[I]; // Adjust for proper alignment if this is a combined entry (for structs). // Look at the next argument - if that is MEMBER_OF this one, then this one @@ -939,6 +941,7 @@ const int NextI = I + 1; if (getParentIndex(ArgTypes[I]) < 0 && NextI < ArgNum && getParentIndex(ArgTypes[NextI]) == I) { + int64_t Alignment = (int64_t)HstPtrBase % MaxAlignment; int64_t Padding = (int64_t)HstPtrBegin % Alignment; if (Padding) { DP("Using a Padding of %" PRId64 " bytes for begin address " DPxMOD @@ -1293,8 +1296,8 @@ FirstPrivateArgInfoTy(int Index, void *HstPtr, int64_t Size, const map_var_info_t HstPtrName = nullptr) : Index(Index), HstPtrBegin(reinterpret_cast(HstPtr)), - HstPtrEnd(HstPtrBegin + Size), AlignedSize(Size + Size % Alignment), - HstPtrName(HstPtrName) {} + HstPtrEnd(HstPtrBegin + Size), + AlignedSize(Size + Size % MaxAlignment), HstPtrName(HstPtrName) {} }; /// A vector of target pointers for all private arguments Index: openmp/libomptarget/test/mapping/low_alignment.c =================================================================== --- /dev/null +++ openmp/libomptarget/test/mapping/low_alignment.c @@ -0,0 +1,25 @@ +// RUN: %libomptarget-compilexx-run-and-check-generic + +#include +#include + +int main() { + struct S { + int i; + int j; + } s; + s.i = 20; + s.j = 30; +#pragma omp target data map(tofrom : s) + { +#pragma omp target map(from : s.i, s.j) + { + s.i = 21; + s.j = 31; + } + } + if (s.i == 21 && s.j == 31) + printf("PASS"); + // CHECK: PASS + return 0; +}