Skip to content

Commit

Permalink
relationals: fix -Wformat warnings (#2218)
Browse files Browse the repository at this point in the history
Avoid a
```
  ‘%zu’ directive writing between 1 and 20 bytes into a region of size 16
```
warning by using `std::string` for `generate_shuffle_mask`.

As this fixes the last remaining Wformat warning in the relationals
suite, drop the local `-Wno-format` compiler option.

Signed-off-by: Sven van Haastregt <[email protected]>
  • Loading branch information
svenvh authored Jan 14, 2025
1 parent bc5b021 commit a2d6cad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
2 changes: 0 additions & 2 deletions test_conformance/relationals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ set(${MODULE_NAME}_SOURCES
test_shuffles.cpp
)

set_gnulike_module_compile_flags("-Wno-format")

include(../CMakeCommon.txt)

61 changes: 36 additions & 25 deletions test_conformance/relationals/test_shuffles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,24 @@ void print_hex_mem_dump(const unsigned char *inDataPtr,
log_info("%s\n", error.str().c_str());
}

void generate_shuffle_mask( char *outMaskString, size_t maskSize, const ShuffleOrder *order )
std::string generate_shuffle_mask(size_t maskSize, const ShuffleOrder *order)
{
outMaskString[ 0 ] = 0;
std::ostringstream outMaskString;
if( order != NULL )
{
for( size_t jj = 0; jj < maskSize; jj++ )
{
char thisMask[ 16 ];
sprintf( thisMask, "%s%d", ( jj == 0 ) ? "" : ", ", (*order)[ jj ] );
strcat( outMaskString, thisMask );
outMaskString << (jj == 0 ? "" : ", ") << +((*order)[jj]);
}
}
else
{
for( size_t jj = 0; jj < maskSize; jj++ )
{
char thisMask[ 16 ];
sprintf(thisMask, "%s%zu", (jj == 0) ? "" : ", ", jj);
strcat( outMaskString, thisMask );
outMaskString << (jj == 0 ? "" : ", ") << jj;
}
}
return outMaskString.str();
}

static int create_shuffle_kernel( cl_context context, cl_program *outProgram, cl_kernel *outKernel,
Expand Down Expand Up @@ -520,9 +517,9 @@ static int create_shuffle_kernel( cl_context context, cl_program *outProgram, cl
maskType = kULong;
}

char maskString[ 1024 ] = "";
size_t maskSize = outVecSize;// ( shuffleMode == kBuiltInDualInputFnMode ) ? ( outVecSize << 1 ) : outVecSize;
generate_shuffle_mask( maskString, maskSize, ( outOrders != NULL ) ? &outOrders[ i ] : NULL );
std::string maskString = generate_shuffle_mask(
maskSize, (outOrders != NULL) ? &outOrders[i] : NULL);

// Set up a quick prefix, so mask gets unsigned type regardless of the input/output type
char maskPrefix[ 2 ] = "u";
Expand All @@ -532,13 +529,21 @@ static int create_shuffle_kernel( cl_context context, cl_program *outProgram, cl
char progLine2[ 10240 ];
if( shuffleMode == kBuiltInDualInputFnMode )
{
sprintf( progLine2, shuffleBuiltInDualPattern, get_explicit_type_name( vecType ), inSizeName,
( inVecSize == 3 ) ? "vload3( %ld, (__global %s *)source )" : "source[ %ld ]",
get_explicit_type_name( vecType ), inSizeName,
( inVecSize == 3 ) ? "vload3( %ld, (__global %s *)secondSource )" : "secondSource[ %ld ]",
maskPrefix, get_explicit_type_name( maskType ), outSizeName, maskPrefix, get_explicit_type_name( maskType ), outSizeName,
maskString,
( outVecSize == 3 ) ? "vstore3( tmp, %ld, (__global %s *)dest )" : "dest[ %ld ] = tmp" );
sprintf(
progLine2, shuffleBuiltInDualPattern,
get_explicit_type_name(vecType), inSizeName,
(inVecSize == 3) ? "vload3( %ld, (__global %s *)source )"
: "source[ %ld ]",
get_explicit_type_name(vecType), inSizeName,
(inVecSize == 3)
? "vload3( %ld, (__global %s *)secondSource )"
: "secondSource[ %ld ]",
maskPrefix, get_explicit_type_name(maskType), outSizeName,
maskPrefix, get_explicit_type_name(maskType), outSizeName,
maskString.c_str(),
(outVecSize == 3)
? "vstore3( tmp, %ld, (__global %s *)dest )"
: "dest[ %ld ] = tmp");

if( outVecSize == 3 )
{
Expand All @@ -557,11 +562,17 @@ static int create_shuffle_kernel( cl_context context, cl_program *outProgram, cl
}
else
{
sprintf( progLine2, shuffleBuiltInPattern, get_explicit_type_name( vecType ), inSizeName,
( inVecSize == 3 ) ? "vload3( %ld, (__global %s *)source )" : "source[ %ld ]",
maskPrefix, get_explicit_type_name( maskType ), outSizeName, maskPrefix, get_explicit_type_name( maskType ), outSizeName,
maskString,
( outVecSize == 3 ) ? "vstore3( tmp, %ld, (__global %s *)dest )" : "dest[ %ld ] = tmp" );
sprintf(
progLine2, shuffleBuiltInPattern,
get_explicit_type_name(vecType), inSizeName,
(inVecSize == 3) ? "vload3( %ld, (__global %s *)source )"
: "source[ %ld ]",
maskPrefix, get_explicit_type_name(maskType), outSizeName,
maskPrefix, get_explicit_type_name(maskType), outSizeName,
maskString.c_str(),
(outVecSize == 3)
? "vstore3( tmp, %ld, (__global %s *)dest )"
: "dest[ %ld ] = tmp");

if( outVecSize == 3 )
{
Expand Down Expand Up @@ -705,9 +716,9 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,
if( ( shuffleMode == kBuiltInFnMode ) || ( shuffleMode == kBuiltInDualInputFnMode ) )
{
// Mask would've been different for every shuffle done, so we have to regen it to print it
char maskString[ 1024 ];
generate_shuffle_mask( maskString, outVecSize, ( outOrderIdx != NULL ) ? &outOrderIdx[ i ] : NULL );
log_error( " Mask: %s\n", maskString );
std::string maskString = generate_shuffle_mask(
outVecSize, (outOrderIdx != NULL) ? &outOrderIdx[i] : NULL);
log_error(" Mask: %s\n", maskString.c_str());
}

ret++;
Expand Down

0 comments on commit a2d6cad

Please sign in to comment.