[Mesa-dev] [PATCH 04/10] clover: Register an llvm diagnostic handler to catch internal compiler errors

Francisco Jerez currojerez at riseup.net
Tue Oct 7 06:31:31 PDT 2014


Francisco Jerez <currojerez at riseup.net> writes:

> Tom Stellard <thomas.stellard at amd.com> writes:
>
>> ---
>>  .../state_trackers/clover/llvm/invocation.cpp      | 30 ++++++++++++++++++++++
>>  1 file changed, 30 insertions(+)
>>
>> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> index 088039a..a1a54e0 100644
>> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> @@ -33,6 +33,8 @@
>>  #include <llvm/Linker.h>
>>  #else
>>  #include <llvm/Linker/Linker.h>
>> +#include <llvm/IR/DiagnosticInfo.h>
>> +#include <llvm/IR/DiagnosticPrinter.h>
>>  #endif
>>  #if HAVE_LLVM < 0x0303
>>  #include <llvm/DerivedTypes.h>
>> @@ -551,6 +553,22 @@ namespace {
>>     }
>>  } // End anonymous namespace
>>  
>> +#if HAVE_LLVM >= 0x0305
>> +
>> +static void diagnostic_handler(const llvm::DiagnosticInfo &di, void *err_string) {

Oh, and can you define this function inside the anonymous namespace and
write the return type in a separate line as we're doing elsewhere?

>> +   if (di.getSeverity() == llvm::DS_Error) {
>> +      std::string message;
>> +      llvm::raw_string_ostream stream(message);
>> +      llvm::DiagnosticPrinterRawOStream dp(stream);
>> +      di.print(dp);
>> +      stream.flush();
>> +      std::string *out_string = (std::string*)err_string;
>> +      *out_string = message;
>> +   }
>> +}
>> +
>> +#endif
>> +
>>  module
>>  clover::compile_program_llvm(const compat::string &source,
>>                               enum pipe_shader_ir ir,
>> @@ -578,6 +596,11 @@ clover::compile_program_llvm(const compat::string &source,
>>     llvm::LLVMContext llvm_ctx;
>>     unsigned optimization_level;
>>  
>> +#if HAVE_LLVM >= 0x0305
>> +   std::string diagnostic_message;
>> +   llvm_ctx.setDiagnosticHandler(diagnostic_handler, &diagnostic_message);
>
> Maybe you could directly pass a pointer to r_log as argument to the
> diagnostic handler so you can avoid the problem below?
>
>> +#endif
>> +
>>     // The input file name must have the .cl extension in order for the
>>     // CompilerInvocation class to recognize it as an OpenCL source file.
>>     llvm::Module *mod = compile(llvm_ctx, source, "input.cl", triple, processor,
>> @@ -607,5 +630,12 @@ clover::compile_program_llvm(const compat::string &source,
>>     // LLVM 3.6 and newer, the user takes ownership of the module.
>>     delete mod;
>>  #endif
>> +#if HAVE_LLVM >= 0x0305
>> +   if (diagnostic_message.size()) {
>> +      r_log = diagnostic_message;
>
> This is probably not executed if the compilation fails throwing an
> exception.
>
> And don't we want to append to the log instead of overwriting its
> previous contents?
>
> Thanks.
>
>> +      throw build_error();
>> +   }
>> +#endif
>> +
>>     return m;
>>  }
>> -- 
>> 1.8.5.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141007/a6752550/attachment.sig>


More information about the mesa-dev mailing list