From e7e1827e573e70c2014d34a9ffa7c91fdb55b89f Mon Sep 17 00:00:00 2001
From: Axel Kohlmeyer <akohlmey@gmail.com>
Date: Tue, 8 May 2018 00:48:53 -0400
Subject: [PATCH] remove variable length arrays in gpu lib

---
 lib/gpu/geryon/ocl_device.h | 7 ++++---
 lib/gpu/geryon/ocl_kernel.h | 5 +++--
 lib/gpu/geryon/ocl_memory.h | 3 ++-
 lib/gpu/lal_device.cpp      | 3 ++-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lib/gpu/geryon/ocl_device.h b/lib/gpu/geryon/ocl_device.h
index 138b03c091..584d04e616 100644
--- a/lib/gpu/geryon/ocl_device.h
+++ b/lib/gpu/geryon/ocl_device.h
@@ -353,7 +353,7 @@ int UCL_Device::set_platform(int pid) {
     _num_devices=0;
     return UCL_ERROR;
   }
-  cl_device_id device_list[_num_devices];
+  cl_device_id *device_list = new cl_device_id[_num_devices];
   CL_SAFE_CALL(clGetDeviceIDs(_cl_platform,CL_DEVICE_TYPE_ALL,n,device_list,
                               &n));
 
@@ -362,7 +362,7 @@ int UCL_Device::set_platform(int pid) {
     _cl_devices.push_back(device_list[i]);
     add_properties(device_list[i]);
   }
-
+  delete[] device_list;
   return UCL_SUCCESS;
 }
 
@@ -518,13 +518,14 @@ int UCL_Device::device_type(const int i) {
 int UCL_Device::set(int num) {
   clear();
 
-  cl_device_id device_list[_num_devices];
+  cl_device_id *device_list = new cl_device_id[_num_devices];
   cl_uint n;
   CL_SAFE_CALL(clGetDeviceIDs(_cl_platform,CL_DEVICE_TYPE_ALL,_num_devices,
                                device_list,&n));
 
   _device=num;
   _cl_device=device_list[_device];
+  delete[] device_list;
   return create_context();
 }
 
diff --git a/lib/gpu/geryon/ocl_kernel.h b/lib/gpu/geryon/ocl_kernel.h
index e4c37b2a77..b65049b9e6 100644
--- a/lib/gpu/geryon/ocl_kernel.h
+++ b/lib/gpu/geryon/ocl_kernel.h
@@ -111,7 +111,7 @@ class UCL_Program {
       size_t ms;
       CL_SAFE_CALL(clGetProgramBuildInfo(_program,_device,CL_PROGRAM_BUILD_LOG,0,
                                          NULL, &ms));
-      char build_log[ms];
+      char *build_log = new char[ms];
       CL_SAFE_CALL(clGetProgramBuildInfo(_program,_device,CL_PROGRAM_BUILD_LOG,ms,
                                          build_log, NULL));
 
@@ -127,8 +127,9 @@ class UCL_Program {
                   << "----------------------------------------------------------\n";
         std::cerr << build_log << std::endl;
         #endif
+        delete[] build_log;
         return UCL_COMPILE_ERROR;
-      }
+      } else delete[] build_log;
     }
 
     return UCL_SUCCESS;
diff --git a/lib/gpu/geryon/ocl_memory.h b/lib/gpu/geryon/ocl_memory.h
index 28bb88941f..9692f4dd7b 100644
--- a/lib/gpu/geryon/ocl_memory.h
+++ b/lib/gpu/geryon/ocl_memory.h
@@ -407,7 +407,7 @@ inline void _ocl_build(cl_program &program, cl_device_id &device,
   size_t ms;
   CL_SAFE_CALL(clGetProgramBuildInfo(program, device,CL_PROGRAM_BUILD_LOG, 0,
                                      NULL, &ms));
-  char build_log[ms];
+  char *build_log = new char[ms];
   CL_SAFE_CALL(clGetProgramBuildInfo(program,device,CL_PROGRAM_BUILD_LOG,ms,
                                      build_log, NULL));
 
@@ -416,6 +416,7 @@ inline void _ocl_build(cl_program &program, cl_device_id &device,
             << " Error compiling OpenCL Program...\n"
             << "----------------------------------------------------------\n";
   std::cerr << build_log << std::endl;
+  delete[] build_log;
 }
 
 inline void _ocl_kernel_from_source(cl_context &context, cl_device_id &device,
diff --git a/lib/gpu/lal_device.cpp b/lib/gpu/lal_device.cpp
index 25f1cea7d4..c58b484e4e 100644
--- a/lib/gpu/lal_device.cpp
+++ b/lib/gpu/lal_device.cpp
@@ -78,7 +78,7 @@ int DeviceT::init_device(MPI_Comm world, MPI_Comm replica, const int first_gpu,
   // Get the names of all nodes
   int name_length;
   char node_name[MPI_MAX_PROCESSOR_NAME];
-  char node_names[MPI_MAX_PROCESSOR_NAME*_world_size];
+  char *node_names = new char[MPI_MAX_PROCESSOR_NAME*_world_size];
   MPI_Get_processor_name(node_name,&name_length);
   MPI_Allgather(&node_name,MPI_MAX_PROCESSOR_NAME,MPI_CHAR,&node_names,
                 MPI_MAX_PROCESSOR_NAME,MPI_CHAR,_comm_world);
@@ -104,6 +104,7 @@ int DeviceT::init_device(MPI_Comm world, MPI_Comm replica, const int first_gpu,
       split_id=split_num;
     split_num++;
   }
+  delete[] node_names;
 
   // Set up a per node communicator and find rank within
   MPI_Comm node_comm;
-- 
GitLab