sipeed / TinyMaix

TinyMaix is a tiny inference library for microcontrollers (TinyML).
Apache License 2.0
879 stars 142 forks source link

build: compilation errors with `-Werror` flag #8

Closed windfallw closed 1 year ago

windfallw commented 1 year ago

Description

I'm trying to port this project to ESP32 using Platformio-espressif32 5.1.1 (ESP-IDF 4.4.1) , and I found that Platformio used -Werror flag for gcc compile which treat warning into an error.

xtensa-esp32-elf-gcc -o .pio/build/esp32dev/src/main.o -c -Og -Wall -Werror=all -Wextra -Wno-error=deprecated-declarations -Wno-error=unused-but-set-variable -Wno-error=unused-function -Wno-error=unused-variable -Wno-frame-address -Wno-old-style-declaration -Wno-sign-compare -Wno-unused-parameter -fdata-sections -ffunction-sections......

Although it can be simplely add build_unflags = -Werror=all in platformio.ini to make the compilation successful, but I think it is better to fix these warnings for compatibility.

https://community.platformio.org/t/disable-warning-errors/13280/2

GCC output

tm_model.c

lib/TinyMaix/src/tm_model.c:98:23: error: pointer targets in assignment from 'uint8_t *' {aka 'unsigned char *'} to 'mtype_t *' {aka 'signed char *'} differ in signedness [-Werror=pointer-sign]
             _in.data  = mdl->buf + h->in_oft;
                       ^
lib/TinyMaix/src/tm_model.c:101:19: error: pointer targets in assignment from 'uint8_t *' {aka 'unsigned char *'} to 'mtype_t *' {aka 'signed char *'} differ in signedness [-Werror=pointer-sign]
         _out.data = mdl->buf + h->out_oft;

tm_stat.c

lib/TinyMaix/src/tm_stat.c:59:61: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'unsigned int' [-Werror=format=]
     printf("---\tInput    \t%3d,%3d,%3d\t-   \t0    \t0 \t%ld \t0\n",\
                                                           ~~^
                                                           %d
         idim[1],idim[2],idim[3], idim[1]*idim[2]*idim[3]*sizeof(mtype_t));
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/TinyMaix/src/tm_stat.c:113:64: error: format '%ld' expects argument of type 'long int', but argument 10 has type 'unsigned int' [-Werror=format=]
             printf("%03d\t%s      \t%3d,%3d,%3d\t%d\t%d\t%d\t%ld\t", layer_i, tml_str_tbl[h->type], \
                                                              ~~^
                                                              %d

mnist.c

src/mnist.c:144:25: error: missing braces around initializer [-Werror=missing-braces]
     tm_mat_t in_uint8 = {3, 28, 28, 1, (mtype_t *)mnist_pic};
                         ^
                                        {                   }
src/mnist.c:145:19: error: missing braces around initializer [-Werror=missing-braces]
     tm_mat_t in = {3, 28, 28, 1, NULL};
                   ^

My solution

_in.data = (mtype_t *)(mdl->buf + h->in_oft);
_out.data = (mtype_t *)(mdl->buf + h->out_oft);

printf("---\tInput    \t%3d,%3d,%3d\t-   \t0    \t0 \t%ld \t0\n",\
    idim[1],idim[2],idim[3], (long int)idim[1]*idim[2]*idim[3]*sizeof(mtype_t));
printf("%03d\t%s      \t%3d,%3d,%3d\t%d\t%d\t%d\t%ld\t", layer_i, tml_str_tbl[h->type], \
    h->out_dims[1], h->out_dims[2], h->out_dims[3], \
    h->in_oft, h->out_oft, h->size - tml_headsize_tbl[h->type], \
    (long int)memout*sizeof(mtype_t));

tm_mat_t in_uint8 = {3, 28, 28, 1, {(mtype_t *)mnist_pic}};
tm_mat_t in = {3, 28, 28, 1, {NULL}};
Zepan commented 1 year ago

hello, thank you for your report! just fixed it, please pull and try again~

windfallw commented 1 year ago

hello, thank you for your report! just fixed it, please pull and try again~

Hi, I have tried the newest repo, now it works with platformio without unflag -Werror=all. just with some unused variable and multi-character character constant warnings, but that doesn't matter

warnings