[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:41 PDT 2025


================
@@ -3321,27 +3321,33 @@ SemaOpenMP::CheckOMPThreadPrivateDecl(SourceLocation Loc,
   }
   return D;
 }
-
 static OMPAllocateDeclAttr::AllocatorTypeTy
 getAllocatorKind(Sema &S, DSAStackTy *Stack, Expr *Allocator) {
+  // No allocator expression → Null mem alloc (matches existing tests).
   if (!Allocator)
     return OMPAllocateDeclAttr::OMPNullMemAlloc;
+
   if (Allocator->isTypeDependent() || Allocator->isValueDependent() ||
       Allocator->isInstantiationDependent() ||
       Allocator->containsUnexpandedParameterPack())
     return OMPAllocateDeclAttr::OMPUserDefinedMemAlloc;
+
   auto AllocatorKindRes = OMPAllocateDeclAttr::OMPUserDefinedMemAlloc;
+
   llvm::FoldingSetNodeID AEId;
   const Expr *AE = Allocator->IgnoreParenImpCasts();
-  AE->IgnoreImpCasts()->Profile(AEId, S.getASTContext(), /*Canonical=*/true);
+  AE->Profile(AEId, S.getASTContext(), /*Canonical=*/true);
+
   for (int I = 0; I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) {
-    auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I);
-    const Expr *DefAllocator = Stack->getAllocator(AllocatorKind);
+    auto K = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I);
+    const Expr *Def = Stack->getAllocator(K);
----------------
shafik wrote:

Same comment, please keep the old more descriptive name.

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


More information about the cfe-commits mailing list