[clang] [flang] [clang][OpenMP] Diagnose invalid allocator in `#pragma omp allocate`; avoid null deref (PR #158146)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 11 13:51:40 PDT 2025


================
@@ -3445,30 +3451,27 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPAllocateDirective(
       else
         llvm_unreachable("Unexpected clause on allocate directive");
   }
+  // No forward-decl needed; just classify with null-guards.
   OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind =
       getAllocatorKind(SemaRef, DSAStack, Allocator);
   SmallVector<Expr *, 8> Vars;
   for (Expr *RefExpr : VarList) {
     auto *DE = cast<DeclRefExpr>(RefExpr);
     auto *VD = cast<VarDecl>(DE->getDecl());
 
-    // Check if this is a TLS variable or global register.
+    // Skip TLS/global-registers.
     if (VD->getTLSKind() != VarDecl::TLS_None ||
         VD->hasAttr<OMPThreadPrivateDeclAttr>() ||
         (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() &&
          !VD->isLocalVarDecl()))
       continue;
 
-    // If the used several times in the allocate directive, the same allocator
-    // must be used.
+    // Enforce same allocator if repeated.
     if (checkPreviousOMPAllocateAttribute(SemaRef, DSAStack, RefExpr, VD,
                                           AllocatorKind, Allocator))
       continue;
 
-    // OpenMP, 2.11.3 allocate Directive, Restrictions, C / C++
-    // If a list item has a static storage type, the allocator expression in the
-    // allocator clause must be a constant expression that evaluates to one of
-    // the predefined memory allocator values.
+    // For static storage, allocator must be predefined.
----------------
shafik wrote:

The previous comment is more helpful, please revert this change.

https://github.com/llvm/llvm-project/pull/158146


More information about the cfe-commits mailing list