Skip to content

Commit

Permalink
integer_ops: fix -Wformat warnings (#1860)
Browse files Browse the repository at this point in the history
The main sources of warnings were:

 * Printing of a `size_t` which requires the `%zu` specifier.

 * Printing of `cl_long`/`cl_ulong` which is now done using the
   `PRI*64` macros to ensure portability across 32 and 64-bit builds.

Signed-off-by: Sven van Haastregt <[email protected]>
  • Loading branch information
svenvh authored Dec 20, 2023
1 parent 47d5d37 commit b36b2d5
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 126 deletions.
58 changes: 50 additions & 8 deletions test_conformance/integer_ops/test_abs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
#include "harness/compat.h"

#include <cinttypes>

#include <stdio.h>
#include <string.h>
#include <limits.h>
Expand All @@ -35,7 +37,12 @@ static int verify_abs_char( const void *p, const void *q, size_t n, const char *
if( inA[i] < 0 )
r = -inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (char%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (char%s) 0x%2.2x) = *0x%2.2x vs "
"0x%2.2x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -52,7 +59,12 @@ static int verify_abs_short( const void *p, const void *q, size_t n, const char
if( inA[i] < 0 )
r = -inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs "
"0x%4.4x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -68,7 +80,12 @@ static int verify_abs_int( const void *p, const void *q, size_t n, const char *s
if( inA[i] < 0 )
r = -inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs "
"0x%8.8x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -84,7 +101,12 @@ static int verify_abs_long( const void *p, const void *q, size_t n, const char *
if( inA[i] < 0 )
r = -inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (long%s) 0x%16.16" PRIx64
") = *0x%16.16" PRIx64 " vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -100,7 +122,12 @@ static int verify_abs_uchar( const void *p, const void *q, size_t n, const char
{
cl_uchar r = inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (uchar%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (uchar%s) 0x%2.2x) = *0x%2.2x vs "
"0x%2.2x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -115,7 +142,12 @@ static int verify_abs_ushort( const void *p, const void *q, size_t n, const char
{
cl_ushort r = inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs "
"0x%4.4x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -129,7 +161,12 @@ static int verify_abs_uint( const void *p, const void *q, size_t n, const char *
{
cl_uint r = inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs "
"0x%8.8x\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -143,7 +180,12 @@ static int verify_abs_ulong( const void *p, const void *q, size_t n, const char
{
cl_ulong r = inA[i];
if( r != outptr[i] )
{ log_info( "%ld) Failure for abs( (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i],r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for abs( (long%s) 0x%16.16" PRIx64
") = *0x%16.16" PRIx64 " vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand Down
57 changes: 49 additions & 8 deletions test_conformance/integer_ops/test_absdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <sys/types.h>
#include <sys/stat.h>

#include <cinttypes>

#include "procs.h"

template <class Integer>
Expand All @@ -43,7 +45,12 @@ static int verify_absdiff_char( const void *p, const void *q, const void *r, siz
{
cl_uchar r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (char%s) 0x%2.2x, (char%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (char%s) 0x%2.2x, (char%s) "
"0x%2.2x) = *0x%2.2x vs 0x%2.2x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -58,7 +65,12 @@ static int verify_absdiff_uchar( const void *p, const void *q, const void *r, si
{
cl_uchar r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (uchar%s) 0x%2.2x, (uchar%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (uchar%s) 0x%2.2x, (uchar%s) "
"0x%2.2x) = *0x%2.2x vs 0x%2.2x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -73,7 +85,12 @@ static int verify_absdiff_short( const void *p, const void *q, const void *r, si
{
cl_ushort r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (short%s) 0x%4.4x, (short%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (short%s) 0x%4.4x, (short%s) "
"0x%4.4x) = *0x%4.4x vs 0x%4.4x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -88,7 +105,12 @@ static int verify_absdiff_ushort( const void *p, const void *q, const void *r, s
{
cl_ushort r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (ushort%s) 0x%4.4x, (ushort%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (ushort%s) 0x%4.4x, (ushort%s) "
"0x%4.4x) = *0x%4.4x vs 0x%4.4x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -104,7 +126,9 @@ static int verify_absdiff_int( const void *p, const void *q, const void *r, size
cl_uint r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{
log_info( "%ld) Failure for absdiff( (int%s) 0x%8.8x, (int%s) 0x%8.8x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] );
log_info("%zu) Failure for absdiff( (int%s) 0x%8.8x, (int%s) "
"0x%8.8x) = *0x%8.8x vs 0x%8.8x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
Expand All @@ -121,7 +145,12 @@ static int verify_absdiff_uint( const void *p, const void *q, const void *r, siz
{
cl_uint r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (uint%s) 0x%8.8x, (uint%s) 0x%8.8x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (uint%s) 0x%8.8x, (uint%s) "
"0x%8.8x) = *0x%8.8x vs 0x%8.8x\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -136,7 +165,13 @@ static int verify_absdiff_long( const void *p, const void *q, const void *r, siz
{
cl_ulong r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (long%s) 0x%16.16llx, (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (long%s) 0x%16.16" PRIx64
", (long%s) 0x%16.16" PRIx64 ") = *0x%16.16" PRIx64
" vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -151,7 +186,13 @@ static int verify_absdiff_ulong( const void *p, const void *q, const void *r, si
{
cl_ulong r = abs_diff(inA[i], inB[i]);
if( r != outptr[i] )
{ log_info( "%ld) Failure for absdiff( (ulong%s) 0x%16.16llx, (ulong%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%zu) Failure for absdiff( (ulong%s) 0x%16.16" PRIx64
", (ulong%s) 0x%16.16" PRIx64 ") = *0x%16.16" PRIx64
" vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand Down
17 changes: 15 additions & 2 deletions test_conformance/integer_ops/test_add_sat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sys/stat.h>

#include <algorithm>
#include <cinttypes>

#include "procs.h"

Expand Down Expand Up @@ -140,7 +141,13 @@ static int verify_addsat_long( const cl_long *inA, const cl_long *inB, const cl_
r = CL_LONG_MIN;
}
if( r != outptr[i] )
{ log_info( "%d) Failure for add_sat( (long%s) 0x%16.16llx, (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%d) Failure for add_sat( (long%s) 0x%16.16" PRIx64
", (long%s) 0x%16.16" PRIx64 ") = *0x%16.16" PRIx64
" vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand All @@ -154,7 +161,13 @@ static int verify_addsat_ulong( const cl_ulong *inA, const cl_ulong *inB, const
if( r < inA[i] )
r = CL_ULONG_MAX;
if( r != outptr[i] )
{ log_info( "%d) Failure for add_sat( (ulong%s) 0x%16.16llx, (ulong%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i], sizeName, inB[i], r, outptr[i] ); return -1; }
{
log_info("%d) Failure for add_sat( (ulong%s) 0x%16.16" PRIx64
", (ulong%s) 0x%16.16" PRIx64 ") = *0x%16.16" PRIx64
" vs 0x%16.16" PRIx64 "\n",
i, sizeName, inA[i], sizeName, inB[i], r, outptr[i]);
return -1;
}
}
return 0;
}
Expand Down
48 changes: 33 additions & 15 deletions test_conformance/integer_ops/test_integers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "harness/conversions.h"

#include <algorithm>
#include <cinttypes>

#define TEST_SIZE 512

Expand Down Expand Up @@ -198,13 +199,23 @@ int test_single_param_integer_kernel(cl_command_queue queue, cl_context context,

case 8:
if( useOpKernel )
log_error( "ERROR: Data sample %d:%d does not validate! Expected (0x%16.16llx), got (0x%16.16llx), sources (0x%16.16llx, 0x%16.16llx)\n",
(int)i, (int)j, ((cl_ulong*)&expected)[0], *( (cl_ulong *)p ),
*( (cl_ulong *)in ), *( (cl_ulong *)in2 ) );
log_error("ERROR: Data sample %d:%d does not "
"validate! Expected (0x%16.16" PRIx64
"), got (0x%16.16" PRIx64
"), sources (0x%16.16" PRIx64
", 0x%16.16" PRIx64 ")\n",
(int)i, (int)j,
((cl_ulong *)&expected)[0],
*((cl_ulong *)p), *((cl_ulong *)in),
*((cl_ulong *)in2));
else
log_error( "ERROR: Data sample %d:%d does not validate! Expected (0x%16.16llx), got (0x%16.16llx), sources (0x%16.16llx)\n",
(int)i, (int)j, ((cl_ulong*)&expected)[0], *( (cl_ulong *)p ),
*( (cl_ulong *)in ) );
log_error("ERROR: Data sample %d:%d does not "
"validate! Expected (0x%16.16" PRIx64
"), got (0x%16.16" PRIx64
"), sources (0x%16.16" PRIx64 ")\n",
(int)i, (int)j,
((cl_ulong *)&expected)[0],
*((cl_ulong *)p), *((cl_ulong *)in));
break;
}
return -1;
Expand Down Expand Up @@ -750,10 +761,14 @@ int test_two_param_integer_kernel(cl_command_queue queue, cl_context context, co
break;

case 8:
log_error( "ERROR: Data sample %d:%d does not validate! Expected (0x%16.16llx), got (0x%16.16llx), sources (0x%16.16llx, 0x%16.16llx)\n",
(int)i, (int)j, ((cl_ulong*)&expected)[ 0 ], *( (cl_ulong *)out ),
*( (cl_ulong *)inA ),
*( (cl_ulong *)inB ) );
log_error("ERROR: Data sample %d:%d does not validate! "
"Expected (0x%16.16" PRIx64
"), got (0x%16.16" PRIx64
"), sources (0x%16.16" PRIx64
", 0x%16.16" PRIx64 ")\n",
(int)i, (int)j, ((cl_ulong *)&expected)[0],
*((cl_ulong *)out), *((cl_ulong *)inA),
*((cl_ulong *)inB));
break;
}
return -1;
Expand Down Expand Up @@ -1417,11 +1432,14 @@ int test_three_param_integer_kernel(cl_command_queue queue, cl_context context,
break;

case 8:
log_error( "ERROR: Data sample %d:%d does not validate! Expected (0x%16.16llx), got (0x%16.16llx), sources (0x%16.16llx, 0x%16.16llx, 0x%16.16llx)\n",
(int)i, (int)j, ((cl_ulong*)&expected)[ 0 ], *( (cl_ulong *)out ),
*( (cl_ulong *)inA ),
*( (cl_ulong *)inB ),
*( (cl_ulong *)inC ) );
log_error("ERROR: Data sample %d:%d does not validate! "
"Expected (0x%16.16" PRIx64
"), got (0x%16.16" PRIx64
"), sources (0x%16.16" PRIx64
", 0x%16.16" PRIx64 ", 0x%16.16" PRIx64 ")\n",
(int)i, (int)j, ((cl_ulong *)&expected)[0],
*((cl_ulong *)out), *((cl_ulong *)inA),
*((cl_ulong *)inB), *((cl_ulong *)inC));
break;
}
return -1;
Expand Down
12 changes: 8 additions & 4 deletions test_conformance/integer_ops/test_intmad24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ verify_int_mad24(int *inptrA, int *inptrB, int *inptrC, int *outptr, size_t n, s
r = a * b + inptrC[i];
if (r != outptr[i])
{
log_error( "Failed at %ld) 0x%8.8x * 0x%8.8x + 0x%8.8x = *0x%8.8x vs 0x%8.8x\n", i, a, b, inptrC[i], r, outptr[i] );
return -1;
log_error("Failed at %zu) 0x%8.8x * 0x%8.8x + 0x%8.8x = *0x%8.8x "
"vs 0x%8.8x\n",
i, a, b, inptrC[i], r, outptr[i]);
return -1;
}
}

Expand All @@ -160,8 +162,10 @@ verify_uint_mad24(cl_uint *inptrA, cl_uint *inptrB, cl_uint *inptrC, cl_uint *ou
r = a * b + inptrC[i];
if (r != outptr[i])
{
log_error( "Failed at %ld) 0x%8.8x * 0x%8.8x + 0x%8.8x = *0x%8.8x vs 0x%8.8x\n", i, a, b, inptrC[i], r, outptr[i] );
return -1;
log_error("Failed at %zu) 0x%8.8x * 0x%8.8x + 0x%8.8x = *0x%8.8x "
"vs 0x%8.8x\n",
i, a, b, inptrC[i], r, outptr[i]);
return -1;
}
}

Expand Down
6 changes: 4 additions & 2 deletions test_conformance/integer_ops/test_intmul24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ verify_uint_mul24(cl_uint *inptrA, cl_uint *inptrB, cl_uint *outptr, size_t n, s
r = (inptrA[i] & 0xffffffU) * (inptrB[i] & 0xffffffU);
if (r != outptr[i])
{
log_error( "failed at %ld: 0x%8.8x * 0x%8.8x = *0x%8.8x vs 0x%8.8x\n", i, inptrA[i], inptrB[i], r, outptr[i] );
return -1;
log_error(
"failed at %zu: 0x%8.8x * 0x%8.8x = *0x%8.8x vs 0x%8.8x\n", i,
inptrA[i], inptrB[i], r, outptr[i]);
return -1;
}
}

Expand Down
Loading

0 comments on commit b36b2d5

Please sign in to comment.