[Openmp-commits] [PATCH] D112005: [OpenMP] Check output of malloc in the device for debug

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Oct 18 08:43:52 PDT 2021


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

A common problem is the device running out of global heap memory and
crashing due to a nullptr dereference when using the data sharing stack.
This explicitly checks that a nullptr was not returned by malloc when
debugging field 1 is enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112005

Files:
  openmp/libomptarget/DeviceRTL/src/State.cpp


Index: openmp/libomptarget/DeviceRTL/src/State.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/State.cpp
+++ openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -162,7 +162,9 @@
 }
 
 void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
-  return malloc(Bytes);
+  void *Ptr = malloc(Bytes);
+  ASSERT(Ptr != nullptr && "Nullptr returned by malloc!");
+  return Ptr;
 }
 
 void memory::freeGlobal(void *Ptr, const char *Reason) { free(Ptr); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112005.380420.patch
Type: text/x-patch
Size: 511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211018/fbefd33b/attachment.bin>


More information about the Openmp-commits mailing list