cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

mungerd
Journeyman III

clBuildProgram segmentation fault (SEGV) with uninitialized pointer

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;


  }


}



0 Likes
1 Reply
dipak
Staff
Staff

Re: clBuildProgram segmentation fault (SEGV) with uninitialized pointer

Hi,

Thanks for reporting this.

When I tried to build your kernel, I got a compilation error (see attached file) but not any segmentation fault. I also tried to compile the kernel using CodeXL and found similar compilation error. I don't know the reason behind this compilation error. It may be a bug. I'll check with concern team and if required, will file an internal bug report.

Regards,

0 Likes