[Mesa-dev] [PATCH 2/5] clover: Fix not setting build log if the build succeeds v2

Francisco Jerez currojerez at riseup.net
Thu Jun 26 07:08:31 PDT 2014


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

> From: Matt Arsenault <arsenm2 at gmail.com>
>
> If there were only warnings, they would not be added to the log.
> Also fixes valgrind use after free errors.
>

This last comment is somewhat misleading now, as this doesn't fix any
valgrind errors anymore.  Without it, this patch is:

Reviewed-by: Francisco Jerez <currojerez at riseup.net>

> v2:
>   - Use compat::string.
> ---
>  src/gallium/state_trackers/clover/core/compiler.hpp   |  3 ++-
>  src/gallium/state_trackers/clover/core/error.hpp      |  4 ++--
>  src/gallium/state_trackers/clover/core/program.cpp    | 11 +++++++----
>  src/gallium/state_trackers/clover/llvm/invocation.cpp | 16 ++++++++++------
>  src/gallium/state_trackers/clover/util/compat.hpp     |  3 +++
>  5 files changed, 24 insertions(+), 13 deletions(-)
>
> diff --git a/src/gallium/state_trackers/clover/core/compiler.hpp b/src/gallium/state_trackers/clover/core/compiler.hpp
> index 49cd022..6ef84d1 100644
> --- a/src/gallium/state_trackers/clover/core/compiler.hpp
> +++ b/src/gallium/state_trackers/clover/core/compiler.hpp
> @@ -32,7 +32,8 @@ namespace clover {
>     module compile_program_llvm(const compat::string &source,
>                                 pipe_shader_ir ir,
>                                 const compat::string &target,
> -                               const compat::string &opts);
> +                               const compat::string &opts,
> +                               compat::string &r_log);
>  
>     module compile_program_tgsi(const compat::string &source);
>  }
> diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp
> index 28459f3..cecbe9b 100644
> --- a/src/gallium/state_trackers/clover/core/error.hpp
> +++ b/src/gallium/state_trackers/clover/core/error.hpp
> @@ -66,8 +66,8 @@ namespace clover {
>  
>     class build_error : public error {
>     public:
> -      build_error(const compat::string &log) :
> -         error(CL_BUILD_PROGRAM_FAILURE, log) {
> +      build_error(const compat::string &what = "") :
> +         error(CL_BUILD_PROGRAM_FAILURE, what) {
>        }
>     };
>  
> diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
> index 3aaa652..e09c3aa 100644
> --- a/src/gallium/state_trackers/clover/core/program.cpp
> +++ b/src/gallium/state_trackers/clover/core/program.cpp
> @@ -52,15 +52,18 @@ program::build(const ref_vector<device> &devs, const char *opts) {
>  
>           _opts.insert({ &dev, opts });
>  
> +         compat::string log;
> +
>           try {
>              auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
>                             compile_program_tgsi(_source) :
>                             compile_program_llvm(_source, dev.ir_format(),
> -                                                dev.ir_target(), build_opts(dev)));
> +                                                dev.ir_target(), build_opts(dev),
> +                                                log));
>              _binaries.insert({ &dev, module });
> -
> -         } catch (build_error &e) {
> -            _logs.insert({ &dev, e.what() });
> +            _logs.insert({ &dev, std::string(log.c_str()) });
> +         } catch (const build_error &) {
> +            _logs.insert({ &dev, std::string(log.c_str()) });
>              throw;
>           }
>        }
> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> index c3daa81..5d2efc4 100644
> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
> @@ -120,7 +120,7 @@ namespace {
>     compile(llvm::LLVMContext &llvm_ctx, const std::string &source,
>             const std::string &name, const std::string &triple,
>             const std::string &processor, const std::string &opts,
> -           clang::LangAS::Map& address_spaces) {
> +           clang::LangAS::Map& address_spaces, compat::string &r_log) {
>  
>        clang::CompilerInstance c;
>        clang::EmitLLVMOnlyAction act(&llvm_ctx);
> @@ -224,11 +224,14 @@ namespace {
>        c.getCodeGenOpts().LinkBitcodeFile = libclc_path;
>  
>        // Compile the code
> -      if (!c.ExecuteAction(act))
> -         throw build_error(log);
> +      bool ExecSuccess = c.ExecuteAction(act);
> +      r_log = log;
> +
> +      if (!ExecSuccess)
> +         throw build_error();
>  
>        // Get address spaces map to be able to find kernel argument address space
> -      memcpy(address_spaces, c.getTarget().getAddressSpaceMap(), 
> +      memcpy(address_spaces, c.getTarget().getAddressSpaceMap(),
>                                                          sizeof(address_spaces));
>  
>        return act.takeModule();
> @@ -391,7 +394,8 @@ module
>  clover::compile_program_llvm(const compat::string &source,
>                               enum pipe_shader_ir ir,
>                               const compat::string &target,
> -                             const compat::string &opts) {
> +                             const compat::string &opts,
> +                             compat::string &r_log) {
>  
>     std::vector<llvm::Function *> kernels;
>     size_t processor_str_len = std::string(target.begin()).find_first_of("-");
> @@ -405,7 +409,7 @@ clover::compile_program_llvm(const compat::string &source,
>     // 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,
> -                               opts, address_spaces);
> +                               opts, address_spaces, r_log);
>  
>     find_kernels(mod, kernels);
>  
> diff --git a/src/gallium/state_trackers/clover/util/compat.hpp b/src/gallium/state_trackers/clover/util/compat.hpp
> index 28601e8..50e1c7d 100644
> --- a/src/gallium/state_trackers/clover/util/compat.hpp
> +++ b/src/gallium/state_trackers/clover/util/compat.hpp
> @@ -265,6 +265,9 @@ namespace clover {
>  
>        class string : public vector<char> {
>        public:
> +         string() : vector() {
> +         }
> +
>           string(const char *p) : vector(p, std::strlen(p)) {
>           }
>  
> -- 
> 1.8.1.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140626/33bf3f78/attachment.sig>


More information about the mesa-dev mailing list