Skip to content

Commit

Permalink
Fix more Wformat warnings related to size_t
Browse files Browse the repository at this point in the history
Printing of a `size_t` requires the `%zu` specifier.

This fixes occurrences where the previous wrong specifier appears to
work in a typical 64-bit build, but causes a Wformat warning in 32-bit
builds.

Signed-off-by: Sven van Haastregt <[email protected]>
  • Loading branch information
svenvh committed Nov 28, 2024
1 parent 0a1456d commit ee8fded
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 105 deletions.
10 changes: 5 additions & 5 deletions test_conformance/buffers/test_sub_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,16 @@ int test_sub_buffers_read_write_core( cl_context context, cl_command_queue queue
size_t sbThatFailed = find_subbuffer_by_index( subBuffers, numSubBuffers, i + j );
if ( sbThatFailed == numSubBuffers )
{
log_error( "ERROR: Validation failure outside of a sub-buffer! (Shouldn't be possible, but it happened at index %ld out of %ld...)\n", i + j, mainSize );
log_error( "ERROR: Validation failure outside of a sub-buffer! (Shouldn't be possible, but it happened at index %zu out of %zu...)\n", i + j, mainSize );
// Since this is a nonsensical, don't bother continuing to check
// (we will, however, print our map of sub-buffers for comparison)
for ( size_t k = 0; k < numSubBuffers; k++ )
{
log_error( "\tBuffer %ld: %ld to %ld (length %ld)\n", k, subBuffers[ k ].mOrigin, subBuffers[ k ].mOrigin + subBuffers[ k ].mSize, subBuffers[ k ].mSize );
log_error( "\tBuffer %zu: %zu to %zu (length %zu)\n", k, subBuffers[ k ].mOrigin, subBuffers[ k ].mOrigin + subBuffers[ k ].mSize, subBuffers[ k ].mSize );
}
return -1;
}
log_error( "ERROR: Validation failure on sub-buffer %ld (start: %ld, length: %ld)\n", sbThatFailed, subBuffers[ sbThatFailed ].mOrigin, subBuffers[ sbThatFailed ].mSize );
log_error( "ERROR: Validation failure on sub-buffer %zu (start: %zu, length: %zu)\n", sbThatFailed, subBuffers[ sbThatFailed ].mOrigin, subBuffers[ sbThatFailed ].mSize );
size_t newPos = subBuffers[ sbThatFailed ].mOrigin + subBuffers[ sbThatFailed ].mSize - 1;
i = newPos & ~65535;
j = newPos - i;
Expand Down Expand Up @@ -589,7 +589,7 @@ int test_sub_buffers_overlapping( cl_device_id deviceID, cl_context context, cl_
}
}

