================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to