Skip to content

Commit 2031e21

Browse files
authored
Fix Build Warnings for AArch64 (KhronosGroup#2242)
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 <a-christidis@ti.com>
1 parent bcfa1f7 commit 2031e21

30 files changed

Lines changed: 104 additions & 43 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang"
107107
add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive
108108
add_cxx_flag_if_supported(-Wno-unknown-pragmas) # Issue #785
109109
add_cxx_flag_if_supported(-Wno-error=asm-operand-widths) # Issue #784
110+
add_cxx_flag_if_supported(-Wno-strict-aliasing) # Issue 2234
110111

111112
# -msse -mfpmath=sse to force gcc to use sse for float math,
112113
# avoiding excess precision problems that cause tests like int2float

test_common/harness/imageHelpers.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,12 @@ int debug_find_vector_in_image(void *imagePtr, image_descriptor *imageInfo,
24152415
(imageInfo->height >> lod) ? (imageInfo->height >> lod) : 1;
24162416
depth = (imageInfo->depth >> lod) ? (imageInfo->depth >> lod) : 1;
24172417
break;
2418+
default:
2419+
log_error("ERROR: Invalid imageInfo->type = %d\n", imageInfo->type);
2420+
width = 0;
2421+
depth = 0;
2422+
height = 0;
2423+
break;
24182424
}
24192425

24202426
row_pitch = width * get_pixel_size(imageInfo->format);
@@ -3661,6 +3667,11 @@ void copy_image_data(image_descriptor *srcImageInfo,
36613667
? (srcImageInfo->height >> src_lod)
36623668
: 1;
36633669
break;
3670+
default:
3671+
log_error("ERROR: Invalid srcImageInfo->type = %d\n",
3672+
srcImageInfo->type);
3673+
src_lod = 0;
3674+
break;
36643675
}
36653676
src_mip_level_offset = compute_mip_level_offset(srcImageInfo, src_lod);
36663677
src_row_pitch_lod =
@@ -3707,6 +3718,11 @@ void copy_image_data(image_descriptor *srcImageInfo,
37073718
? (dstImageInfo->height >> dst_lod)
37083719
: 1;
37093720
break;
3721+
default:
3722+
log_error("ERROR: Invalid dstImageInfo->num_mip_levels = %d\n",
3723+
dstImageInfo->num_mip_levels);
3724+
dst_lod = 0;
3725+
break;
37103726
}
37113727
dst_mip_level_offset = compute_mip_level_offset(dstImageInfo, dst_lod);
37123728
dst_row_pitch_lod =

test_common/harness/typeWrappers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ cl_int clProtectedImage::Create(cl_context context,
348348
const cl_image_format *fmt, size_t width,
349349
size_t height, size_t depth, size_t arraySize)
350350
{
351-
cl_int error;
351+
cl_int error = 0;
352352
#if defined(__APPLE__)
353353
int protect_pages = 1;
354354
cl_device_id devices[16];

test_conformance/SVM/test_enqueue_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ REGISTER_TEST(svm_enqueue_api)
160160
error = clSetUserEventStatus(userEvent, CL_COMPLETE);
161161
test_error(error, "clSetUserEventStatus failed");
162162

163-
cl_uchar *src_ptr;
164-
cl_uchar *dst_ptr;
163+
cl_uchar *src_ptr = nullptr;
164+
cl_uchar *dst_ptr = nullptr;
165165
if (test_case.srcAlloc == host)
166166
{
167167
src_ptr = srcHostData.data();

test_conformance/api/test_wg_suggested_local_work_size.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int do_test_work_group_suggested_local_size(
208208
bool (*skip_cond)(size_t), size_t start, size_t end, size_t incr,
209209
cl_ulong max_local_mem_size, size_t global_work_offset[], num_dims dim)
210210
{
211-
int err;
211+
int err = 0;
212212
size_t test_values[] = { 1, 1, 1 };
213213
std::string kernel_names[6] = {
214214
"test_wg_scan_local_work_group_size",

test_conformance/basic/test_imagereadwrite.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ test_imagereadwrite(cl_device_id device, cl_context context, cl_command_queue qu
314314
}
315315
outp = (void *)rgbafp_outptr;
316316
break;
317+
default:
318+
log_error("ERROR Invalid j = %d\n", j);
319+
elem_size = 0;
320+
p = nullptr;
321+
outp = nullptr;
322+
break;
317323
}
318324

319325
const char* update_packed_pitch_name = "";

test_conformance/basic/test_imagereadwrite3d.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ test_imagereadwrite3d(cl_device_id device, cl_context context, cl_command_queue
320320
}
321321
outp = (void *)rgbafp_outptr;
322322
break;
323+
default:
324+
log_error("ERROR Invalid j = %d\n", j);
325+
elem_size = 0;
326+
p = nullptr;
327+
outp = nullptr;
328+
break;
323329
}
324330

325331
const char* update_packed_pitch_name = "";

test_conformance/buffers/test_buffer_write.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,8 @@ int test_buffer_write_struct( cl_device_id deviceID, cl_context context, cl_comm
852852
buffers[0] =
853853
clCreateBuffer(context, flag_set[src_flag_id],
854854
ptrSizes[i] * num_elements, NULL, &err);
855-
if ( err ){
856-
align_free( outptr[i] );
855+
if (err)
856+
{
857857
print_error(err, " clCreateBuffer failed\n" );
858858
free_mtdata(d);
859859
return -1;

test_conformance/contractions/contractions.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,18 @@ static int ParseArgs( int argc, const char **argv )
365365
int length_of_seed = 0;
366366

367367
{ // Extract the app name
368-
strncpy( appName, argv[0], MAXPATHLEN );
368+
strncpy(appName, argv[0], MAXPATHLEN - 1);
369+
appName[MAXPATHLEN - 1] = '\0';
369370

370371
#if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__))
371372
char baseName[MAXPATHLEN];
372373
char *base = NULL;
373-
strncpy( baseName, argv[0], MAXPATHLEN );
374+
strncpy(baseName, argv[0], MAXPATHLEN - 1);
375+
baseName[MAXPATHLEN - 1] = '\0';
374376
base = basename( baseName );
375377
if( NULL != base )
376378
{
377-
strncpy( appName, base, sizeof( appName ) );
379+
strncpy(appName, base, sizeof(appName) - 1);
378380
appName[ sizeof( appName ) -1 ] = '\0';
379381
}
380382
#elif defined (_WIN32)
@@ -385,7 +387,7 @@ static int ParseArgs( int argc, const char **argv )
385387
fname, _MAX_FNAME, ext, _MAX_EXT );
386388
if (err == 0) { // no error
387389
strcat (fname, ext); //just cat them, size of frame can keep both
388-
strncpy (appName, fname, sizeof(appName));
390+
strncpy(appName, fname, sizeof(appName) - 1);
389391
appName[ sizeof( appName ) -1 ] = '\0';
390392
}
391393
#endif

test_conformance/conversions/basic_test_conversions.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,9 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat,
14481448
char inName[32];
14491449
char outName[32];
14501450
strncpy(inName, gTypeNames[inType], sizeof(inName));
1451+
inName[sizeof(inName) - 1] = '\0';
14511452
strncpy(outName, gTypeNames[outType], sizeof(outName));
1453+
outName[sizeof(outName) - 1] = '\0';
14521454
sprintf(testName, "test_implicit_%s_%s", outName, inName);
14531455

14541456
source << "__kernel void " << testName << "( __global " << inName
@@ -1473,17 +1475,21 @@ cl_program MakeProgram(Type outType, Type inType, SaturationMode sat,
14731475
switch (vectorSizetmp)
14741476
{
14751477
case 1:
1476-
strncpy(inName, gTypeNames[inType], sizeof(inName));
1477-
strncpy(outName, gTypeNames[outType], sizeof(outName));
1478+
strncpy(inName, gTypeNames[inType], sizeof(inName) - 1);
1479+
inName[sizeof(inName) - 1] = '\0';
1480+
strncpy(outName, gTypeNames[outType], sizeof(outName) - 1);
1481+
outName[sizeof(outName) - 1] = '\0';
14781482
snprintf(convertString, sizeof(convertString), "convert_%s%s%s",
14791483
outName, gSaturationNames[sat],
14801484
gRoundingModeNames[round]);
14811485
snprintf(testName, 256, "test_%s_%s", convertString, inName);
14821486
vlog("Building %s( %s ) test\n", convertString, inName);
14831487
break;
14841488
case 3:
1485-
strncpy(inName, gTypeNames[inType], sizeof(inName));
1486-
strncpy(outName, gTypeNames[outType], sizeof(outName));
1489+
strncpy(inName, gTypeNames[inType], sizeof(inName) - 1);
1490+
inName[sizeof(inName) - 1] = '\0';
1491+
strncpy(outName, gTypeNames[outType], sizeof(outName) - 1);
1492+
outName[sizeof(outName) - 1] = '\0';
14871493
snprintf(convertString, sizeof(convertString),
14881494
"convert_%s3%s%s", outName, gSaturationNames[sat],
14891495
gRoundingModeNames[round]);

0 commit comments

Comments
 (0)