diff --git a/openmp/libomptarget/DeviceRTL/include/State.h b/openmp/libomptarget/DeviceRTL/include/State.h --- a/openmp/libomptarget/DeviceRTL/include/State.h +++ b/openmp/libomptarget/DeviceRTL/include/State.h @@ -277,7 +277,8 @@ template struct ValueRAII { ValueRAII(VTy &V, Ty NewValue, Ty OldValue, bool Active, IdentTy *Ident) - : Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) : nullptr), + : Ptr(Active ? &V.lookup(/* IsReadonly */ false, Ident) + : (Ty *)utils::UndefPtr), Val(OldValue), Active(Active) { if (!Active) return; diff --git a/openmp/libomptarget/DeviceRTL/include/Utils.h b/openmp/libomptarget/DeviceRTL/include/Utils.h --- a/openmp/libomptarget/DeviceRTL/include/Utils.h +++ b/openmp/libomptarget/DeviceRTL/include/Utils.h @@ -14,6 +14,8 @@ #include "Types.h" +#pragma omp begin declare target device_type(nohost) + namespace _OMP { namespace utils { @@ -72,10 +74,15 @@ return V - V % Align; } +/// A pointer variable that has by design an `undef` value. Use with care. +__attribute__((loader_uninitialized)) static void *const UndefPtr; + #define OMP_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) #define OMP_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) } // namespace utils } // namespace _OMP +#pragma omp end declare target + #endif