Allow build errors to be generated also from cmdline issues
Fixes a crash in case there was an issue in the build command line,
which does not yet involve any source code.
@@ -145,19 +145,21 @@ static void get_build_log(cl_program program,
unsigned device_i,
std::stringstream &ss_build_log,
clang::TextDiagnosticBuffer *diagsBuffer,
- const SourceManager &sm)
+ const SourceManager *SM)
{
for (TextDiagnosticBuffer::const_iterator i = diagsBuffer->err_begin(),
e = diagsBuffer->err_end(); i != e; ++i)
{
- ss_build_log << "error: " << i->first.printToString(sm)
- << ": " << i->second << std::endl;
+ ss_build_log << "error: "
+ << (SM == nullptr ? "" : (i->first.printToString(*SM) + ": "))
+ << i->second << std::endl;
}
for (TextDiagnosticBuffer::const_iterator i = diagsBuffer->warn_begin(),
e = diagsBuffer->warn_end(); i != e; ++i)
{
- ss_build_log << "warning: " << i->first.printToString(sm)
- << ": " << i->second << std::endl;
+ ss_build_log << "warning: "
+ << (SM == nullptr ? "" : (i->first.printToString(*SM) + ": "))
+ << i->second << std::endl;
}
std::string log = ss_build_log.str();
@@ -363,7 +365,8 @@ int pocl_llvm_build_program(cl_program program,
diags)) {
pocl_cache_create_program_cachedir(program, device_i, NULL, 0,
program_bc_path);
- get_build_log(program, device_i, ss_build_log, diagsBuffer, CI.getSourceManager());
+ get_build_log(program, device_i, ss_build_log, diagsBuffer,
+ CI.hasSourceManager() ? &CI.getSourceManager() : nullptr);
return CL_INVALID_BUILD_OPTIONS;
}
@@ -496,7 +499,8 @@ int pocl_llvm_build_program(cl_program program,
if (PreprocessedOut == nullptr) {
pocl_cache_create_program_cachedir(program, device_i, NULL, 0,
program_bc_path);
- get_build_log(program, device_i, ss_build_log, diagsBuffer, CI.getSourceManager());
+ get_build_log(program, device_i, ss_build_log, diagsBuffer,
+ CI.hasSourceManager() ? &CI.getSourceManager() : nullptr);
return CL_BUILD_PROGRAM_FAILURE;
}
@@ -517,7 +521,7 @@ int pocl_llvm_build_program(cl_program program,
clang::EmitLLVMOnlyAction EmitLLVM(&c);
success = CI.ExecuteAction(EmitLLVM);
- get_build_log(program, device_i, ss_build_log, diagsBuffer, CI.getSourceManager());
+ get_build_log(program, device_i, ss_build_log, diagsBuffer, &CI.getSourceManager());
if (!success)
return CL_BUILD_PROGRAM_FAILURE;
