[clang] [OpenMP] Fix firstprivate pointer handling in target regions (PR #167879)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 19 06:28:09 PST 2025


================
@@ -9565,6 +9575,38 @@ class MappableExprsHandler {
     }
   }
 
+  /// Check if a variable should be treated as firstprivate due to explicit
+  /// firstprivate clause or defaultmap(firstprivate:...).
+  bool isEffectivelyFirstprivate(const VarDecl *VD, QualType Type) const {
+    // Check explicit firstprivate clauses
+    if (FirstPrivateDecls.count(VD))
+      return true;
+
+    // Check defaultmap(firstprivate:scalar) for scalar types
+    if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_scalar)) {
+      if (Type->isScalarType())
+        return true;
+    }
+
+    // Check defaultmap(firstprivate:pointer) for pointer types
+    if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_pointer)) {
+      if (Type->isAnyPointerType())
+        return true;
+    }
+
+    // Check defaultmap(firstprivate:aggregate) for aggregate types
+    if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_aggregate)) {
+      if (Type->isAggregateType())
+        return true;
+    }
+
+    // Check defaultmap(firstprivate:all) for all types
+    if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_all))
+      return true;
+
+    return false;
----------------
alexey-bataev wrote:

```suggestion
   return DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_all);
```

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


More information about the cfe-commits mailing list