This patch fixes calculation of 'HstPtrBegin' address to prevent
'explicit extension not allowed: ...' error that may happen when the
structure being mapped has less that 8-byte alignment:
#include <omp.h>
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;
}
}
return 0;
}In case 's' object is only 4-byte aligned (please, see D135462 for details),
we may get the following error:
... Libomptarget --> Looking up mapping(HstPtrBegin=0x00007ffc9b2581e4, Size=8)... Libomptarget --> Creating new map entry with HstPtrBase=0x00007ffc9b2581e4, HstPtrBegin=0x00007ffc9b2581e4... ... Libomptarget --> Moving 8 bytes (hst:0x00007ffc9b2581e4) -> (tgt:0x0000561d0739b390) ... Libomptarget --> Entry 0: Base=0x00007ffc9b2581e4, Begin=0x00007ffc9b2581e4, Size=8, Type=0x20, Name=unknown Libomptarget --> Entry 1: Base=0x00007ffc9b2581e4, Begin=0x00007ffc9b2581e4, Size=4, Type=0x1000000000002, Name=s.i Libomptarget --> Entry 2: Base=0x00007ffc9b2581e4, Begin=0x00007ffc9b2581e8, Size=4, Type=0x1000000000002, Name=s.j ... Libomptarget --> Using a padding of 4 bytes for begin address 0x00007ffc9b2581e4 Libomptarget --> Looking up mapping(HstPtrBegin=0x00007ffc9b2581e0, Size=12)... Libomptarget --> WARNING: Pointer is not mapped but section extends into already mapped data Libomptarget message: explicit extension not allowed: host address specified is 0x00007ffc9b2581e0 (12 bytes), but device allocation maps to host at 0x00007ffc9b2581e4 (8 bytes)
Here we have wrong HstPtrBegin address - 0x00007ffc9b2581e0 that points
to a memory before 's' object itself, which starts at HstPtrBase (0x00007ffc9b2581e4).
This, in turn, leads to inconsistency in mapping sizes created and requested.