clover: Don't segfault when compiling a program with no kernel
authorTom Stellard <thomas.stellard@amd.com>
Thu, 6 Jun 2013 00:05:43 +0000 (17:05 -0700)
committerTom Stellard <thomas.stellard@amd.com>
Fri, 28 Jun 2013 22:19:06 +0000 (15:19 -0700)
src/gallium/state_trackers/clover/llvm/invocation.cpp

index 90bc53b238c55ee705355dee5836a7359438c83b..dae61f7fa7dc11e8ced6dc3cc7c1881a8496ee42 100644 (file)
@@ -211,6 +211,13 @@ namespace {
    find_kernels(llvm::Module *mod, std::vector<llvm::Function *> &kernels) {
       const llvm::NamedMDNode *kernel_node =
                                  mod->getNamedMetadata("opencl.kernels");
+      // This means there are no kernels in the program.  The spec does not
+      // require that we return an error here, but there will be an error if
+      // the user tries to pass this program to a clCreateKernel() call.
+      if (!kernel_node) {
+         return;
+      }
+
       for (unsigned i = 0; i < kernel_node->getNumOperands(); ++i) {
          kernels.push_back(llvm::dyn_cast<llvm::Function>(
                                     kernel_node->getOperand(i)->getOperand(0)));