]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Add warning when functions containing metadirectives with 'construct={target...
authorKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 28 Jan 2022 13:56:33 +0000 (13:56 +0000)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 28 Jan 2022 15:44:23 +0000 (15:44 +0000)
commitd6d82af79181c20d48c61df62360a79a04104c05
tree7bd76ba9445eb858d708f85f4f0c62b174431f45
parent090bd2c50bc7987644c4b2eba76a310134475842
openmp: Add warning when functions containing metadirectives with 'construct={target}' called directly

void f(void)
{
  #pragma omp metadirective \
    when (construct={target}: A) \
    default (B)
    ...
}
...
{
  #pragma omp target
    f(); // Target call

  f(); // Local call
}

With the OpenMP 5.0/5.1 specifications, we would expect A to be selected in
the metadirective when the target call is made, but B when f is called
directly outside of a target context.  However, since GCC does not have
separate copies of f for local and target calls, and the construct selector
is static, it must be resolved one way or the other at compile-time (currently
in the favour of selecting A), which may be unexpected behaviour.

This patch attempts to detect the above situation, and will emit a warning
if found.

2022-01-28  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* gimplify.c (gimplify_omp_metadirective): Mark offloadable functions
containing metadirectives with 'construct={target}' in the selector.
* omp-general.c (omp_has_target_constructor_p): New.
* omp-general.h (omp_has_target_constructor_p): New prototype.
* omp-low.c (lower_omp_1): Emit warning if marked functions called
outside of a target context.

gcc/testsuite/
* c-c++-common/gomp/metadirective-4.c (main): Add expected warning.
* gfortran.dg/gomp/metadirective-4.f90 (test): Likewise.

libgomp/
* testsuite/libgomp.c-c++-common/metadirective-2.c (main): Add
expected warning.
* testsuite/libgomp.fortran/metadirective-2.f90 (test): Likewise.
gcc/gimplify.c
gcc/omp-general.c
gcc/omp-general.h
gcc/omp-low.c
gcc/testsuite/c-c++-common/gomp/metadirective-4.c
gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90
libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c
libgomp/testsuite/libgomp.fortran/metadirective-2.f90