On Mon, May 23, 2016 at 09:19:47PM +0300, Alexander Monakov wrote: > > So unlike for functions, for variables GCC needs to know exactly whether they > are 'omp declare target [link]' at all points of use, not just at the point of > definition.
There are many bugs that just can't be diagnosed by the compiler. It is up to the users to make sure they write sane code. > There's a pitfall if the user forgets the pragma on the external declaration: > > === a.c > > #pragma omp declare target > int a; > void set_a() > { > a = 42; > } > #pragma omp end declare target > > === main.c > > extern int a; > extern void set_a(); > #pragma omp declare target to(set_a) > > int main() > { > a = 0; > #pragma omp target map(tofrom:a) > set_a(); > > if (a != 42) abort(); > } > === The above will abort always, no matter if you have #pragma omp declare target to(a) in main.c or not, because a is already mapped (with infinite refcount), so the map(tofrom:a) doesn't actually do anything (but prevent firstprivatization of the var). With map clause on the target, the only change would be that the body of the target (but not functions it calls), if they reference a, would be less efficient (would reference a through some pointer set up during the mapping, instead of a directly). Jakub