Skip to content

Conversation

@ddpagan
Copy link
Contributor

@ddpagan ddpagan commented Nov 12, 2025

The variable-category 'allocatable' is explicitly noted as applying only to Fortran. If specified in C/C++ it should generate an error. NOTE: Issue will be filed against OpenMP 6.0 specification that restriction is missing from 'default' clause section.

From the OpenMP 6.0 specification:
Section 7.5.1 default Clause
Semantics, under Fortran only, L18-19, pg. 223
The allocatable variable-category specifies variables with the ALLOCATABLE
attribute.

Section 7.9.9 defaultmap Clause
Semantics, under Fortran only, L9-10, pg. 292
The allocatable variable-category specifies variables with the ALLOCATABLE
attribute.

Restrictions, C/C++
  L1, pg. 293
  The specified variable-category must not be allocatable.

… C/C++

The variable-category 'allocatable' is explicitly noted as applying only to
Fortran. If specified in C/C++ it should generate an error. NOTE: Issue
will be filed against OpenMP 6.0 specification that restriction is missing
from 'default' clause section.

From the OpenMP 6.0 specification:
  Section 7.5.1 default Clause
    Semantics, under Fortran only, L18-19, pg. 223
    The allocatable variable-category specifies variables with the ALLOCATABLE
    attribute.

  Section 7.9.9 defaultmap Clause
    Semantics, under Fortran only, L9-10, pg. 292
    The allocatable variable-category specifies variables with the ALLOCATABLE
    attribute.

    Restrictions, C/C++
      L1, pg. 293
      The specified variable-category must not be allocatable.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels Nov 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2025

@llvm/pr-subscribers-clang

Author: David Pagan (ddpagan)

Changes

The variable-category 'allocatable' is explicitly noted as applying only to Fortran. If specified in C/C++ it should generate an error. NOTE: Issue will be filed against OpenMP 6.0 specification that restriction is missing from 'default' clause section.

From the OpenMP 6.0 specification:
Section 7.5.1 default Clause
Semantics, under Fortran only, L18-19, pg. 223
The allocatable variable-category specifies variables with the ALLOCATABLE
attribute.

Section 7.9.9 defaultmap Clause
Semantics, under Fortran only, L9-10, pg. 292
The allocatable variable-category specifies variables with the ALLOCATABLE
attribute.

Restrictions, C/C++
  L1, pg. 293
  The specified variable-category must not be allocatable.

Full diff: https://github.com/llvm/llvm-project/pull/167735.diff

3 Files Affected:

  • (modified) clang/include/clang/Basic/OpenMPKinds.def (-1)
  • (modified) clang/lib/Sema/SemaOpenMP.cpp (-11)
  • (modified) clang/test/OpenMP/parallel_default_messages.cpp (+5)
diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def
index 166b80314f687..da0cbafd05a5b 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -127,7 +127,6 @@ OPENMP_DEVICE_MODIFIER(device_num)
 // Variable-category attributes for 'default' clause.
 OPENMP_DEFAULT_VARIABLE_CATEGORY(aggregate)
 OPENMP_DEFAULT_VARIABLE_CATEGORY(all)
-OPENMP_DEFAULT_VARIABLE_CATEGORY(allocatable)
 OPENMP_DEFAULT_VARIABLE_CATEGORY(pointer)
 OPENMP_DEFAULT_VARIABLE_CATEGORY(scalar)
 
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 2ab2fd10a942e..06cc7ec28ae90 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -80,7 +80,6 @@ enum DefaultDataSharingAttributes {
 enum DefaultDataSharingVCAttributes {
   DSA_VC_all = 0,     /// for all variables.
   DSA_VC_aggregate,   /// for aggregate variables.
-  DSA_VC_allocatable, /// for allocatable variables.
   DSA_VC_pointer,     /// for pointer variables.
   DSA_VC_scalar,      /// for scalar variables.
 };
@@ -760,11 +759,6 @@ class DSAStackTy {
     getTopOfStack().DefaultVCAttr = DSA_VC_all;
     getTopOfStack().DefaultAttrVCLoc = VCLoc;
   }
-  /// Set default data sharing variable category attribute to allocatable.
-  void setDefaultDSAVCAllocatable(SourceLocation VCLoc) {
-    getTopOfStack().DefaultVCAttr = DSA_VC_allocatable;
-    getTopOfStack().DefaultAttrVCLoc = VCLoc;
-  }
   /// Set default data sharing variable category attribute to pointer.
   void setDefaultDSAVCPointer(SourceLocation VCLoc) {
     getTopOfStack().DefaultVCAttr = DSA_VC_pointer;
@@ -1373,11 +1367,6 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter,
     if (!VD->getType()->isAggregateType())
       IterDA = DSA_none;
     break;
-  case DSA_VC_allocatable:
-    if (!(VD->getType()->isPointerType() ||
-          VD->getType()->isVariableArrayType()))
-      IterDA = DSA_none;
-    break;
   case DSA_VC_pointer:
     if (!VD->getType()->isPointerType())
       IterDA = DSA_none;
diff --git a/clang/test/OpenMP/parallel_default_messages.cpp b/clang/test/OpenMP/parallel_default_messages.cpp
index 842b1ac5a96b8..b1d62118e0440 100644
--- a/clang/test/OpenMP/parallel_default_messages.cpp
+++ b/clang/test/OpenMP/parallel_default_messages.cpp
@@ -64,6 +64,11 @@ int main(int argc, char **argv) {
     ++x;
     ++y;
   }
+#pragma omp parallel default(private: allocatable) private(x,y) // expected-error {{wrong variable category specified with modifier private in the default clause}}
+  {
+    ++x;
+    ++y;
+  }
 #endif
   return 0;
 }

@github-actions
Copy link

github-actions bot commented Nov 12, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ddpagan ddpagan merged commit db5b398 into llvm:main Nov 13, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants