Skip to content

Commit 8e6eff8

Browse files
committed
misc: fix warnings with -Wall and -Wextra
Some things being fixed: * signed compare warnings * set but unused variables * bracket warnings
1 parent 03d860e commit 8e6eff8

13 files changed

+92
-41
lines changed

examples/example1/example1.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ main (int argc, char **argv)
4949
cl_float4 *srcA = NULL;
5050
cl_float4 *srcB = NULL;
5151
cl_float *dst = NULL;
52-
int i, err, spirv, poclbin;
52+
int err, spirv, poclbin;
53+
cl_uint i;
5354

5455
cl_context context = NULL;
5556
cl_platform_id platform = NULL;

lib/CL/clEnqueueUnmapMemObject.c

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "pocl_cl.h"
26+
#include "pocl_compiler_macros.h"
2627
#include "pocl_mem_management.h"
2728
#include "pocl_util.h"
2829
#include "utlist.h"
@@ -97,6 +98,7 @@ POname(clEnqueueUnmapMemObject)(cl_command_queue command_queue,
9798

9899
/* Release the "mapping reference" which keeps the buffer alive until the
99100
mapping is on. The command execution should also retain/release. */
101+
POCL_UNUSED
100102
int newrefc;
101103
POCL_RELEASE_OBJECT (memobj, newrefc);
102104

lib/CL/devices/cpu_dbk/pocl_dbk_khr_onnxrt_cpu.c

-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ pocl_destroy_ort_instance (onnxrt_instance_t **onnxrt)
249249
*onnxrt = NULL;
250250
free (ort);
251251

252-
ERROR:
253252
return CL_SUCCESS;
254253
}
255254

lib/CL/devices/printf_base.c

+8-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
#include "printf_base.h"
2626

27-
#include <stddef.h>
28-
#include <stdint.h>
27+
#include <limits.h>
2928
#include <stdio.h>
3029

