Fix Build Warnings for AArch64 (#2242)

This commit links to issue (#2234).

When cross-compiling for AArch64, using gcc 13.3, you encounter three
warnings types that turn into errors:

- maybe-uninitialized
- stringop-truncation
- strict-aliasing

This commit fixes all the warnings found, in regards to the first two
rules. To resolve the warnigns due to strict-aliasing, I am editing the
CMake build system.

Signed-off-by: Antonios Christidis <a-christidis@ti.com>
This commit is contained in:
Antonios Christidis
2025-02-05 06:58:17 -06:00
committed by GitHub
parent bcfa1f7c26
commit 2031e21a58
30 changed files with 104 additions and 43 deletions

View File

@@ -160,8 +160,8 @@ REGISTER_TEST(svm_enqueue_api)
error = clSetUserEventStatus(userEvent, CL_COMPLETE);
test_error(error, "clSetUserEventStatus failed");
cl_uchar *src_ptr;
cl_uchar *dst_ptr;
cl_uchar *src_ptr = nullptr;
cl_uchar *dst_ptr = nullptr;
if (test_case.srcAlloc == host)
{
src_ptr = srcHostData.data();

View File

@@ -208,7 +208,7 @@ int do_test_work_group_suggested_local_size(
bool (*skip_cond)(size_t), size_t start, size_t end, size_t incr,
cl_ulong max_local_mem_size, size_t global_work_offset[], num_dims dim)
{
int err;
int err = 0;
size_t test_values[] = { 1, 1, 1 };
std::string kernel_names[6] = {
"test_wg_scan_local_work_group_size",

View File

@@ -314,6 +314,12 @@ test_imagereadwrite(cl_device_id device, cl_context context, cl_command_queue qu
}
outp = (void *)rgbafp_outptr;
break;
default:
log_error("ERROR Invalid j = %d\n", j);
elem_size = 0;
p = nullptr;
outp = nullptr;
break;
}
const char* update_packed_pitch_name = "";

View File

@@ -320,6 +320,12 @@ test_imagereadwrite3d(cl_device_id device, cl_context context, cl_command_queue
}
outp = (void *)rgbafp_outptr;
break;
default:
log_error("ERROR Invalid j = %d\n", j);
elem_size = 0;
p = nullptr;
outp = nullptr;
break;
}
const char* update_packed_pitch_name = "";

View File

@@ -852,8 +852,8 @@ int test_buffer_write_struct( cl_device_id deviceID, cl_context context, cl_comm
buffers[0] =
clCreateBuffer(context, flag_set[src_flag_id],
ptrSizes[i] * num_elements, NULL, &err);
if ( err ){
align_free( outptr[i] );
if (err)
{
print_error(err, " clCreateBuffer failed\n" );
free_mtdata(d);
return -1;

View File

@@ -365,16 +365,18 @@ static int ParseArgs( int argc, const char **argv )
int length_of_seed = 0;
{ // Extract the app name
strncpy( appName, argv[0], MAXPATHLEN );
strncpy(appName, argv[0], MAXPATHLEN - 1);
appName[MAXPATHLEN - 1] = '\0';
#if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__))
char baseName[MAXPATHLEN];
char *base = NULL;
strncpy( baseName, argv[0], MAXPATHLEN );
strncpy(baseName, argv[0], MAXPATHLEN - 1);
baseName[MAXPATHLEN - 1] = '\0';
base = basename( baseName );
if( NULL != base )
{
strncpy( appName, base, sizeof( appName ) );
strncpy(appName, base, sizeof(appName) - 1);
appName[ sizeof( appName ) -1 ] = '\0';
}
#elif defined (_WIN32)
@@ -385,7 +387,7 @@ static int ParseArgs( int argc, const char **argv )
fname, _MAX_FNAME, ext, _MAX_EXT );
if (err == 0) { // no error
strcat (fname, ext); //just cat them, size of frame can keep both
strncpy (appName, fname, sizeof(appName));
strncpy(appName, fname, sizeof(appName) - 1);
appName[ sizeof( appName ) -1 ] = '\0';
}
#endif

View File

@@ -1448,7 +1448,9 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat,
char inName[32];
char outName[32];
strncpy(inName, gTypeNames[inType], sizeof(inName));
inName[sizeof(inName) - 1] = '\0';
strncpy(outName, gTypeNames[outType], sizeof(outName));
outName[sizeof(outName) - 1] = '\0';
sprintf(testName, "test_implicit_%s_%s", outName, inName);
source << "__kernel void " << testName << "( __global " << inName
@@ -1473,8 +1475,10 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat,
switch (vectorSizetmp)
{
case 1:
strncpy(inName, gTypeNames[inType], sizeof(inName));
strncpy(outName, gTypeNames[outType], sizeof(outName));
strncpy(inName, gTypeNames[inType], sizeof(inName) - 1);
inName[sizeof(inName) - 1] = '\0';
strncpy(outName, gTypeNames[outType], sizeof(outName) - 1);
outName[sizeof(outName) - 1] = '\0';
snprintf(convertString, sizeof(convertString), "convert_%s%s%s",
outName, gSaturationNames[sat],
gRoundingModeNames[round]);
@@ -1482,8 +1486,10 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat,
vlog("Building %s( %s ) test\n", convertString, inName);
break;
case 3:
strncpy(inName, gTypeNames[inType], sizeof(inName));
strncpy(outName, gTypeNames[outType], sizeof(outName));
strncpy(inName, gTypeNames[inType], sizeof(inName) - 1);
inName[sizeof(inName) - 1] = '\0';
strncpy(outName, gTypeNames[outType], sizeof(outName) - 1);
outName[sizeof(outName) - 1] = '\0';
snprintf(convertString, sizeof(convertString),
"convert_%s3%s%s", outName, gSaturationNames[sat],
gRoundingModeNames[round]);

View File

@@ -182,11 +182,12 @@ static int ParseArgs(int argc, const char **argv)
#if (defined(__APPLE__) || defined(__linux__) || defined(__MINGW32__))
{ // Extract the app name
char baseName[MAXPATHLEN];
strncpy(baseName, argv[0], MAXPATHLEN);
strncpy(baseName, argv[0], MAXPATHLEN - 1);
baseName[sizeof(baseName) - 1] = '\0';
char *base = basename(baseName);
if (NULL != base)
{
strncpy(appName, base, sizeof(appName));
strncpy(appName, base, sizeof(appName) - 1);
appName[sizeof(appName) - 1] = '\0';
}
}
@@ -200,7 +201,7 @@ static int ParseArgs(int argc, const char **argv)
if (err == 0)
{ // no error
strcat(fname, ext); // just cat them, size of frame can keep both
strncpy(appName, fname, sizeof(appName));
strncpy(appName, fname, sizeof(appName) - 1);
appName[sizeof(appName) - 1] = '\0';
}
}

View File

@@ -89,7 +89,7 @@ int test_event_enqueue_wait_for_events_run_test(
// If we are to use two devices, then get them and create a context with
// both.
cl_device_id *two_device_ids;
cl_device_id *two_device_ids = nullptr;
if (two_devices)
{
two_device_ids = (cl_device_id *)malloc(sizeof(cl_device_id) * 2);

View File

@@ -341,8 +341,8 @@ int Test_vStoreHalf_private(cl_device_id device, f2h referenceFunc,
int vectorSize, error;
cl_program programs[kVectorSizeCount + kStrangeVectorSizeCount][3];
cl_kernel kernels[kVectorSizeCount + kStrangeVectorSizeCount][3];
cl_program resetProgram;
cl_kernel resetKernel;
cl_program resetProgram = nullptr;
cl_kernel resetKernel = nullptr;
uint64_t time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 };
uint64_t min_time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 };
@@ -1225,8 +1225,8 @@ int Test_vStoreaHalf_private(cl_device_id device, f2h referenceFunc,
int vectorSize, error;
cl_program programs[kVectorSizeCount + kStrangeVectorSizeCount][3];
cl_kernel kernels[kVectorSizeCount + kStrangeVectorSizeCount][3];
cl_program resetProgram;
cl_kernel resetKernel;
cl_program resetProgram = nullptr;
cl_kernel resetKernel = nullptr;
uint64_t time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 };
uint64_t min_time[kVectorSizeCount + kStrangeVectorSizeCount] = { 0 };

View File

@@ -144,11 +144,12 @@ static int ParseArgs( int argc, const char **argv )
#if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__))
{ // Extract the app name
char baseName[ MAXPATHLEN ];
strncpy( baseName, argv[0], MAXPATHLEN );
strncpy(baseName, argv[0], MAXPATHLEN - 1);
baseName[MAXPATHLEN - 1] = '\0';
char *base = basename( baseName );
if( NULL != base )
{
strncpy( appName, base, sizeof( appName ) );
strncpy(appName, base, sizeof(appName) - 1);
appName[ sizeof( appName ) -1 ] = '\0';
}
}

View File

@@ -25,7 +25,7 @@ int test_copy_image_size_1D( cl_context context, cl_command_queue queue, image_d
size_t src_lod = 0, src_width_lod = imageInfo->width, src_row_pitch_lod;
size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod;
size_t width_lod = imageInfo->width;
size_t max_mip_level;
size_t max_mip_level = 0;
if( gTestMipmaps )
{

View File

@@ -25,7 +25,7 @@ int test_copy_image_size_1D_array( cl_context context, cl_command_queue queue, i
size_t src_lod = 0, src_width_lod = imageInfo->width, src_row_pitch_lod;
size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod;
size_t width_lod = imageInfo->width;
size_t max_mip_level;
size_t max_mip_level = 0;
if( gTestMipmaps )
{

View File

@@ -27,7 +27,7 @@ int test_copy_image_size_2D( cl_context context, cl_command_queue queue, image_d
size_t dst_lod = 0, dst_width_lod = imageInfo->width, dst_row_pitch_lod;
size_t dst_height_lod = imageInfo->height;
size_t width_lod = imageInfo->width, height_lod = imageInfo->height;
size_t max_mip_level;
size_t max_mip_level = 0;
if( gTestMipmaps )
{

View File

@@ -72,7 +72,7 @@ int test_copy_image_size_2D_2D_array( cl_context context, cl_command_queue queue
size_t threeImage_lod = 0, threeImage_width_lod = threeImage->width, threeImage_row_pitch_lod, threeImage_slice_pitch_lod;
size_t threeImage_height_lod = threeImage->height;
size_t width_lod, height_lod;
size_t twoImage_max_mip_level,threeImage_max_mip_level;
size_t twoImage_max_mip_level = 0, threeImage_max_mip_level = 0;
if( gTestMipmaps )
{

View File

@@ -68,7 +68,7 @@ int test_copy_image_size_2D_3D( cl_context context, cl_command_queue queue, imag
size_t threeImage_lod = 0, threeImage_width_lod = threeImage->width, threeImage_row_pitch_lod, threeImage_slice_pitch_lod;
size_t threeImage_height_lod = threeImage->height, depth_lod = threeImage->depth;
size_t width_lod, height_lod;
size_t twoImage_max_mip_level,threeImage_max_mip_level;
size_t twoImage_max_mip_level = 0, threeImage_max_mip_level = 0;
if( gTestMipmaps )
{

View File

@@ -39,8 +39,8 @@ extern int test_copy_image_set_1D_buffer_1D(cl_device_id device,
int test_image_type( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod, cl_mem_flags flags )
{
const char *name;
cl_mem_object_type imageType;
const char *name = nullptr;
cl_mem_object_type imageType = 0;
if ( gTestMipmaps )
{

View File

@@ -277,6 +277,11 @@ cl_mem create_image( cl_context context, cl_command_queue queue, BufferOwningPtr
depth = imageInfo->depth;
imageSize = imageInfo->slicePitch * imageInfo->depth;
break;
default:
log_error("ERROR Invalid imageInfo->type = %d\n", imageInfo->type);
height = 0;
depth = 0;
break;
}
size_t origin[ 3 ] = { 0, 0, 0 };

View File

@@ -181,6 +181,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE3D:
required_height = imageInfo->height;
break;
default:
log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type);
required_height = 0;
break;
}
size_t outHeight;
@@ -204,6 +208,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE3D:
required_depth = imageInfo->depth;
break;
default:
log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type);
required_depth = 0;
break;
}
size_t outDepth;
@@ -227,6 +235,10 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
required_array_size = imageInfo->arraySize;
break;
default:
log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type);
required_array_size = 0;
break;
}
size_t outArraySize;

View File

@@ -69,7 +69,7 @@ static inline size_t get_format_size(cl_context context,
}
cl_int error = 0;
cl_mem buffer;
cl_mem buffer = nullptr;
if (imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER)
{
buffer = clCreateBuffer(context, flags,

View File

@@ -769,7 +769,7 @@ int image_from_buffer_fill_positive(cl_device_id device, cl_context context,
err = clFinish(queue);
test_error(err, "Error clFinish");
cl_mem image1d_buffer;
cl_mem image1d_buffer = nullptr;
if (imageType == CL_MEM_OBJECT_IMAGE1D_BUFFER)
{
image1d_buffer = clCreateBuffer(context, flag, buffer_size,

View File

@@ -1191,7 +1191,7 @@ int test_read_image_2D( cl_context context, cl_command_queue queue, cl_kernel ke
{
int error;
static int initHalf = 0;
cl_mem imageBuffer;
cl_mem imageBuffer = nullptr;
cl_mem_flags image_read_write_flags = CL_MEM_READ_ONLY;
size_t threads[2];

View File

@@ -223,7 +223,7 @@ int test_write_image( cl_device_id device, cl_context context, cl_command_queue
clProtectedImage protImage;
clMemWrapper unprotImage;
cl_mem image;
cl_mem imageBuffer;
cl_mem imageBuffer = nullptr;
if( gMemFlagsToUse == CL_MEM_USE_HOST_PTR )
{
@@ -910,7 +910,7 @@ int test_write_image_formats(cl_device_id device, cl_context context,
gTestCount++;
print_write_header( &imageFormat, false );
int retCode;
int retCode = 0;
switch (imageType)
{
case CL_MEM_OBJECT_IMAGE1D:

View File

@@ -97,7 +97,7 @@ int test_unary_op( cl_command_queue queue, cl_context context, OpKonstants which
get_explicit_type_size(vecType) * vecSize * TEST_SIZE, inData, &error);
test_error( error, "Creating input data array failed" );
cl_uint bits;
cl_uint bits = 0;
for( i = 0; i < TEST_SIZE; i++ )
{
size_t which = i & 7;

View File

@@ -1151,7 +1151,8 @@ int main(int argc, const char* argv[])
char* pcTempFname = get_temp_filename();
if (pcTempFname != nullptr)
{
strncpy(gFileName, pcTempFname, sizeof(gFileName));
strncpy(gFileName, pcTempFname, sizeof(gFileName) - 1);
gFileName[sizeof(gFileName) - 1] = '\0';
}
free(pcTempFname);

View File

@@ -261,14 +261,18 @@ static cl_program makeSelectProgram(cl_kernel *kernel_ptr,
switch( vec_len )
{
case 1:
strncpy(stypename, type_name[srctype], sizeof(stypename));
strncpy(ctypename, type_name[cmptype], sizeof(ctypename));
strncpy(stypename, type_name[srctype], sizeof(stypename) - 1);
stypename[sizeof(stypename) - 1] = '\0';
strncpy(ctypename, type_name[cmptype], sizeof(ctypename) - 1);
ctypename[sizeof(ctypename) - 1] = '\0';
snprintf(testname, sizeof(testname), "select_%s_%s", stypename, ctypename );
log_info("Building %s(%s, %s, %s)\n", testname, stypename, stypename, ctypename);
break;
case 3:
strncpy(stypename, type_name[srctype], sizeof(stypename));
strncpy(ctypename, type_name[cmptype], sizeof(ctypename));
strncpy(stypename, type_name[srctype], sizeof(stypename) - 1);
stypename[sizeof(stypename) - 1] = '\0';
strncpy(ctypename, type_name[cmptype], sizeof(ctypename) - 1);
ctypename[sizeof(ctypename) - 1] = '\0';
snprintf(testname, sizeof(testname), "select_%s3_%s3", stypename, ctypename );
log_info("Building %s(%s3, %s3, %s3)\n", testname, stypename, stypename, ctypename);
break;

View File

@@ -1611,7 +1611,7 @@ template <typename Ty, typename Fns, size_t TSIZE = 0> struct subgroup_test
test_params.subgroup_size = subgroup_size;
Fns::gen(idata.data(), mapin.data(), sgmap.data(), test_params);
test_status status;
test_status status = TEST_FAIL;
if (test_params.divergence_mask_arg != -1)
{