log_info( "\tTesting %d sub-buffers with %lld overlapping Kbytes (%d%%; as many as %ld buffers overlapping at once)\n",
log_info( "\tTesting %d sub-buffers with %lld overlapping Kbytes (%d%%; as many as %zu buffers overlapping at once)\n",
16, ( delta / 1024LL ), (int)( delta * 100LL / (long long)mainSize ), maxOverlap );

// Write some random contents to the main buffer
Expand All @@ -615,7 +615,7 @@ int test_sub_buffers_overlapping( cl_device_id deviceID, cl_context context, cl_

if ( memcmp( tempBuffer, contents + subBuffers[ i ].mOrigin, subBuffers[ i ].mSize ) != 0 )
{
log_error( "ERROR: Validation for sub-buffer %ld failed!\n", i );
log_error( "ERROR: Validation for sub-buffer %zu failed!\n", i );
numErrors++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test_conformance/compiler/test_build_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ int test_load_program_source(cl_device_id deviceID, cl_context context, cl_comma
// Note: according to spec section 5.4.5, the length returned should include the null terminator
if (length != line_length + 1)
{
log_error("ERROR: Length of program (%ld) does not match reference "
"length (%ld)!\n",
log_error("ERROR: Length of program (%zu) does not match reference "
"length (%zu)!\n",
length, line_length + 1);
return -1;
}
Expand Down Expand Up @@ -520,7 +520,7 @@ int test_get_program_build_info(cl_device_id deviceID, cl_context context, cl_co
error = clGetProgramBuildInfo( program, deviceID, CL_PROGRAM_BUILD_LOG, 0, NULL, &length );
test_error( error, "Unable to get program build log length" );

log_info("Build log is %ld long.\n", length);
log_info("Build log is %zu long.\n", length);

buffer = (char*)malloc(length);

Expand Down
16 changes: 8 additions & 8 deletions test_conformance/compiler/test_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,14 +1999,14 @@ static int verifyCopyBuffer(cl_context context, cl_command_queue queue,

if (srcBuffer == NULL)
{
log_error("ERROR: Unable to allocate srcBuffer float array with %lu "
log_error("ERROR: Unable to allocate srcBuffer float array with %zu "
"floats! (in %s:%d)\n",
cnDimension, __FILE__, __LINE__);
return -1;
}
if (dstBuffer == NULL)
{
log_error("ERROR: Unable to allocate dstBuffer float array with %lu "
log_error("ERROR: Unable to allocate dstBuffer float array with %zu "
"floats! (in %s:%d)\n",
cnDimension, __FILE__, __LINE__);
return -1;
Expand Down Expand Up @@ -2067,7 +2067,7 @@ static int verifyCopyBuffer(cl_context context, cl_command_queue queue,
{
if (mismatch < 4)
{
log_info("Offset %08lX: Expected %08X, Got %08X\n", i * 4,
log_info("Offset %08zX: Expected %08X, Got %08X\n", i * 4,
pSrc[i], pDst[i]);
}
else
Expand Down Expand Up @@ -2292,7 +2292,7 @@ int test_execute_after_serialize_reload_object(cl_device_id deviceID,
binary = (unsigned char *)malloc(sizeof(unsigned char) * binarySize);
if (binary == NULL)
{
log_error("ERROR: Unable to allocate binary character array with %lu "
log_error("ERROR: Unable to allocate binary character array with %zu "
"characters! (in %s:%d)\n",
binarySize, __FILE__, __LINE__);
return -1;
Expand Down Expand Up @@ -2404,7 +2404,7 @@ int test_execute_after_serialize_reload_library(cl_device_id deviceID,
binary = (unsigned char *)malloc(sizeof(unsigned char) * binarySize);
if (binary == NULL)
{
log_error("ERROR: Unable to allocate binary character array with %lu "
log_error("ERROR: Unable to allocate binary character array with %zu "
"characters (in %s:%d)!",
binarySize, __FILE__, __LINE__);
return -1;
Expand Down Expand Up @@ -3308,7 +3308,7 @@ int test_program_binary_type(cl_device_id deviceID, cl_context context,
if (binary == NULL)
{
log_error("ERROR: Unable to allocate binary character array with "
"%lu characters! (in %s:%d)\n",
"%zu characters! (in %s:%d)\n",
binarySize, __FILE__, __LINE__);
return -1;
}
Expand Down Expand Up @@ -3389,7 +3389,7 @@ int test_program_binary_type(cl_device_id deviceID, cl_context context,
binary = (unsigned char *)malloc(sizeof(unsigned char) * binarySize);
if (binary == NULL)
{
log_error("ERROR: Unable to allocate binary character array with %lu "
log_error("ERROR: Unable to allocate binary character array with %zu "
"characters! (in %s:%d)\n",
binarySize, __FILE__, __LINE__);
return -1;
Expand Down Expand Up @@ -3487,7 +3487,7 @@ int test_program_binary_type(cl_device_id deviceID, cl_context context,
if (binary == NULL)
{
log_error("ERROR: Unable to allocate binary character array with "
"%lu characters! (in %s:%d)\n",
"%zu characters! (in %s:%d)\n",
binarySize, __FILE__, __LINE__);
return -1;
}
Expand Down
40 changes: 20 additions & 20 deletions test_conformance/contractions/contractions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ static int RunTest( int testNumber )
for( i = 0; i < sizeof(args ) / sizeof( args[0]); i++ )
if( (error = clSetKernelArg(k, i, sizeof( cl_mem ), args + i) ))
{
vlog_error( "Error %d setting kernel arg # %ld\n", error, i );
vlog_error( "Error %d setting kernel arg # %zu\n", error, i );
return error;
}

Expand Down Expand Up @@ -1021,23 +1021,23 @@ static int RunTest( int testNumber )
switch( testNumber )
{
// Zeros for these should be positive
case 0: vlog_error( "%ld) Error for %s %s: %a * %a + %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 0: vlog_error( "%zu) Error for %s %s: %a * %a + %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 1: vlog_error( "%ld) Error for %s %s: %a * %a - %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 1: vlog_error( "%zu) Error for %s %s: %a * %a - %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 2: vlog_error( "%ld) Error for %s %s: %a + %a * %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 2: vlog_error( "%zu) Error for %s %s: %a + %a * %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 3: vlog_error( "%ld) Error for %s %s: %a - %a * %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 3: vlog_error( "%zu) Error for %s %s: %a - %a * %a = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;

// Zeros for these should be negative
case 4: vlog_error( "%ld) Error for %s %s: -(%a * %a + %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
// Zeros for these shouzu be negative
case 4: vlog_error( "%zu) Error for %s %s: -(%a * %a + %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 5: vlog_error( "%ld) Error for %s %s: -(%a * %a - %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 5: vlog_error( "%zu) Error for %s %s: -(%a * %a - %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 6: vlog_error( "%ld) Error for %s %s: -(%a + %a * %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 6: vlog_error( "%zu) Error for %s %s: -(%a + %a * %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
case 7: vlog_error( "%ld) Error for %s %s: -(%a - %a * %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
case 7: vlog_error( "%zu) Error for %s %s: -(%a - %a * %a) = *%a vs. %a\n", i, sizeNames[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); clReleaseKernel(k); return -1;
default:
vlog_error( "error: Unknown test number!\n" );
Expand Down Expand Up @@ -1097,7 +1097,7 @@ static int RunTest_Double( int testNumber )
for( i = 0; i < sizeof(args ) / sizeof( args[0]); i++ )
if( (error = clSetKernelArg(k, i, sizeof( cl_mem ), args + i) ))
{
vlog_error( "Error %d setting kernel arg # %ld\n", error, i );
vlog_error( "Error %d setting kernel arg # %zu\n", error, i );
return error;
}

Expand Down Expand Up @@ -1138,23 +1138,23 @@ static int RunTest_Double( int testNumber )
switch( testNumber )
{
// Zeros for these should be positive
case 0: vlog_error( "%ld) Error for %s %s: %a * %a + %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 0: vlog_error( "%zu) Error for %s %s: %a * %a + %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); return -1;
case 1: vlog_error( "%ld) Error for %s %s: %a * %a - %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 1: vlog_error( "%zu) Error for %s %s: %a * %a - %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); return -1;
case 2: vlog_error( "%ld) Error for %s %s: %a + %a * %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 2: vlog_error( "%zu) Error for %s %s: %a + %a * %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); return -1;
case 3: vlog_error( "%ld) Error for %s %s: %a - %a * %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 3: vlog_error( "%zu) Error for %s %s: %a - %a * %a = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); return -1;

// Zeros for these should be negative
case 4: vlog_error( "%ld) Error for %s %s: -(%a * %a + %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
// Zeros for these shouzu be negative
case 4: vlog_error( "%zu) Error for %s %s: -(%a * %a + %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); return -1;
case 5: vlog_error( "%ld) Error for %s %s: -(%a * %a - %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 5: vlog_error( "%zu) Error for %s %s: -(%a * %a - %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
a[i], b[i], c[i], correct[testNumber][i], test[i] ); return -1;
case 6: vlog_error( "%ld) Error for %s %s: -(%a + %a * %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 6: vlog_error( "%zu) Error for %s %s: -(%a + %a * %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); return -1;
case 7: vlog_error( "%ld) Error for %s %s: -(%a - %a * %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
case 7: vlog_error( "%zu) Error for %s %s: -(%a - %a * %a) = *%a vs. %a\n", i, sizeNames_double[ vectorSize], kernelName[ testNumber ],
c[i], a[i], b[i], correct[testNumber][i], test[i] ); return -1;
default:
vlog_error( "error: Unknown test number!\n" );
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/conversions/test_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ test_status InitCL(cl_device_id device)
vlog("\tCL C Version: %s\n", c);
clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(c), c, NULL);
vlog("\tDriver Version: %s\n", c);
vlog("\tProcessing with %ld devices\n", gComputeDevices);
vlog("\tProcessing with %zu devices\n", gComputeDevices);
vlog("\tDevice Frequency: %d MHz\n", gDeviceFrequency);
vlog("\tSubnormal values supported for floats? %s\n",
no_yes[0 != (CL_FP_DENORM & floatCapabilities)]);
Expand Down
10 changes: 5 additions & 5 deletions test_conformance/device_partition/test_device_partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ int test_device_set(size_t deviceCount, size_t queueCount, cl_device_id *devices
RandomSeed seed( gRandomSeed );

if (queueCount > MAX_QUEUES) {
log_error("Number of queues (%ld) is greater than the number for which the test was written (%d).", queueCount, MAX_QUEUES);
log_error("Number of queues (%zu) is greater than the number for which the test was written (%d).", queueCount, MAX_QUEUES);
return -1;
}

log_info("Testing with %ld queues on %ld devices, %ld kernel executions.\n", queueCount, deviceCount, queueCount*num_elements/TEST_SIZE);
log_info("Testing with %zu queues on %zu devices, %zu kernel executions.\n", queueCount, deviceCount, queueCount*num_elements/TEST_SIZE);

for (i=0; i<deviceCount; i++) {
size_t deviceNameSize;
Expand All @@ -242,7 +242,7 @@ int test_device_set(size_t deviceCount, size_t queueCount, cl_device_id *devices
char *deviceName = (char *)alloca(deviceNameSize * (sizeof(char)));
error = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, deviceNameSize, deviceName, NULL);
test_error(error, "clGetDeviceInfo CL_DEVICE_NAME failed");
log_info("Device %ld is \"%s\".\n", i, deviceName);
log_info("Device %zu is \"%s\".\n", i, deviceName);
}

/* Create a context */
Expand Down Expand Up @@ -332,11 +332,11 @@ int test_device_set(size_t deviceCount, size_t queueCount, cl_device_id *devices
{
if( expectedResults[ i ] != outputData[ i ] )
{
log_error( "ERROR: Sample data did not verify for queue %d on device %ld (sample %d, expected %d, got %d)\n",
log_error( "ERROR: Sample data did not verify for queue %d on device %zu (sample %d, expected %d, got %d)\n",
q, q % deviceCount, (int)i, expectedResults[ i ], outputData[ i ] );
for (size_t j=0; j<deviceCount; j++) {
if (expectedResultsOneDevice[j][i] == outputData[i])
log_info("Sample consistent with only device %ld having modified the data.\n", j);
log_info("Sample consistent with only device %zu having modified the data.\n", j);
}
errorsThisTime++;
break;
Expand Down
Loading

0 comments on commit ee8fded

Please sign in to comment.