3130
void
@@ -51,7 +50,7 @@ void
5150
__pocl_printf_ul_base (param_t *p, UINT_T num)
5251
{
5352
char temp[SMALL_BUF_SIZE];
54-
unsigned i = 0, j = 0;
53+
int i = 0, j = 0;
5554
unsigned digit;
5655
unsigned base = p->base;
5756
while (num > 0)
@@ -78,7 +77,7 @@ void
7877
__pocl_printf_ul16 (param_t *p, UINT_T num)
7978
{
8079
char temp[SMALL_BUF_SIZE];
81-
unsigned i = 0, j = 0;
80+
int i = 0, j = 0;
8281
unsigned digit;
8382
const unsigned base = 16;
8483
char digit_offset = (p->flags.uc ? 'A' : 'a');
@@ -428,12 +427,12 @@ unsigned
428427
__pocl_printf_puts_ljust (param_t *p,
429428
const char *string,
430429
unsigned width,
431-
int max_width)
430+
int inp_max_width)
432431
{
433432
char c;
434433
unsigned written = 0;
435-
if (max_width < 0)
436-
max_width = INT32_MAX;
434+
unsigned max_width = inp_max_width >= 0 ? inp_max_width : INT_MAX;
435+
437436
while ((c = *string++))
438437
{
439438
if (written < max_width)
@@ -453,12 +452,11 @@ unsigned
453452
__pocl_printf_puts_rjust (param_t *p,
454453
const char *string,
455454
unsigned width,
456-
int max_width)
455+
int inp_max_width)
457456
{
458457
char c;
459458
unsigned i, strleng = 0, written = 0;
460-
if (max_width < 0)
461-
max_width = INT32_MAX;
459+
unsigned max_width = inp_max_width >= 0 ? inp_max_width : INT_MAX;
462460

463461
const char *tmp = string;
464462
while ((c = *tmp++))

lib/CL/devices/printf_buffer.c

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "printf_buffer.h"
2828
#include "common.h"
29+
#include "pocl_compiler_macros.h"
2930
#include "pocl_debug.h"
3031
#include "printf_base.h"
3132

@@ -559,6 +560,7 @@ __pocl_printf_format_full (param_t *p, char *buffer, uint32_t buffer_size)
559560
{
560561
/* .. else fallthrough to double */
561562
alloca_length = 8;
563+
POCL_FALLTHROUGH;
562564
}
563565
case 8:
564566
__pocl_print_floats_double (p, buffer, vector_length);

lib/CL/devices/remote/remote.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ pocl_remote_build_binary (cl_program program, cl_uint device_i,
10171017

10181018
program->data[real_i] = pd;
10191019
assert ((!spirv_build && program->binary_sizes[real_i] > 0)
1020-
|| spirv_build && program->program_il_size > 0);
1020+
|| (spirv_build && program->program_il_size > 0));
10211021
assert ((!spirv_build && program->binaries[real_i] != NULL)
10221022
|| (spirv_build && program->program_il != NULL));
10231023

@@ -2736,7 +2736,7 @@ pocl_remote_set_kernel_exec_info_ext (cl_device_id dev,
27362736
case CL_KERNEL_EXEC_INFO_SVM_PTRS:
27372737
case CL_KERNEL_EXEC_INFO_USM_PTRS_INTEL:
27382738
{
2739-
for (int i = 0; i < param_value_size / sizeof (void *); ++i)
2739+
for (size_t i = 0; i < param_value_size / sizeof (void *); ++i)
27402740
{
27412741
struct _pocl_ptr_list_node *n
27422742
= malloc (sizeof (struct _pocl_ptr_list_node));

lib/CL/pocl_binary.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ pocl_binary_get_kernels_metadata (cl_program program, unsigned device_i)
874874
BUFFER_READ(len, uint64_t);
875875
assert (len > 0);
876876
buffer += len;
877-
assert (buffer - start <= max_len);
877+
assert ((size_t) (buffer - start) <= max_len);
878878
}
879879

880880
unsigned j;

lib/CL/pocl_builtin_kernels.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,14 @@ pocl_copy_defined_builtin_attributes (BuiltinKernelId kernel_id,
886886
= (cl_dbk_attributes_exp_gemm *)kernel_attributes;
887887
memcpy (attrs, src, sizeof (cl_dbk_attributes_exp_gemm));
888888
err = pocl_copy_tensor_desc_layout (&attrs->a, &src->a);
889-
err = pocl_copy_tensor_desc_layout (&attrs->b, &src->b);
890-
err = pocl_copy_tensor_desc_layout (&attrs->c_in, &src->c_in);
891-
err = pocl_copy_tensor_desc_layout (&attrs->c_out, &src->c_out);
889+
err |= pocl_copy_tensor_desc_layout(&attrs->b, &src->b);
890+
err |= pocl_copy_tensor_desc_layout(&attrs->c_in, &src->c_in);
891+
err |= pocl_copy_tensor_desc_layout(&attrs->c_out, &src->c_out);
892+
if (err != CL_SUCCESS) {
893+
POCL_MSG_WARN("Could not copy POCL_CDBI_DBK_EXP_GEMM attributes (err: %d).\n", err);
894+
free(attrs);
895+
return NULL;
896+
}
892897

893898
return attrs;
894899
}
@@ -903,9 +908,13 @@ pocl_copy_defined_builtin_attributes (BuiltinKernelId kernel_id,
903908
memcpy (attrs, src, sizeof (cl_dbk_attributes_exp_matmul));
904909

905910
err = pocl_copy_tensor_desc_layout (&attrs->a, &src->a);
906-
err = pocl_copy_tensor_desc_layout (&attrs->b, &src->b);
907-
err = pocl_copy_tensor_desc_layout (&attrs->c, &src->c);
908-
911+
err |= pocl_copy_tensor_desc_layout (&attrs->b, &src->b);
912+
err |= pocl_copy_tensor_desc_layout (&attrs->c, &src->c);
913+
if (err != CL_SUCCESS) {
914+
POCL_MSG_WARN("Could not copy POCL_CDBI_DBK_EXP_MATMUL attributes (err: %d).\n", err);
915+
free(attrs);
916+
return NULL;
917+
}
909918
return attrs;
910919
}
911920
case POCL_CDBI_DBK_EXP_JPEG_ENCODE:

lib/CL/pocl_compiler_macros.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* pocl_compiler_macros.h - collection of macros to tell the compiler that a
2+
warning for a piece of code is deliberate.
3+
4+
Copyright (c) 2024 Robin Bijl / Tampere University
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to
8+
deal in the Software without restriction, including without limitation the
9+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
sell copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
IN THE SOFTWARE.
23+
*/
24+
25+
#ifndef POCL_POCL_COMPILER_MACROS_H
26+
#define POCL_POCL_COMPILER_MACROS_H
27+
28+
#if (defined(__GNUC__) && (__GNUC__ > 6)) || (defined(__clang__) && __clang_major__ >= 12)
29+
#define POCL_FALLTHROUGH __attribute__((fallthrough))
30+
#else
31+
#define POCL_FALLTHROUGH
32+
#endif
33+
34+
#if defined(__GNUC__)
35+
#define POCL_UNUSED __attribute__((unused))
36+
#else
37+
#define POCL_UNUSED
38+
#endif
39+
40+
#endif //POCL_POCL_COMPILER_MACROS_H

lib/CL/pocl_tensor_util.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ pocl_tensor_dtype_value_equals (const cl_tensor_datatype DType,
346346
case CL_TENSOR_DTYPE_INT64:
347347
return (Value->l == longConst);
348348
case CL_TENSOR_DTYPE_UINT64:
349-
return (Value->l == ulongConst);
349+
return ((cl_ulong)Value->l == ulongConst);
350350
case CL_TENSOR_DTYPE_INT32:
351-
return ((cl_long)Value->l == longConst);
351+
return (Value->l == longConst);
352352
case CL_TENSOR_DTYPE_UINT32:
353353
return ((cl_ulong)Value->i == ulongConst);
354354
case CL_TENSOR_DTYPE_INT16:

tests/runtime/test_dbk_jpeg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ main (int argc, char const *argv[])
201201
write_event, decode_event };
202202
size_t all_events_size = sizeof (all_events) / sizeof (all_events[0]);
203203
clWaitForEvents (all_events_size, all_events);
204-
for (int i = 0; i < all_events_size; i++)
204+
for (size_t i = 0; i < all_events_size; i++)
205205
clReleaseEvent (all_events[i]);
206206

207207
TEST_ASSERT (jpeg_size_value > 0);
@@ -220,7 +220,7 @@ main (int argc, char const *argv[])
220220
clReleaseKernel (decode_kernel);
221221
clReleaseProgram (program);
222222
clReleaseContext (context);
223-
for (int i = 0; i < num_devices; i++)
223+
for (cl_uint i = 0; i < num_devices; i++)
224224
{
225225
clReleaseDevice (devices[i]);
226226
clReleaseCommandQueue (queues[i]);

tests/runtime/test_event_free.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int main(int argc, char **argv)
144144
*/
145145

146146
if (has_img) {
147-
cl_uint4 color = {0,0,0,0};
147+
cl_uint4 color = {{0,0,0,0}};
148148
const size_t origin[] = {0, 0, 0};
149149
const size_t region[] = {1, 1, 1};
150150

tests/runtime/test_fill-buffer.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,35 @@ main (void)
107107
NULL, NULL));
108108

109109
CHECK_CL_ERROR (clFinish (queue));
110-
for (int i = 0; i < pattern_size * 2; i++)
110+
for (int k = 0; k < pattern_size * 2; k++)
111111
{
112-
if (host_buf1[i] != 1)
112+
if (host_buf1[k] != 1)
113113
{
114-
printf ("Expected value at %d: 1, actual value: %d\n", i,
115-
host_buf1[i]);
114+
printf ("Expected value at %d: 1, actual value: %d\n", k,
115+
host_buf1[k]);
116116
return EXIT_FAILURE;
117117
}
118118
}
119-
for (int i = buf_size - pattern_size; i < buf_size; i++)
119+
for (size_t k = buf_size - pattern_size; k < buf_size; k++)
120120
{
121-
if (host_buf1[i] != 1)
121+
if (host_buf1[k] != 1)
122122
{
123-
printf ("Expected value at %d: 1, actual value: %d\n", i,
124-
host_buf1[i]);
123+
printf ("Expected value at %zu: 1, actual value: %d\n",
124+
k, host_buf1[k]);
125125
return EXIT_FAILURE;
126126
}
127127
}
128-
for (int i = pattern_size * 2; i < buf_size - pattern_size;
129-
i += pattern_size)
128+
for (size_t k = pattern_size * 2; k < buf_size - pattern_size;
129+
k += pattern_size)
130130
{
131-
for (int j = 0; j < pattern_size; j++)
131+
for (int l = 0; l < pattern_size; l++)
132132
{
133-
cl_char expected_value = *((char *)&(pattern) + j);
134-
if (host_buf1[i + j] != expected_value)
133+
cl_char expected_value = *((char *)&(pattern) + l);
134+
if (host_buf1[k + l] != expected_value)
135135
{
136136
printf (
137-
"Expected value at %d: %d, actual value: %d\n",
138-
i + j, expected_value, host_buf1[i + j]);
137+
"Expected value at %zu: %d, actual value: %d\n",
138+
k + l, expected_value, host_buf1[k + l]);
139139
return EXIT_FAILURE;
140140
}
141141
}

0 commit comments

Comments
 (0)