Clang error: the user condition in the OpenMP context selector needs to be constant; A is not (err_omp_declare_variant_user_condition_not_constant)
Jump to navigation
Jump to search
| Text | error: the user condition in the OpenMP context selector needs to be constant; A is not (since 11.0) |
|---|---|
| Type | Error |
| Category | OpenMP Issue (since 11.0) |
| Internal Id | err_omp_declare_variant_user_condition_not_constant (since 11.0) |
| Internal Message | the user condition in the OpenMP context selector needs to be constant; %0 is not (since 11.0)
|
| Regular Expression | (?:error|fatal error)\: the user condition in the OpenMP context selector needs to be constant; (.*?) is not
|
| First Commit | 2019-12-20 1228d42ddab8 [OpenMP][Part 2] Use reusable OpenMP context/traits handling |
Description
Example
| Flags | -xc -fopenmp
|
|
|---|---|---|
| Source |
#pragma omp declare variant(f) match(user={condition(x)})
int f(int x) { return x * 2; }
int x; // Non-constant variable
int main() {}
| |
| Compiler Output |
<source>:1:54: error: the user condition in the OpenMP context selector needs to be constant; x is not |
Clang Internals (17.0.6)
Git Commit Message
[OpenMP][Part 2] Use reusable OpenMP context/traits handling
This patch implements an almost complete handling of OpenMP
contexts/traits such that we can reuse most of the logic in Flang
through the OMPContext.{h,cpp} in llvm/Frontend/OpenMP.
All but construct SIMD specifiers, e.g., inbranch, and the device ISA
selector are define in `llvm/lib/Frontend/OpenMP/OMPKinds.def`. From
these definitions we generate the enum classes `TraitSet`,
`TraitSelector`, and `TraitProperty` as well as conversion and helper
functions in `llvm/lib/Frontend/OpenMP/OMPContext.{h,cpp}`.
The above enum classes are used in the parser, sema, and the AST
attribute. The latter is not a collection of multiple primitive variant
arguments that contain encodings via numbers and strings but instead a
tree that mirrors the `match` clause (see `struct OpenMPTraitInfo`).
The changes to the parser make it more forgiving when wrong syntax is
read and they also resulted in more specialized diagnostics. The tests
are updated and the core issues are detected as before. Here and
elsewhere this patch tries to be generic, thus we do not distinguish
what selector set, selector, or property is parsed except if they do
behave exceptionally, as for example `user={condition(EXPR)}` does.
The sema logic changed in two ways: First, the OMPDeclareVariantAttr
representation changed, as mentioned above, and the sema was adjusted to
work with the new `OpenMPTraitInfo`. Second, the matching and scoring
logic moved into `OMPContext.{h,cpp}`. It is implemented on a flat
representation of the `match` clause that is not tied to clang.
`OpenMPTraitInfo` provides a method to generate this flat structure (see
`struct VariantMatchInfo`) by computing integer score values and boolean
user conditions from the `clang::Expr` we keep for them.
The OpenMP context is now an explicit object (see `struct OMPContext`).
This is in anticipation of construct traits that need to be tracked. The
OpenMP context, as well as the `VariantMatchInfo`, are basically made up
of a set of active or respectively required traits, e.g., 'host', and an
ordered container of constructs which allows duplication. Matching and
scoring is kept as generic as possible to allow easy extension in the
future.
---
Test changes:
The messages checked in `OpenMP/declare_variant_messages.{c,cpp}` have
been auto generated to match the new warnings and notes of the parser.
The "subset" checks were reversed causing the wrong version to be
picked. The tests have been adjusted to correct this.
We do not print scores if the user did not provide one.
We print spaces to make lists in the `match` clause more legible.
Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim
Subscribers: merge_guards_bot, rampitec, mgorny, hiraditya, aheejin, fedor.sergeev, simoncook, bollu, guansong, dexonsmith, jfb, s.egerton, llvm-commits, cfe-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D71830
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaOpenMP.cpp (line 7430)
std::optional<std::pair<FunctionDecl *, Expr *>> Sema::checkOpenMPDeclareVariantFunction(Sema::DeclGroupPtrTy DG, Expr *VariantRef, OMPTraitInfo &TI, unsigned NumAppendArgs, SourceRange SR) {
// ...
// Deal with non-constant score and user condition expressions.
auto HandleNonConstantScoresAndConditions = [this](Expr *&E, bool IsScore) -> bool {
// ...
if (IsScore) {
// ...
} else {
// ...
Diag(E->getExprLoc(), diag::err_omp_declare_variant_user_condition_not_constant) << E;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/OpenMP/declare_variant_messages.c
- clang/test/OpenMP/declare_variant_messages.c:57:58: error: the user condition in the OpenMP context selector needs to be constant; foo() is not
- clang/test/OpenMP/declare_variant_messages.c:56:58: error: the user condition in the OpenMP context selector needs to be constant; foo is not