Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relationals: fix -Wformat warnings #2218

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of .c_str() is the only real change here; remainder are formatting changes.

(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
Loading