Skip to content

Commit

Permalink
Fix Build Warnings for AArch64 (KhronosGroup#2242)
Browse files Browse the repository at this point in the history
This commit links to issue (KhronosGroup#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 <[email protected]>
  • Loading branch information
Antonios-C authored Feb 5, 2025
1 parent bcfa1f7 commit 2031e21
Show file tree
Hide file tree
Showing 30 changed files with 104 additions and 43 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang"
add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive
add_cxx_flag_if_supported(-Wno-unknown-pragmas) # Issue #785
add_cxx_flag_if_supported(-Wno-error=asm-operand-widths) # Issue #784
add_cxx_flag_if_supported(-Wno-strict-aliasing) # Issue 2234

# -msse -mfpmath=sse to force gcc to use sse for float math,
# avoiding excess precision problems that cause tests like int2float
Expand Down
16 changes: 16 additions & 0 deletions test_common/harness/imageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,12 @@ int debug_find_vector_in_image(void *imagePtr, image_descriptor *imageInfo,
(imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1;
depth = (imageInfo->depth >> lod) ? (imageInfo->depth >> lod) : 1;
break;
default:
log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type);
width = 0;
depth = 0;
height = 0;
break;
}

row_pitch = width * get_pixel_size(imageInfo->format);
Expand Down Expand Up @@ -3661,6 +3667,11 @@ void copy_image_data(image_descriptor *srcImageInfo,
? (srcImageInfo->height >> src_lod)
: 1;
break;
default:
log_error("ERROR: Invalid srcImageInfo->type = %d\n",
srcImageInfo->type);
src_lod = 0;
break;
}
src_mip_level_offset = compute_mip_level_offset(srcImageInfo, src_lod);
src_row_pitch_lod =
Expand Down Expand Up @@ -3707,6 +3718,11 @@ void copy_image_data(image_descriptor *srcImageInfo,
? (dstImageInfo->height >> dst_lod)
: 1;
break;
default:
log_error("ERROR: Invalid dstImageInfo->num_mip_levels = %d\n",
dstImageInfo->num_mip_levels);
dst_lod = 0;
break;
}
dst_mip_level_offset = compute_mip_level_offset(dstImageInfo, dst_lod);
dst_row_pitch_lod =
Expand Down
2 changes: 1 addition & 1 deletion test_common/harness/typeWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ cl_int clProtectedImage::Create(cl_context context,
const cl_image_format *fmt, size_t width,
size_t height, size_t depth, size_t arraySize)
{
cl_int error;
cl_int error = 0;
#if defined(__APPLE__)
int protect_pages = 1;
cl_device_id devices[16];
Expand Down
4 changes: 2 additions & 2 deletions test_conformance/SVM/test_enqueue_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/api/test_wg_suggested_local_work_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions test_conformance/basic/test_imagereadwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
6 changes: 6 additions & 0 deletions test_conformance/basic/test_imagereadwrite3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
4 changes: 2 additions & 2 deletions test_conformance/buffers/test_buffer_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions test_conformance/contractions/contractions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions test_conformance/conversions/basic_test_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1473,17 +1475,21 @@ 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]);
snprintf(testName, 256, "test_%s_%s", convertString, inName);
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]);
Expand Down
7 changes: 4 additions & 3 deletions test_conformance/conversions/test_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand All @@ -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';
}
}
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/events/test_event_dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions test_conformance/half/Test_vStoreHalf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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 };
Expand Down
5 changes: 3 additions & 2 deletions test_conformance/half/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/images/clCopyImage/test_copy_1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/images/clCopyImage/test_copy_1D_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/images/clCopyImage/test_copy_2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/images/clCopyImage/test_copy_2D_3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions test_conformance/images/clCopyImage/test_loops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions test_conformance/images/clFillImage/test_fill_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
12 changes: 12 additions & 0 deletions test_conformance/images/clGetInfo/test_2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 2031e21

Please sign in to comment.