Pedantic (#159)
authorBrice Videau <bvideau@anl.gov>
Wed, 15 Dec 2021 05:56:46 +0000 (23:56 -0600)
committerGitHub <noreply@github.com>
Wed, 15 Dec 2021 05:56:46 +0000 (21:56 -0800)
* Replace usage of `d_type` of `struct dirent` by `stat()`.

* Remove unsigned comparison warning.

* Remove warning conversion for function pointers.

* Fix missing initializers.

* Remove unused variable warnings.

* Update loader/linux/icd_linux.c

Co-authored-by: Ronan Keryell <ronan@keryell.fr>
Co-authored-by: Ronan Keryell <ronan@keryell.fr>
15 files changed:
loader/linux/icd_linux.c
test/driver_stub/cl.c
test/driver_stub/cl_ext.c
test/driver_stub/icd.c
test/loader_test/main.c
test/loader_test/param_struct.h
test/loader_test/test_buffer_object.c
test/loader_test/test_cl_runtime.c
test/loader_test/test_clgl.c
test/loader_test/test_create_calls.c
test/loader_test/test_image_objects.c
test/loader_test/test_kernel.c
test/loader_test/test_platforms.c
test/loader_test/test_program_objects.c
test/loader_test/test_sampler_objects.c

index 183261471fafdc9afa655569bcc02837bba6dff9..7fa7bcd476267ff5462eff9f0c6cffb6dcf5f141 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <dirent.h>
 #include <pthread.h>
 
@@ -61,76 +62,74 @@ void khrIcdOsVendorsEnumerate(void)
         // attempt to load all files in the directory
         for (dirEntry = readdir(dir); dirEntry; dirEntry = readdir(dir) )
         {
-            switch(dirEntry->d_type)
+            struct stat statBuff;
+            stat(dirEntry->d_name, &statBuff);
+            if (S_ISREG(statBuff.st_mode) || S_ISLNK(statBuff.st_mode))
             {
-            case DT_UNKNOWN:
-            case DT_REG:
-            case DT_LNK:
+                const char* extension = ".icd";
+                FILE *fin = NULL;
+                char* fileName = NULL;
+                char* buffer = NULL;
+                long bufferSize = 0;
+
+                // make sure the file name ends in .icd
+                if (strlen(extension) > strlen(dirEntry->d_name) )
                 {
-                    const char* extension = ".icd";
-                    FILE *fin = NULL;
-                    char* fileName = NULL;
-                    char* buffer = NULL;
-                    long bufferSize = 0;
-
-                    // make sure the file name ends in .icd
-                    if (strlen(extension) > strlen(dirEntry->d_name) )
-                    {
-                        break;
-                    }
-                    if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) )
-                    {
-                        break;
-                    }
-
-                    // allocate space for the full path of the vendor library name
-                    fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 2);
-                    if (!fileName)
-                    {
-                        KHR_ICD_TRACE("Failed allocate space for ICD file path\n");
-                        break;
-                    }
-                    sprintf(fileName, "%s/%s", vendorPath, dirEntry->d_name);
-
-                    // open the file and read its contents
-                    fin = fopen(fileName, "r");
-                    if (!fin)
-                    {
-                        free(fileName);
-                        break;
-                    }
-                    fseek(fin, 0, SEEK_END);
-                    bufferSize = ftell(fin);
-
-                    buffer = malloc(bufferSize+1);
-                    if (!buffer)
-                    {
-                        free(fileName);
-                        fclose(fin);
-                        break;
-                    }
-                    memset(buffer, 0, bufferSize+1);
-                    fseek(fin, 0, SEEK_SET);
-                    if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) )
-                    {
-                        free(fileName);
-                        free(buffer);
-                        fclose(fin);
-                        break;
-                    }
-                    // ignore a newline at the end of the file
-                    if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0';
-
-                    // load the string read from the file
-                    khrIcdVendorAdd(buffer);
+                    continue;
+                }
+                if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) )
+                {
+                    continue;
+                }
+
+                // allocate space for the full path of the vendor library name
+                fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 2);
+                if (!fileName)
+                {
+                    KHR_ICD_TRACE("Failed allocate space for ICD file path\n");
+                    continue;
+                }
+                sprintf(fileName, "%s/%s", vendorPath, dirEntry->d_name);
 
