https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96810
--- Comment #2 from Wei Wentao <weiwt.fnst at cn dot fujitsu.com> --- > --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- > >The standard says this is unspecified behavior, but the unspecified behavior > >happens at runtime, so if the compiler could detect it at compile time, it > >would need to be at most a warning (if the code is never called, there is no > >unspecified behavior). Generally this isn't something that can be detected > >at > >compile time, e.g. the target data can be in a different function from > >target, > >or there could be target exit data that unmaps it in between and makes it > >valid, or the fact that the pointer must alias the array could be not known > >to > >the compiler, etc. > >And the testcase is rejected at runtime: > >libgomp: Trying to map into device [0x7ffc13463cbc..0x7ffc13463d0c) object > >when > > [0x7ffc13463cb0..0x7ffc13463cc0) is already mapped When I use clang to compile the same case, the compilation fails which is in line with expectations and is opposite to the result of gcc. The details show as below: clang version 11.0.0 clang /.../llvm/build/bin/clang -fopenmp-version=50 -fopenmp -I/.../common.deb.ompt.optional/include/ Example array_sections.2.c Example_array_sections.2.c:19:7: error: original storage of expression in data environment is shared but data environment do not fully contain mapped expression storage A[2] = 0; ^ Example_array_sections.2.c:11:30: note: used here #pragma omp target data map( A[0:4] ) ^~~~~~ 1 error generated.