1 Reply Latest reply on Nov 5, 2014 3:33 AM by dipak

    clBuildProgram segmentation fault (SEGV) with uninitialized pointer

    mungerd

      This is possibly a bug report.

       

      clBuildProgram() crashes instead of reporting an error when accessing index get_global_id() of an uninitialized pointer.  Here is a minimal example in C++:

       

      #define __CL_ENABLE_EXCEPTIONS
      #include <CL/cl.hpp>
      #include <iostream>
      
      int main(int argc, char** argv) {
        try {
          std::vector <cl::Platform> platforms;
          cl::Platform::get(&platforms);
          cl_context_properties properties[] = 
              {CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
          cl::Context context(CL_DEVICE_TYPE_CPU, properties);
          std::vector<cl::Device> devices;
          devices = context.getInfo<CL_CONTEXT_DEVICES>();
          std::string prog_str = "__kernel void minex() { int *x; x[get_global_id(0)] = 0; }";
          cl::Program::Sources source(1, std::make_pair(prog_str.c_str(),prog_str.length()));
          cl::Program program(context, source);
          program.build(devices,""); // SEGV here from clBuildProgram
          return EXIT_SUCCESS;
        }
        catch (cl::Error& e) {
          std::cerr << "ERROR: " << e.what() << " - " << e.err() << std::endl;
          return EXIT_FAILURE;
        }
      }