Skip to content

Commit

Permalink
harness: Fix -Wformat warnings (#1527)
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 <sven.vanhaastregt@arm.com>

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
  • Loading branch information
svenvh authored Oct 13, 2022
1 parent 4b39b59 commit f6a963a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions test_common/harness/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//
#include "conversions.h"
#include <cinttypes>
#include <limits.h>
#include <time.h>
#include <assert.h>
Expand Down Expand Up @@ -50,10 +51,10 @@ void print_type_to_string(ExplicitType type, void *data, char *string)
case kInt: sprintf(string, "%d", *((cl_int *)data)); return;
case kUInt:
case kUnsignedInt: sprintf(string, "%u", *((cl_uint *)data)); return;
case kLong: sprintf(string, "%lld", *((cl_long *)data)); return;
case kLong: sprintf(string, "%" PRId64 "", *((cl_long *)data)); return;
case kULong:
case kUnsignedLong:
sprintf(string, "%llu", *((cl_ulong *)data));
sprintf(string, "%" PRIu64 "", *((cl_ulong *)data));
return;
case kFloat: sprintf(string, "%f", *((cl_float *)data)); return;
case kHalf: sprintf(string, "half"); return;
Expand Down
7 changes: 4 additions & 3 deletions test_common/harness/imageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <malloc.h>
#endif
#include <algorithm>
#include <cinttypes>
#include <iterator>
#if !defined(_WIN32)
#include <cmath>
Expand Down Expand Up @@ -421,7 +422,7 @@ void print_first_pixel_difference_error(size_t where, const char *sourcePixel,
(int)thirdDim, (int)imageInfo->rowPitch,
(int)imageInfo->rowPitch
- (int)imageInfo->width * (int)pixel_size);
log_error("Failed at column: %ld ", where);
log_error("Failed at column: %zu ", where);

switch (pixel_size)
{
Expand Down Expand Up @@ -454,7 +455,7 @@ void print_first_pixel_difference_error(size_t where, const char *sourcePixel,
((cl_ushort *)destPixel)[1], ((cl_ushort *)destPixel)[2]);
break;
case 8:
log_error("*0x%16.16llx vs. 0x%16.16llx\n",
log_error("*0x%16.16" PRIx64 " vs. 0x%16.16" PRIx64 "\n",
((cl_ulong *)sourcePixel)[0], ((cl_ulong *)destPixel)[0]);
break;
case 12:
Expand All @@ -473,7 +474,7 @@ void print_first_pixel_difference_error(size_t where, const char *sourcePixel,
((cl_uint *)destPixel)[2], ((cl_uint *)destPixel)[3]);
break;
default:
log_error("Don't know how to print pixel size of %ld\n",
log_error("Don't know how to print pixel size of %zu\n",
pixel_size);
break;
}
Expand Down
11 changes: 6 additions & 5 deletions test_common/harness/propertyHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <assert.h>

#include <algorithm>
#include <cinttypes>
#include <vector>

static bool findProperty(const std::vector<cl_properties>& props,
Expand Down Expand Up @@ -97,16 +98,16 @@ int compareProperties(const std::vector<cl_properties>& queried,

if (!found)
{
log_error("ERROR: expected property 0x%llx not found!\n",
log_error("ERROR: expected property 0x%" PRIx64 " not found!\n",
check_prop);
return TEST_FAIL;
}
else if (check_value != queried_value)
{
log_error(
"ERROR: mis-matched value for property 0x%llx: wanted "
"0x%llx, got 0x%llx\n",
check_prop, check_value, queried_value);
log_error("ERROR: mis-matched value for property 0x%" PRIx64
": wanted "
"0x%" PRIx64 ", got 0x%" PRIx64 "\n",
check_prop, check_value, queried_value);
return TEST_FAIL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test_common/harness/testHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ cl_platform_id getPlatformFromDevice(cl_device_id deviceID)

void PrintArch(void)
{
vlog("sizeof( void*) = %ld\n", sizeof(void *));
vlog("sizeof( void*) = %zu\n", sizeof(void *));
#if defined(__ppc__)
vlog("ARCH:\tppc\n");
#elif defined(__ppc64__)
Expand Down

0 comments on commit f6a963a

Please sign in to comment.