Open
Description
Hi @ThomasMertes, building the Seed7 C code leads to the following C compiler warnings on my macOS system built with clang:
- Missing cases in dcllib.c:
dcllib.c:516:15: warning: enumeration value 'PARAM_UNDEFINED' not handled in switch [-Wswitch]
516 | switch (object_type->in_param_type) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
dcllib.c:516:15: note: add missing switch cases
516 | switch (object_type->in_param_type) {
| ^
517 | case PARAM_VALUE:
dcllib.c:562:19: warning: enumeration value 'PARAM_UNDEFINED' not handled in switch [-Wswitch]
562 | switch (object_type->in_param_type) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
dcllib.c:562:19: note: add missing switch cases
562 | switch (object_type->in_param_type) {
| ^
563 | case PARAM_VALUE:
2 warnings generated.
- variable set but not used warning in strlib.c:
- The local variable definition should be placed inside the only block that uses it.
- Both implementations of
SHRINK_STRI(v1,v2,l1,l2)
macro ignore the l1 argument. It should then be removed from the macro. That will probably mean updating other code, but it will make the intention of the macro clearer. The same issue affects the GROW_STRI(v1,v2,l1,l2) macro implementations. COUNT_SHRINK_STRI(len1,len2)
also discard both arguments. (and also theCOUNT_GROW_STRI()
andCOUNT_GROW2_STRI()
I might be missing something but it looks like some refactoring of the pre-processor macros might be needed along with the insertion of pre-processor conditional compilation control of insertion/activation of test/debug code to ensure that code builds with no warnings while allowing activation of debug/tracing code at the build level instead of activation of commented out code in some C files.
strlib.c:1597:17: warning: variable 'striSize' set but not used [-Wunused-but-set-variable]
1597 | memSizeType striSize;
| ^
1 warning generated.
- comparison is always false in prg_comp.c
Perhaps one way to solve this would be to use the pre-processor and including the test for architecture where the comparison can be true?
prg_comp.c:443:47: warning: result of comparison of constant 9223372036854775807 with expression of type 'const unsigned int' is always false [-Wtautological-constant-out-of-range-compare]
443 | } else if (unlikely(aProgram->error_count > INTTYPE_MAX)) {
| ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
./version.h:101:39: note: expanded from macro 'unlikely'
101 | #define unlikely(x) __builtin_expect((x),0)
| ^
1 warning generated.
clang -O2 -g -ffunction-sections -fdata-sections -I"/opt/X11/include" -flto -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith -ftrapv -c -o analyze.o analyze.c
analyze.c:641:11: warning: variable 'isOpen' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
641 | if ((absolutePath = getAbsolutePath(sourceFilePath)) == NULL) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
analyze.c:665:11: note: uninitialized use occurs here
665 | if (isOpen) {
| ^~~~~~
analyze.c:641:7: note: remove the 'if' if its condition is always false
641 | if ((absolutePath = getAbsolutePath(sourceFilePath)) == NULL) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
642 | *err_info = MEMORY_ERROR;
| ~~~~~~~~~~~~~~~~~~~~~~~~~
643 | } else {
| ~~~~~~
analyze.c:605:20: note: initialize the variable 'isOpen' to silence this warning
605 | boolType isOpen;
| ^
| = 0
1 warning generated.
- unused function in inf_beep:
These 3 functions are static and never called in the file. Perhaps they should be included only when needed by a pre-processor statement? Or removed?
con_inf.c:312:13: warning: unused function 'inf_beep' [-Wunused-function]
312 | static void inf_beep (void)
| ^~~~~~~~
con_inf.c:349:13: warning: unused function 'inf_standardcolour' [-Wunused-function]
349 | static void inf_standardcolour (void)
| ^~~~~~~~~~~~~~~~~~
con_inf.c:367:12: warning: unused function 'inf_setfont' [-Wunused-function]
367 | static int inf_setfont (char *fontname)
| ^~~~~~~~~~~
3 warnings generated.
- Comparison is always false in sql_lite.c:
Perhaps one way to solve this would be to use the pre-processor and including the test for architecture where the comparison can be true?
sql_lite.c:2250:52: warning: result of comparison of constant 9223372036854775807 with expression of type 'unsigned int' is always false [-Wtautological-constant-out-of-range-compare]
2250 | if (unlikely(preparedStmt->result_column_count > INTTYPE_MAX)) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
./version.h:101:39: note: expanded from macro 'unlikely'
101 | #define unlikely(x) __builtin_expect((x),0)
| ^
1 warning generated.
- Comparison is always false AND unused functions in sql_oci.c:
sql_oci.c:2118:19: warning: result of comparison of constant 4611686018427387896 with expression of type 'ub4' (aka 'unsigned int') is always true [-Wtautological-constant-out-of-range-compare]
2118 | if (unlikely(!ALLOC_STRI_CHECK_SIZE(stri, length))) {
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./heaputl.h:427:111: note: expanded from macro 'ALLOC_STRI_CHECK_SIZE'
427 | #define ALLOC_STRI_CHECK_SIZE(var,len) ((len) < STRI_FREELIST_ARRAY_SIZE ? POP_OR_ALLOC_STRI(var,len) : ((len)<=MAX_STRI_LEN?HEAP_ALLOC_STRI(var, len):(var=NULL, FALSE)))
| ^
./version.h:101:39: note: expanded from macro 'unlikely'
101 | #define unlikely(x) __builtin_expect((x),0)
| ^
sql_oci.c:779:13: warning: unused function 'ociNumberToDecimalInt' [-Wunused-function]
779 | static void ociNumberToDecimalInt (const OCINumber *ociNumber, striType stri,
| ^~~~~~~~~~~~~~~~~~~~~
sql_oci.c:935:12: warning: unused function 'ociNumberToDecimalFraction' [-Wunused-function]
935 | static int ociNumberToDecimalFraction (const OCINumber *ociNumber, striType stri,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
sql_oci.c:1079:13: warning: unused function 'ociNumberFromDecimalInt' [-Wunused-function]
1079 | static void ociNumberFromDecimalInt (OCINumber *ociNumber, const const_striType decimal,
| ^~~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.
clang -O2 -g -ffunction-sections -fdata-sections -I"/opt/X11/include" -flto -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith -ftrapv -c -o sql_odbc.o sql_odbc.c
In file included from sql_odbc.c:79:
./sql_cli.c:518:13: warning: unused function 'memcpy_to_sqlwstri' [-Wunused-function]
518 | static void memcpy_to_sqlwstri (SQLWCHAR *dest, const char *src, memSizeType len)
| ^~~~~~~~~~~~~~~~~~
1 warning generated.
clang -O2 -g -ffunction-sections -fdata-sections -I"/opt/X11/include" -flto -Wall -Wstrict-prototypes -Winline -Wconversion -Wshadow -Wpointer-arith -ftrapv -c -o sql_post.o sql_post.c
sql_post.c:2442:17: warning: unused variable 'err_info' [-Wunused-variable]
2442 | errInfoType err_info = OKAY_NO_ERROR;
| ^~~~~~~~
1 warning generated.
- Implicit conversion loses precision in cmd_rtl:
cmd_rtl.c:4229:42: warning: implicit conversion loses integer precision: 'int' to 'mode_t' (aka 'unsigned short') [-Wimplicit-int-conversion]
4229 | chmod_result = os_chmod(os_path, int_mode);
| ~~~~~~~~ ^~~~~~~~
1 warning generated.
- variable set but not used in soc_rtl.c:
2 changes would be needed to fix this:
- The variable is not used, but debug code uses it. The debug code is commented out. A solution to this would be to control the declaration of the local variable by pre-processor conditional compilation statement, just as the debug code. The debug code would not be commented out but also under control of conditional compilation. The variable would be moved into the block that uses it (when compiled in).
- The REALLOC_STRI_CHECK_SIZE(v1,v2,l1,l2) never uses the l1 argument. That argument should therefore be removed and old_result_size would not be passed to it anymore, making it clearer in the user code that it's not used (except for debugging).
soc_rtl.c:1650:17: warning: variable 'old_result_size' set but not used [-Wunused-but-set-variable]
1650 | memSizeType old_result_size;
| ^
1 warning generated.
- variable set but not used in numutl.c:
2 changes would be needed to fix this:
- remove this local variable; it is set but not used, perhaps it was for debug code. In that case it should probably be controlled by pre-processor conditional compilation.
- Modify the declaration of
FREE_STR(str, len)
in heaputl.h to only use the first argument since the 4 implementation do not use the len argument. - This looks like a bigger problem.
FREE_STR()
is used in several places where the second argument is passed. but it is never used by the pre-processor macro as far as I can see.
numutl.c:281:17: warning: variable 'savedSize' set but not used [-Wunused-but-set-variable]
281 | memSizeType savedSize;
| ^
1 warning generated.
- implicit conversion looses precision in pol_unx.c:
pol_unx.c:889:70: warning: implicit conversion loses integer precision: 'const memSizeType' (aka 'const unsigned long') to 'nfds_t' (aka 'unsigned int') [-Wshorten-64-to-32]
889 | poll_result = os_poll(conv(pollData)->pollFds, conv(pollData)->size, -1); /* &timeout); */
| ~~~~~~~ ~~~~~~~~~~~~~~~~^~~~
1 warning generated.
- implicit conversion looses precision in tim_unx.c:
tim_unx.c:244:47: warning: implicit conversion loses integer precision: 'intType' (aka 'long') to '__darwin_suseconds_t' (aka 'int') [-Wshorten-64-to-32]
244 | timeout_value.tv_usec = micro_sec - time_val.tv_usec;
| ~ ~~~~~~~~~~^~~~~~~~~~~~~~~~~~
tim_unx.c:246:64: warning: implicit conversion loses integer precision: 'intType' (aka 'long') to '__darwin_suseconds_t' (aka 'int') [-Wshorten-64-to-32]
246 | timeout_value.tv_usec = 1000000 - time_val.tv_usec + micro_sec;
| ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
2 warnings generated.
Metadata
Metadata
Assignees
Labels
No labels