[clang] [llvm] [OpenMP][Offload] Add FB_NULLIFY map-type for `use_device_ptr(fb_nullify)`. (1/4) (PR #169603)

Abhinav Gaba via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 9 14:53:48 PST 2026


================
@@ -707,14 +707,20 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
         // to references to a local device pointer that refers to this device
         // address.
         //
-        // TODO: Add a new map-type bit to support OpenMP 6.1's `fb_nullify`
-        // and set the result to `nullptr - Delta`. Note that `fb_nullify` is
-        // already the default for `need_device_ptr`, but clang/flang do not
-        // support its codegen yet.
-        TgtPtrBase = reinterpret_cast<void *>(
-            reinterpret_cast<uintptr_t>(HstPtrBegin) - Delta);
-        ODBG(ODT_Mapping) << "Returning host pointer " << TgtPtrBase
-                          << " as fallback (lookup failed)";
+        // OpenMP 6.1's `fb_nullify` fallback behavior: when the FB_NULLIFY bit
+        // is set by the compiler, e.g. for `use/need_device_ptr(fb_nullify)`),
+        // return `nullptr - Delta` when lookup fails.
+        if (ArgTypes[I] & OMP_TGT_MAPTYPE_FB_NULLIFY) {
+          TgtPtrBase = reinterpret_cast<void *>(
+              reinterpret_cast<uintptr_t>(nullptr) - Delta);
+          ODBG(ODT_Mapping) << "Returning offsetted null pointer " << TgtPtrBase
+                            << " as fallback (lookup failed)";
+        } else {
+          TgtPtrBase = reinterpret_cast<void *>(
+              reinterpret_cast<uintptr_t>(HstPtrBegin) - Delta);
----------------
abhinavgaba wrote:

This can just be `HstPtrBase`, but I wrote it like this for readability/consistency with the other cases, since most compilers would optimize it anyway. But we can use `HstPtrBase` directly if that's preferable.

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


More information about the cfe-commits mailing list