https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127817
Bug ID: 127817
Summary: [OpenMP] indirect refuses to accept anything that
isn't a literal 0 as false
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: openmp, rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
void f ();
#pragma omp declare target enter(f) indirect(1 == 2) device_type(host)
constexpr bool b = false;
void g ();
#pragma omp declare target enter(g) indirect(b) device_type(host)
This C++11 program should, as far as I can tell, validly compile. GCC trunk,
16, 15 and 14 (those below don't implement indirect) (with -fopenmp -std=c++11)
disagrees:
<source>:2:54: error: 'device_type' clause must specify 'any' when used with an
'indirect' clause
2 | #pragma omp declare target enter(f) indirect(1 == 2) device_type(host)
| ^~~~~~~~~~~
<source>:6:49: error: 'device_type' clause must specify 'any' when used with an
'indirect' clause
6 | #pragma omp declare target enter(g) indirect(b) device_type(host)
| ^~~~~~~~~~~
...despite the fact that device_type(host) is fine if invoked-by-fptr in
indirect(invoked-by-fptr) does not evaluate to true.
They appear to be parsing indirect such that anything that isn't a literal 0 is
treated as if it were true:
(in cp_parser_omp_declare_target)
for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
{
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE)
device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c);
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_INDIRECT)
indirect |= !integer_zerop (OMP_CLAUSE_INDIRECT_EXPR (c));
}
I assume this should be actually evaluating the indirect clause (I have not
personally tested such a fix). I would also assume that anything that does
error (e.g. if this used device_type(any)) would simply incorrectly register
the function for indirect calling.