[Mesa-dev] [PATCH 4/5] clover: Register an llvm diagnostic handler v3

Francisco Jerez currojerez at riseup.net
Thu Oct 9 11:16:28 PDT 2014


Tom Stellard <thomas.stellard at amd.com> writes:

> This will allow us to handle internal compiler errors.
>
> v2:
>   - Code cleanups.
>
> v3:
>   - More cleanups.
> ---
>  .../state_trackers/clover/llvm/invocation.cpp      | 25 ++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>
> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> index ac52710..6349769 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>
> @@ -575,6 +577,24 @@ namespace {
>        return m;
>     }
>  
> +#if HAVE_LLVM >= 0x0305
> +
> +   void
> +   diagnostic_handler(const llvm::DiagnosticInfo &di, void *data) {
> +      if (di.getSeverity() == llvm::DS_Error) {
> +         std::string message = *(compat::string*)data;
> +         llvm::raw_string_ostream stream(message);
> +         llvm::DiagnosticPrinterRawOStream dp(stream);
> +         di.print(dp);
> +         stream.flush();
> +	 *(compat::string*)data = message;

The indentation looks weird here.  Mixing tabs and spaces?  Other than
that looks good,
Reviewed-by: Francisco Jerez <currojerez at riseup.net>

> +
> +         throw build_error();
> +      }
> +   }
> +
> +#endif
> +
>     void
>     init_targets() {
>        static bool targets_initialized = false;
> @@ -606,6 +626,10 @@ clover::compile_program_llvm(const compat::string &source,
>     llvm::LLVMContext llvm_ctx;
>     unsigned optimization_level;
>  
> +#if HAVE_LLVM >= 0x0305
> +   llvm_ctx.setDiagnosticHandler(diagnostic_handler, &r_log);
> +#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(llvm_ctx, source, "input.cl", triple,
> @@ -637,5 +661,6 @@ clover::compile_program_llvm(const compat::string &source,
>     // LLVM 3.6 and newer, the user takes ownership of the module.
>     delete mod;
>  #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/20141009/a4b3936a/attachment-0001.sig>


More information about the mesa-dev mailing list