[llvm] [Offload] Introduce ATTACH map-type support for pointer attachment. (PR #149036)

Abhinav Gaba via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 11 04:13:11 PDT 2025


================
@@ -821,19 +821,22 @@ int processAttachEntries(DeviceTy &Device, AttachInfoTy &AttachInfo,
       return TPR;
     };
 
-    // Get device version of the pointer (e.g., &p)
+    // Get device version of the pointee (e.g., &p[10]) first, as we can
+    // release its TPR after extracting the pointer value.
+    void *TgtPteeBegin;
+    if (auto PteeTPROpt = LookupTargetPointer(HstPteeBegin, 0, "pointee"))
+      TgtPteeBegin = PteeTPROpt->TargetPointer;
+    else
+      continue;
----------------
abhinavgaba wrote:

Adding the braces will only change the condition. TgtPteeBegin will still be uninitialized at the declaration, unless it's explicitly initialized to null.

```cpp
void *TgtPteeBegin; // The declaration has to be outside the scope of the braces.
{
  auto PteeTPROpt = LookupTargetPointer(HstPteeBegin, 0, "pointee");
  if (!PteeTPROpt)
    TgtPteeBegin = PteeTPROpt->TargetPointer;
}
```

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


More information about the llvm-commits mailing list