Clang error: expected... variable of type 'omp_interop_t' (err_omp_interop_variable_expected)

From emmtrix Wiki
Jump to navigation Jump to search
Text
error: expected
 
non-const
variable of type 'omp_interop_t'

(since 13.0)

Type Error
Category OpenMP Issue (since 13.0)
Internal Id err_omp_interop_variable_expected (since 13.0)
Internal Message expected%select{| non-const}0 variable of type 'omp_interop_t' (since 13.0)
Regular Expression (?:error|fatal error)\: expected(?:| non\-const) variable of type 'omp_interop_t'
First Commit 2020-05-20 61d065e21ff3 Let clang atomic builtins fetch add/sub support floating point types

Description

The error is issued by the Clang compiler when an operation involving the OpenMP interoperability type, omp_interop_t, does not conform to the expected usage patterns defined by the OpenMP specification. Specifically, this diagnostic message arises in situations where:
  • A variable of type omp_interop_t is used in a context that requires a mutable (non-const) object, but the variable is either explicitly declared as const or is otherwise determined to be constant in the context of its usage. OpenMP interoperability constructs, such as those involving initialization or destruction of interoperability objects, stipulate that the interoperability variable must be modifiable.
  • An attempt is made to use a constant omp_interop_t variable with OpenMP pragmas that expect a mutable interoperability variable to correctly perform operations like initialization, use, destruction, or synchronization with target devices.

This error ensures compliance with the OpenMP standard, which is designed to facilitate efficient and correct parallel computation by explicitly managing the constancy and mutability of variables involved in parallel operations.

 
AI Generated

Example

In the following example, an attempted use of the OpenMP interoperability type omp_interop_t is demonstrated to cause compilation errors under specific circumstances. Initially, an instance of omp_interop_t is incorrectly initialized to an integer value, which does not adhere to the OpenMP standard for initializing interoperability variables. Following this, a constant omp_interop_t variable is defined, which is a misuse since OpenMP interoperability mechanisms require variables that can be modified to ensure proper initiation, use, destruction, or synchronization with target devices.

The critical issue arises when the const interop variable is utilized in a #pragma omp interop directive for the purpose of 'targetsync'. However, the OpenMP specification mandates that variables used in this context must be non-const to allow for their modification during the operation of the directive. The resulting compilation errors directly point out the misuse of a const variable where a mutable one is expected, alongside the expectation of specifying at least one directive clause that operates on the variable.

Overall, the example serves to underline the importance of adhering to the OpenMP requirements for mutability and proper initialization of omp_interop_t variables, especially when they are intended for use with OpenMP pragmas that facilitate interoperability operations.

 
AI Generated


Flags -fopenmp -xc

[Try out in Compiler Explorer]

Source
#include <omp.h>

int main() {
  omp_interop_t i = 0; // Initialization not according to omp_interop_t requirements
  const omp_interop_t c = i; // Constant type not allowed with interop

  #pragma omp interop init(targetsync: c) // const variable used here
}
Compiler Output
<source>:7:40: error: expected non-const variable of type 'omp_interop_t'
<source>:7:3: error: expected at least one 'init', 'use', 'destroy', or 'nowait' clause for '#pragma omp interop'


Clang Internals (17.0.6)

Git Commit Message

Let clang atomic builtins fetch add/sub support floating point types

Recently atomicrmw started to support fadd/fsub:

https://reviews.llvm.org/D53965

However clang atomic builtins fetch add/sub still does not support
emitting atomicrmw fadd/fsub.

This patch adds that.

Reviewed by: John McCall, Artem Belevich, Matt Arsenault, JF Bastien,
James Y Knight, Louis Dionne, Olivier Giroux

Differential Revision: https://reviews.llvm.org/D71726

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 17685)

static bool isValidInteropVariable(Sema &SemaRef, Expr *InteropVarExpr, SourceLocation VarLoc, OpenMPClauseKind Kind) {
  // ...
  // OpenMP 5.1 [2.15.1, interop Construct, Restrictions]
  // The interop-var passed to init or destroy must be non-const.
  if ((Kind == OMPC_init || Kind == OMPC_destroy) && isConstNotMutableType(SemaRef, InteropVarExpr->getType())) {
    SemaRef.Diag(VarLoc, diag::err_omp_interop_variable_expected) << /*non-const*/ 1;

Triggered in Clang Tests

This section lists all internal Clang test cases that trigger the diagnostic.

clang/test/OpenMP/interop_messages.cpp

  • clang/test/OpenMP/interop_messages.cpp:197:50: error: expected variable of type 'omp_interop_t'
  • clang/test/OpenMP/interop_messages.cpp:200:52: error: expected variable of type 'omp_interop_t'