[Piglit] [PATCH] cl-api-compile-program: Initialize variable.

Jan Vesely jan.vesely at rutgers.edu
Wed Dec 3 14:49:54 PST 2014


On Tue, 2014-12-02 at 20:17 -0800, Vinson Lee wrote:
> This patch silences Clang sometimes-uninitialized warnings.
> 
> compile-program.c:312:6: warning: variable 'kernel' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>                 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
>                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> compile-program.c:332:18: note: uninitialized use occurs here
>         clReleaseKernel(kernel);
>                         ^~~~~~
> compile-program.c:312:3: note: remove the 'if' if its condition is always false
>                 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> compile-program.c:302:5: warning: variable 'kernel' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
>         if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
>            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> compile-program.c:332:18: note: uninitialized use occurs here
>         clReleaseKernel(kernel);
>                         ^~~~~~
> compile-program.c:302:2: note: remove the 'if' if its condition is always false
>         if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> compile-program.c:114:18: note: initialize the variable 'kernel' to silence this warning
>         cl_kernel kernel;
>                         ^
>                          = NULL
> 
> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
> ---
>  tests/cl/api/compile-program.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/cl/api/compile-program.c b/tests/cl/api/compile-program.c
> index d280f98..821033d 100644
> --- a/tests/cl/api/compile-program.c
> +++ b/tests/cl/api/compile-program.c
> @@ -111,7 +111,7 @@ piglit_cl_test(const int argc,
>  	cl_program header_invalid;
>  	cl_program program;
>  	cl_program temp_program;
> -	cl_kernel kernel;
> +	cl_kernel kernel = NULL;
>  
>  	/*** Normal usage ***/
>  

I think it might be nicer to just move the
"clReleaseKernel(kernel);" line
inside the else branch that calls clCreateKernel

Either way
Reviewed-by: Jan Vesely <jan.vesely at rutgers.edu>

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20141203/0d513c99/attachment-0001.sig>


More information about the Piglit mailing list