[clang] [llvm] [Clang][OpenMP] Capture mapped pointers on `target` by reference. (PR #145454)

Abhinav Gaba via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 23 21:14:05 PDT 2025


================
@@ -8811,8 +8829,19 @@ class MappableExprsHandler {
         ++EI;
       }
     }
-    llvm::stable_sort(DeclComponentLists, [](const MapData &LHS,
-                                             const MapData &RHS) {
+    llvm::stable_sort(DeclComponentLists, [VD](const MapData &LHS,
+                                               const MapData &RHS) {
+      // For cases like map(p, p[0], p[0][0]), the shortest map, like map(p)
+      // in this case, should be handled first, to ensure that it gets the
+      // TARGET_PARAM flag.
+      OMPClauseMappableExprCommon::MappableExprComponentListRef Components =
+          std::get<0>(LHS);
+      OMPClauseMappableExprCommon::MappableExprComponentListRef ComponentsR =
+          std::get<0>(RHS);
+      if (VD && VD->getType()->isAnyPointerType() && Components.size() == 1 &&
+          ComponentsR.size() > 1)
+        return true;
----------------
abhinavgaba wrote:

Is the following preferable?

```cpp
      const Expr *E = std::get<5>(LHS);
      const Expr *ER = std::get<5>(RHS);
      if (VD && VD->getType()->isAnyPointerType() &&
          isa_and_present<DeclRefExpr>(E) && !isa_and_present<DeclRefExpr>(ER))

```

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


More information about the cfe-commits mailing list