Clang error: Only one A clause can appear on a requires directive in a single translation unit (err_omp_requires_clause_redeclaration)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: Only one A clause can appear on a requires directive in a single translation unit (since 8.0)
Type Error
Category OpenMP Issue (since 8.0)
Internal Id err_omp_requires_clause_redeclaration (since 8.0)
Internal Message Only one %0 clause can appear on a requires directive in a single translation unit (since 8.0)
Regular Expression (?:error|fatal error)\: Only one (.*?) clause can appear on a requires directive in a single translation unit
First Commit 2018-09-26 1408f91a2588 [OPENMP] Add support for OMP5 requires directive + unified_address clause

Description

The error is issued by the Clang compiler when it detects multiple declarations of the same clause within the requires directive in a single translation unit. OpenMP 5.0 introduced the requires directive to specify certain requirements that must be fulfilled by the implementation for the correct execution of the program. This directive may include several clauses, but each clause type is intended to appear only once in all requires directives combined throughout the whole translation unit. A translation unit represents a single source file along with all the headers and source files included in it, directly or indirectly. When a clause is specified more than once, it may lead to conflicts or ambiguities regarding the requirements imposed on the OpenMP implementation, thus violating the OpenMP specification. This error ensures that each unique clause type associated with the requires directive is declared no more than once, maintaining the consistency and clarity of the directives’ requirements.  
AI Generated

Example

In the following example, the Clang compiler issues an error due to the repeated use of the unified_address clause in multiple requires directives within the same translation unit. The initial requires directive correctly specifies the requirement for a unified address space. However, the subsequent requires directive attempts to redeclare this requirement by specifying the unified_address clause again. According to the OpenMP 5.0 specification, each clause within requires directives must be unique for the entire translation unit to prevent conflicts or ambiguities. The compiler detects this duplication and raises an error, indicating the location of both the original and the duplicate clause declarations.  
AI Generated


Flags -xc++ -fopenmp

[Try out in Compiler Explorer]

Source
#pragma omp requires unified_address unified_shared_memory
// Duplicate unified_address
#pragma omp requires unified_address
Compiler Output
<source>:3:22: error: Only one unified_address clause can appear on a requires directive in a single translation unit
<source>:1:22: note: unified_address clause previously used here


Clang Internals (17.0.6)

Git Commit Message

[OPENMP] Add support for OMP5 requires directive + unified_address clause

Add support for OMP5.0 requires directive and unified_address clause.
Patches to follow will include support for additional clauses.

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

llvm-svn: 343063

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

/// Stack for tracking declarations used in OpenMP directives and
/// clauses and their data-sharing attributes.
class DSAStackTy {
  // ...
  /// Checks for a duplicate clause amongst previously declared requires
  /// directives
  bool hasDuplicateRequiresClause(ArrayRef<OMPClause *> ClauseList) const {
    // ...
    for (OMPClause *CNew : ClauseList) {
      for (const OMPRequiresDecl *D : RequiresDecls) {
        for (const OMPClause *CPrev : D->clauselists()) {
          if (CNew->getClauseKind() == CPrev->getClauseKind()) {
            SemaRef.Diag(CNew->getBeginLoc(), diag::err_omp_requires_clause_redeclaration) << getOpenMPClauseName(CNew->getClauseKind());

Triggered in Clang Tests

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

clang/test/OpenMP/requires_default_atomic_mem_order_messages.cpp

  • clang/test/OpenMP/requires_default_atomic_mem_order_messages.cpp:10:22: error: Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit
  • clang/test/OpenMP/requires_default_atomic_mem_order_messages.cpp:11:22: error: Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit