diff --git a/openmp/libomptarget/DeviceRTL/include/Configuration.h b/openmp/libomptarget/DeviceRTL/include/Configuration.h --- a/openmp/libomptarget/DeviceRTL/include/Configuration.h +++ b/openmp/libomptarget/DeviceRTL/include/Configuration.h @@ -21,6 +21,7 @@ enum DebugKind : uint32_t { Assertion = 1U << 0, FunctionTracing = 1U << 1, + CommonIssues = 1U << 2, }; /// Return the number of devices in the system, same number as returned on the diff --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp --- a/openmp/libomptarget/DeviceRTL/src/State.cpp +++ b/openmp/libomptarget/DeviceRTL/src/State.cpp @@ -134,9 +134,12 @@ return Ptr; } - return memory::allocGlobal(AlignedBytes, - "Slow path shared memory allocation, insufficient " - "shared memory stack memory!"); + void *GlobalMemory = memory::allocGlobal( + AlignedBytes, "Slow path shared memory allocation, insufficient " + "shared memory stack memory!"); + ASSERT(GlobalMemory != nullptr && "nullptr returned by malloc!"); + + return GlobalMemory; } void SharedMemorySmartStackTy::pop(void *Ptr, uint32_t Bytes) { @@ -162,7 +165,10 @@ } void *memory::allocGlobal(uint64_t Bytes, const char *Reason) { - return malloc(Bytes); + void *Ptr = malloc(Bytes); + if (config::isDebugMode(config::DebugKind::CommonIssues) && Ptr == nullptr) + PRINT("nullptr returned by malloc!\n"); + return Ptr; } void memory::freeGlobal(void *Ptr, const char *Reason) { free(Ptr); } @@ -280,6 +286,7 @@ if (!ThreadStates[TId]) { ThreadStates[TId] = reinterpret_cast(memory::allocGlobal( sizeof(ThreadStateTy), "ICV modification outside data environment")); + ASSERT(ThreadStates[TId] != nullptr && "Nullptr returned by malloc!"); ThreadStates[TId]->init(); } return ThreadStates[TId]->ICVState.*Var; @@ -531,6 +538,8 @@ } else { SharedMemVariableSharingSpacePtr = (void **)memory::allocGlobal( nArgs * sizeof(void *), "new extended args"); + ASSERT(SharedMemVariableSharingSpacePtr != nullptr && + "Nullptr returned by malloc!"); } *GlobalArgs = SharedMemVariableSharingSpacePtr; }