[Openmp-commits] [openmp] c422d69 - [LIBOMPTARGET]Fix PR45139: Bug in mixing Python and OpenMP target offload.

Alexey Bataev via Openmp-commits openmp-commits at lists.llvm.org
Wed Mar 11 06:14:28 PDT 2020


Author: Alexey Bataev
Date: 2020-03-11T09:12:02-04:00
New Revision: c422d69b1ad7ae3fdbe0d4ec795a2931e08459f7

URL: https://github.com/llvm/llvm-project/commit/c422d69b1ad7ae3fdbe0d4ec795a2931e08459f7
DIFF: https://github.com/llvm/llvm-project/commit/c422d69b1ad7ae3fdbe0d4ec795a2931e08459f7.diff

LOG: [LIBOMPTARGET]Fix PR45139: Bug in mixing Python and OpenMP target offload.

Summary: Explicitly initialize data members of RTLsTy class upon construction.

Reviewers: grokos

Subscribers: guansong, openmp-commits, caomhin, kkwli0

Tags: #openmp

Differential Revision: https://reviews.llvm.org/D75946

Added: 
    

Modified: 
    openmp/libomptarget/src/rtl.h

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/rtl.h b/openmp/libomptarget/src/rtl.h
index 633e44b5961c..439efec4ad91 100644
--- a/openmp/libomptarget/src/rtl.h
+++ b/openmp/libomptarget/src/rtl.h
@@ -13,6 +13,7 @@
 #ifndef _OMPTARGET_RTL_H
 #define _OMPTARGET_RTL_H
 
+#include "omptarget.h"
 #include <list>
 #include <map>
 #include <mutex>
@@ -38,33 +39,33 @@ struct RTLInfoTy {
                                       int32_t, int32_t, int32_t, uint64_t);
   typedef int64_t(init_requires_ty)(int64_t);
 
-  int32_t Idx;                     // RTL index, index is the number of devices
-                                   // of other RTLs that were registered before,
-                                   // i.e. the OpenMP index of the first device
-                                   // to be registered with this RTL.
-  int32_t NumberOfDevices;         // Number of devices this RTL deals with.
+  int32_t Idx = -1;             // RTL index, index is the number of devices
+                                // of other RTLs that were registered before,
+                                // i.e. the OpenMP index of the first device
+                                // to be registered with this RTL.
+  int32_t NumberOfDevices = -1; // Number of devices this RTL deals with.
 
-  void *LibraryHandler;
+  void *LibraryHandler = nullptr;
 
 #ifdef OMPTARGET_DEBUG
   std::string RTLName;
 #endif
 
   // Functions implemented in the RTL.
-  is_valid_binary_ty *is_valid_binary;
-  number_of_devices_ty *number_of_devices;
-  init_device_ty *init_device;
-  load_binary_ty *load_binary;
-  data_alloc_ty *data_alloc;
-  data_submit_ty *data_submit;
-  data_retrieve_ty *data_retrieve;
-  data_delete_ty *data_delete;
-  run_region_ty *run_region;
-  run_team_region_ty *run_team_region;
-  init_requires_ty *init_requires;
+  is_valid_binary_ty *is_valid_binary = nullptr;
+  number_of_devices_ty *number_of_devices = nullptr;
+  init_device_ty *init_device = nullptr;
+  load_binary_ty *load_binary = nullptr;
+  data_alloc_ty *data_alloc = nullptr;
+  data_submit_ty *data_submit = nullptr;
+  data_retrieve_ty *data_retrieve = nullptr;
+  data_delete_ty *data_delete = nullptr;
+  run_region_ty *run_region = nullptr;
+  run_team_region_ty *run_team_region = nullptr;
+  init_requires_ty *init_requires = nullptr;
 
   // Are there images associated with this RTL.
-  bool isUsed;
+  bool isUsed = false;
 
   // Mutex for thread-safety when calling RTL interface functions.
   // It is easier to enforce thread-safety at the libomptarget level,
@@ -73,17 +74,9 @@ struct RTLInfoTy {
 
   // The existence of the mutex above makes RTLInfoTy non-copyable.
   // We need to provide a copy constructor explicitly.
-  RTLInfoTy()
-      : Idx(-1), NumberOfDevices(-1), LibraryHandler(0),
-#ifdef OMPTARGET_DEBUG
-        RTLName(),
-#endif
-        is_valid_binary(0), number_of_devices(0), init_device(0),
-        load_binary(0), data_alloc(0), data_submit(0), data_retrieve(0),
-        data_delete(0), run_region(0), run_team_region(0),
-        init_requires(0), isUsed(false), Mtx() {}
+  RTLInfoTy() = default;
 
-  RTLInfoTy(const RTLInfoTy &r) : Mtx() {
+  RTLInfoTy(const RTLInfoTy &r) {
     Idx = r.Idx;
     NumberOfDevices = r.NumberOfDevices;
     LibraryHandler = r.LibraryHandler;
@@ -121,9 +114,9 @@ class RTLsTy {
   // binaries.
   std::vector<RTLInfoTy *> UsedRTLs;
 
-  int64_t RequiresFlags;
+  int64_t RequiresFlags = OMP_REQ_UNDEFINED;
 
-  explicit RTLsTy() {}
+  explicit RTLsTy() = default;
 
   // Register the clauses of the requires directive.
   void RegisterRequires(int64_t flags);
@@ -158,9 +151,9 @@ extern std::mutex *TrlTblMtx;
 
 /// Map between the host ptr and a table index
 struct TableMap {
-  TranslationTable *Table; // table associated with the host ptr.
-  uint32_t Index; // index in which the host ptr translated entry is found.
-  TableMap() : Table(0), Index(0) {}
+  TranslationTable *Table = nullptr; // table associated with the host ptr.
+  uint32_t Index = 0; // index in which the host ptr translated entry is found.
+  TableMap() = default;
   TableMap(TranslationTable *table, uint32_t index)
       : Table(table), Index(index) {}
 };


        


More information about the Openmp-commits mailing list