+                // open the file and read its contents
+                fin = fopen(fileName, "r");
+                if (!fin)
+                {
+                    free(fileName);
+                    continue;
+                }
+                fseek(fin, 0, SEEK_END);
+                bufferSize = ftell(fin);
+
+                buffer = malloc(bufferSize+1);
+                if (!buffer)
+                {
+                    free(fileName);
+                    fclose(fin);
+                    continue;
+                }
+                memset(buffer, 0, bufferSize+1);
+                fseek(fin, 0, SEEK_SET);
+                if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) )
+                {
                     free(fileName);
                     free(buffer);
                     fclose(fin);
+                    continue;
                 }
-                break;
-            default:
-                break;
+                // ignore a newline at the end of the file
+                if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0';
+
+                // load the string read from the file
+                khrIcdVendorAdd(buffer);
+
+                free(fileName);
+                free(buffer);
+                fclose(fin);
+            }
+            else
+            {
+                continue;
             }
         }
 
index 2325cd16f4c159c5dcc9d8205f2674f2ea8e1d92..9b78e5804c501095be5ec24c8812064d7bec407a 100644 (file)
@@ -171,7 +171,7 @@ clGetDeviceIDs(cl_platform_id   platform,
 {
     cl_int ret = CL_SUCCESS;
 
-    if ((num_entries > 1 || num_entries < 0) && devices != NULL) {
+    if ((num_entries > 1) && devices != NULL) {
         ret = CL_INVALID_VALUE;
         goto done;
     }
@@ -902,6 +902,7 @@ clCompileProgram(cl_program            program ,
                  void (CL_CALLBACK *   pfn_notify)(cl_program  program , void *  user_data),
                  void *                user_data) CL_API_SUFFIX__VERSION_1_2
 {
+    (void)input_headers;
     cl_int return_value = CL_OUT_OF_RESOURCES;
     test_icd_stub_log("clCompileProgram(%p, %u, %p, %p, %u, %p, %p, %p)\n",
                       program,
index ece0c591b288a9a662b8778f65c182e1c239e606..4a5c38b396d0375fc6bea0248ebe1bc1cbf03f3f 100644 (file)
@@ -10,7 +10,7 @@ struct driverStubextFunc_st
     void *func;
 };
 
-#define EXT_FUNC(name) { #name, (void*)(name) }
+#define EXT_FUNC(name) { #name, (void*)(intptr_t)(name) }
 
 static struct driverStubextFunc_st clExtensions[] = 
 {
index 75eb245e6c24e4f9eaccc7da3d618aae6629b03d..3f12d7792fff522189cd01a44e763eddaa1d264b 100644 (file)
@@ -29,7 +29,7 @@ clSetCommandQueueProperty(cl_command_queue              /* command_queue */,
 
 #define ICD_DISPATCH_TABLE_ENTRY(fn) \
     assert(dispatchTable->entryCount < 256); \
-    dispatchTable->entries[dispatchTable->entryCount++] = (void*)(fn)
+    dispatchTable->entries[dispatchTable->entryCount++] = (void*)(intptr_t)(fn)
 
 cl_int cliIcdDispatchTableCreate(CLIicdDispatchTable **outDispatchTable)
 {
index 1d783d16bf109e7a78b60f8e6bf2d2e0fae873d5..b8b73040140e0e83a4526a27803af4147d4e78fc 100644 (file)
@@ -18,6 +18,8 @@ extern int test_icd_match();
 
 int main(int argc, char **argv)
 {
+    (void)argc;
+    (void)argv;
     test_icd_initialize_app_log();
     test_icd_initialize_stub_log();
 
index 9677d7de5f8752eecdd8dce33f596d94a484d63f..00d96a97f123611fd87036210b3bde20d055f161 100644 (file)
@@ -802,7 +802,8 @@ struct clEnqueueMigrateMemObjects_st
 struct clEnqueueNDRangeKernel_st 
 {
     cl_command_queue command_queue;
-    cl_kernel kernel; cl_uint work_dim;
+    cl_kernel kernel;
+    cl_uint work_dim;
     const size_t *global_work_offset;
     const size_t *global_work_size;
     const size_t *local_work_size;  
index 1710e8800657171f98782f5453c286067bfcd591..90ff0d102324434ffa94cc6389f3f5f6f0a1cab5 100644 (file)
@@ -336,6 +336,7 @@ int test_clEnqueueMapBuffer(const struct clEnqueueMapBuffer_st *data)
 
 int test_clRetainMemObject(const struct clRetainMemObject_st *data)
 {
+    (void)data;
     test_icd_app_log("clRetainMemObject(%p)\n", buffer);
 
     ret_val=clRetainMemObject(buffer);
index 60bd3eeedaab245eda13c7308abee58e034d5034..380627dd34db95ee33d65cf04382df53ce7e554e 100644 (file)
@@ -14,6 +14,7 @@ const struct clGetCommandQueueInfo_st clGetCommandQueueInfoData[NUM_ITEMS_clGetC
 
 int test_clRetainCommandQueue(const struct clRetainCommandQueue_st *data)
 {
+    (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clRetainCommandQueue(%p)\n", command_queue);
index ee84e3c07f5d497fad6a1f72fad6564b83bc3801..088b7d6a548a44ba49ebe12abb994c163aadf2a6 100644 (file)
@@ -268,7 +268,8 @@ int test_clCreateEventFromGLsyncKHR(const struct clCreateEventFromGLsyncKHR_st*
                      data->sync,
                      data->errcode_ret);
 
-    pfn_clCreateEventFromGLsyncKHR = clGetExtensionFunctionAddress("clCreateEventFromGLsyncKHR");
+    pfn_clCreateEventFromGLsyncKHR = (PFN_clCreateEventFromGLsyncKHR)
+      (intptr_t)clGetExtensionFunctionAddress("clCreateEventFromGLsyncKHR");
     if (!pfn_clCreateEventFromGLsyncKHR) {
         test_icd_app_log("clGetExtensionFunctionAddress failed!\n");
         return 1;
@@ -305,7 +306,8 @@ int test_clGetGLContextInfoKHR(const struct clGetGLContextInfoKHR_st* data)
                      data->param_value,
                      data->param_value_size_ret);
 
-    pfn_clGetGLContextInfoKHR = clGetExtensionFunctionAddress("clGetGLContextInfoKHR");
+    pfn_clGetGLContextInfoKHR = (PFN_clGetGLContextInfoKHR)
+      (intptr_t)clGetExtensionFunctionAddress("clGetGLContextInfoKHR");
     if (!pfn_clGetGLContextInfoKHR) {
         test_icd_app_log("clGetExtensionFunctionAddress failed!\n");
         return 1;
index 9bd351468432a00559bf7c4e60378bb35f9c9d98..4cdcfd7348da26b2e9137b6226076c0cca40d9f3 100644 (file)
@@ -157,6 +157,8 @@ int test_clGetPlatformIDs(const struct clGetPlatformIDs_st* data)
                      data->num_entries,
                      &platforms, 
                      &num_platforms);
+#else
+    (void)data;
 #endif
 
     ret_val = clGetPlatformIDs(0,
@@ -614,6 +616,7 @@ const struct clReleaseSampler_st clReleaseSamplerData[NUM_ITEMS_clReleaseSampler
 
 int test_clReleaseSampler(const struct clReleaseSampler_st *data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;
 
     test_icd_app_log("clReleaseSampler(%p)\n", sampler);
@@ -646,6 +649,7 @@ const struct clReleaseEvent_st clReleaseEventData[NUM_ITEMS_clReleaseEvent] =
 
 int test_clReleaseEvent(const struct clReleaseEvent_st* data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;
 
     test_icd_app_log("clReleaseEvent(%p)\n", event);
@@ -665,6 +669,7 @@ const struct clReleaseKernel_st clReleaseKernelData[NUM_ITEMS_clReleaseKernel] =
 
 int test_clReleaseKernel(const struct clReleaseKernel_st* data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;   
 
     test_icd_app_log("clReleaseKernel(%p)\n", kernel);
@@ -684,6 +689,7 @@ const struct clReleaseProgram_st clReleaseProgramData[NUM_ITEMS_clReleaseProgram
 
 int test_clReleaseProgram(const struct clReleaseProgram_st *data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;
 
     test_icd_app_log("clReleaseProgram(%p)\n", program);
@@ -703,6 +709,7 @@ const struct clReleaseCommandQueue_st clReleaseCommandQueueData[NUM_ITEMS_clRele
 
 int test_clReleaseCommandQueue(const struct clReleaseCommandQueue_st *data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;
 
     test_icd_app_log("clReleaseCommandQueue(%p)\n", command_queue);
@@ -722,6 +729,7 @@ const struct clReleaseContext_st clReleaseContextData[NUM_ITEMS_clReleaseContext
 
 int test_clReleaseContext(const struct clReleaseContext_st* data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES; 
 
     test_icd_app_log("clReleaseContext(%p)\n", context);
@@ -741,6 +749,7 @@ const struct clReleaseDevice_st clReleaseDeviceData[NUM_ITEMS_clReleaseDevice] =
 
 int test_clReleaseDevice(const struct clReleaseDevice_st* data)
 {
+    (void)data;
     int ret_val = CL_OUT_OF_RESOURCES;
 
     test_icd_app_log("clReleaseDevice(%p)\n", devices); 
index 34040ce98a24f7fdb0a960b6e6c340e0428036c7..c6b99e7d2d226cab2cb66e8bc86cb7d952a964be 100644 (file)
@@ -27,7 +27,7 @@ const struct clEnqueueCopyBufferToImage_st clEnqueueCopyBufferToImageData[NUM_IT
 
 const struct clEnqueueMapImage_st clEnqueueMapImageData[NUM_ITEMS_clEnqueueMapImage] =
 {
-    { NULL, NULL, 0, 0x0, NULL, NULL, NULL, NULL,0, NULL, NULL}
+    { NULL, NULL, 0, 0x0, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL}
 };
 
 const struct clEnqueueReadImage_st clEnqueueReadImageData[NUM_ITEMS_clEnqueueReadImage] =
index be116edb312e5376178aad5a350d89957cc7682d..2382eabb438bbec5a886354805a008f1c60b24c1 100644 (file)
@@ -26,6 +26,7 @@ struct clRetainKernel_st clRetainKernelData[NUM_ITEMS_clRetainKernel] =
 
 int test_clRetainKernel(const struct clRetainKernel_st* data)
 {
+    (void)data;
     test_icd_app_log("clRetainKernel(%p)\n", kernel);
                
     ret_val=clRetainKernel(kernel);
@@ -168,7 +169,7 @@ int test_clEnqueueMigrateMemObjects(const struct clEnqueueMigrateMemObjects_st*
 
 struct clEnqueueNDRangeKernel_st clEnqueueNDRangeKernelData[NUM_ITEMS_clEnqueueNDRangeKernel] =
 {
-    {NULL, NULL, 0, NULL, NULL, NULL, 0, NULL}
+    {NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, NULL}
 };
 
 int test_clEnqueueNDRangeKernel(const struct clEnqueueNDRangeKernel_st* data)
@@ -345,6 +346,7 @@ struct clRetainEvent_st clRetainEventData[NUM_ITEMS_clRetainEvent] =
 
 int test_clRetainEvent(const struct clRetainEvent_st* data)
 {
+    (void)data;
     test_icd_app_log("clRetainEvent(%p)\n", event);
 
     ret_val=clRetainEvent(event);
@@ -361,6 +363,7 @@ struct clEnqueueMarker_st clEnqueueMarkerData[NUM_ITEMS_clEnqueueMarker] =
 
 int test_clEnqueueMarker(const struct clEnqueueMarker_st* data)
 {
+    (void)data;
     test_icd_app_log("clEnqueueMarker(%p, %p)\n", command_queue, &event);
 
     ret_val = clEnqueueMarker(command_queue, &event);
@@ -443,6 +446,7 @@ struct clEnqueueBarrier_st clEnqueueBarrierData[NUM_ITEMS_clEnqueueBarrier] =
 
 int test_clEnqueueBarrier(const struct clEnqueueBarrier_st* data)
 {
+    (void)data;
     test_icd_app_log("clEnqueueBarrier(%p)\n", command_queue);
 
     ret_val = clEnqueueBarrier(command_queue);
@@ -483,6 +487,7 @@ struct clFlush_st clFlushData[NUM_ITEMS_clFlush] =
 
 int test_clFlush(const struct clFlush_st* data)
 {
+    (void)data;
     test_icd_app_log("clFlush(%p)\n", command_queue);
 
     ret_val=clFlush(command_queue);
@@ -499,6 +504,7 @@ struct clFinish_st clFinishData[NUM_ITEMS_clFinish] =
 
 int test_clFinish(const struct clFinish_st* data)
 {
+    (void)data;
     test_icd_app_log("clFinish(%p)\n", command_queue);
 
     ret_val=clFinish(command_queue);
index cb2839b0bebc075eac112904cf3c43ab35321993..5700738103bfe9f66c4d48b573cdc30b023f2668 100644 (file)
@@ -49,6 +49,7 @@ struct clRetainDevice_st clRetainDeviceData[NUM_ITEMS_clRetainDevice] =
 
 int test_clRetainContext(const struct clRetainContext_st* data)
 {
+    (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clRetainContext(%p)\n", context);
@@ -176,6 +177,7 @@ int test_clCreateSubDevices(const struct clCreateSubDevices_st* data)
 
 int test_clRetainDevice(const struct clRetainDevice_st* data)
 {
+    (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clRetainDevice(%p)\n", devices);
index 04395d4fac4544afecee17e326b7ac6d1f04d8b6..8e643724228043ea2b13ba887983534a650e797c 100644 (file)
@@ -51,6 +51,7 @@ const struct clGetProgramBuildInfo_st clGetProgramBuildInfoData[NUM_ITEMS_clGetP
 
 int test_clRetainProgram(const struct clRetainProgram_st *data)
 {
+    (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clRetainProgram(%p)\n",
@@ -152,6 +153,7 @@ int test_clLinkProgram(const struct clLinkProgram_st *data)
 
 int test_clUnloadPlatformCompiler(const struct clUnloadPlatformCompiler_st *data)
 {
+    (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clUnloadPlatformCompiler(%p)\n", platform);
index 79944110f96db3951dc696fc6fd0f928a022152d..afc11be8381c2f21e2af0a06e9def35aa134633e 100644 (file)
@@ -17,6 +17,7 @@ const struct clGetSamplerInfo_st clGetSamplerInfoData[NUM_ITEMS_clGetSamplerInfo
 
 int test_clRetainSampler(const struct clRetainSampler_st *data)
 {
+   (void)data;
     cl_int ret_val;
 
     test_icd_app_log("clRetainSampler(%p)\n", sampler);