DragonMinded / libdragon

Open source library for N64 development.
https://libdragon.dev
The Unlicense
748 stars 108 forks source link

Address warnings on building libdragon #515

Closed Dragorn421 closed 6 months ago

Dragorn421 commented 8 months ago

Addresses the following warnings:

for n64 code (reported as errors due to a -Werror in the corresponding example's Makefile):

``` /opt/n64/libragon/mips64-elf/include/graphics.h: In function 'color_t color_from_packed16(uint16_t)': /opt/n64/libragon/mips64-elf/include/graphics.h:62:40: error: narrowing conversion of '(((int)(((short unsigned int)((int)(c >> 11))) & 31)) << 3)' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 62 | return (color_t){ .r=((c>>11)&0x1F)<<3, .g=((c>>6)&0x1F)<<3, .b=((c>>1)&0x1F)<<3, .a=(c&0x1) ? 0xFF : 0 }; | ~~~~~~~~~~~~~~^~~ /opt/n64/libragon/mips64-elf/include/graphics.h:62:61: error: narrowing conversion of '(((int)(((short unsigned int)((int)(c >> 6))) & 31)) << 3)' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 62 | return (color_t){ .r=((c>>11)&0x1F)<<3, .g=((c>>6)&0x1F)<<3, .b=((c>>1)&0x1F)<<3, .a=(c&0x1) ? 0xFF : 0 }; | ~~~~~~~~~~~~~^~~ /opt/n64/libragon/mips64-elf/include/graphics.h:62:82: error: narrowing conversion of '(((int)(((short unsigned int)((int)(c >> 1))) & 31)) << 3)' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 62 | return (color_t){ .r=((c>>11)&0x1F)<<3, .g=((c>>6)&0x1F)<<3, .b=((c>>1)&0x1F)<<3, .a=(c&0x1) ? 0xFF : 0 }; | ~~~~~~~~~~~~~^~~ /opt/n64/libragon/mips64-elf/include/graphics.h:62:98: error: narrowing conversion of '((((int)(((short unsigned int)((int)c)) & 1)) != 0) ? 255 : 0)' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 62 | return (color_t){ .r=((c>>11)&0x1F)<<3, .g=((c>>6)&0x1F)<<3, .b=((c>>1)&0x1F)<<3, .a=(c&0x1) ? 0xFF : 0 }; | ~~~~~~~~^~~~~~~~~~ /opt/n64/libragon/mips64-elf/include/graphics.h: In function 'color_t color_from_packed32(uint32_t)': /opt/n64/libragon/mips64-elf/include/graphics.h:67:33: error: narrowing conversion of '((c >> 24) & 255)' from 'long unsigned int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 67 | return (color_t){ .r=(c>>24)&0xFF, .g=(c>>16)&0xFF, .b=(c>>8)&0xFF, .a=c&0xFF }; | ~~~~~~~^~~~~ /opt/n64/libragon/mips64-elf/include/graphics.h:67:50: error: narrowing conversion of '((c >> 16) & 255)' from 'long unsigned int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 67 | return (color_t){ .r=(c>>24)&0xFF, .g=(c>>16)&0xFF, .b=(c>>8)&0xFF, .a=c&0xFF }; | ~~~~~~~^~~~~ /opt/n64/libragon/mips64-elf/include/graphics.h:67:66: error: narrowing conversion of '((c >> 8) & 255)' from 'long unsigned int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 67 | return (color_t){ .r=(c>>24)&0xFF, .g=(c>>16)&0xFF, .b=(c>>8)&0xFF, .a=c&0xFF }; | ~~~~~~^~~~~ /opt/n64/libragon/mips64-elf/include/graphics.h:67:77: error: narrowing conversion of '(c & 255)' from 'long unsigned int' to 'uint8_t' {aka 'unsigned char'} [-Werror=narrowing] 67 | return (color_t){ .r=(c>>24)&0xFF, .g=(c>>16)&0xFF, .b=(c>>8)&0xFF, .a=c&0xFF }; | ~^~~~~ In file included from /opt/n64/libragon/mips64-elf/include/libdragon.h:58: /opt/n64/libragon/mips64-elf/include/surface.h: In function 'surface_t surface_make(void*, tex_format_t, uint32_t, uint32_t, uint32_t)': /opt/n64/libragon/mips64-elf/include/surface.h:168:18: error: narrowing conversion of 'width' from 'uint32_t' {aka 'long unsigned int'} to 'uint16_t' {aka 'short unsigned int'} [-Werror=narrowing] 168 | .width = width, | ^~~~~ /opt/n64/libragon/mips64-elf/include/surface.h:169:19: error: narrowing conversion of 'height' from 'uint32_t' {aka 'long unsigned int'} to 'uint16_t' {aka 'short unsigned int'} [-Werror=narrowing] 169 | .height = height, | ^~~~~~ /opt/n64/libragon/mips64-elf/include/surface.h:170:19: error: narrowing conversion of 'stride' from 'uint32_t' {aka 'long unsigned int'} to 'uint16_t' {aka 'short unsigned int'} [-Werror=narrowing] 170 | .stride = stride, | ^~~~~~ ```

for tools:

``` n64sym.c: In function ‘symbol_add’: n64sym.c:136:13: warning: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 136 | asprintf(&addrbin, "%s/bin/mips64-elf-addr2line", n64_inst); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ n64sym.c:183:9: warning: ignoring return value of ‘getline’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 183 | getline(&line_buf, &line_buf_size, addr2line_r); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ n64sym.c:205:5: warning: ignoring return value of ‘getline’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 205 | getline(&line_buf, &line_buf_size, addr2line_r); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ n64sym.c:206:5: warning: ignoring return value of ‘getline’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 206 | getline(&line_buf, &line_buf_size, addr2line_r); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [AR] libdragon.a n64sym.c: In function ‘elf_find_callsites’: n64sym.c:213:5: warning: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 213 | asprintf(&cmd, "%s/bin/mips64-elf-objdump -d %s", n64_inst, elf); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
Dragorn421 commented 8 months ago

My N64 cross gcc btw since CI/others didn't seem to have the surface color funcs warnings:

$ $N64_GCCPREFIX/bin/mips64-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/n64/libragon_gcc/bin/mips64-elf-gcc
COLLECT_LTO_WRAPPER=/opt/n64/libragon_gcc/libexec/gcc/mips64-elf/13.2.0/lto-wrapper
Target: mips64-elf
Configured with: ../gcc-13.2.0/configure --prefix=/opt/n64/libragon_gcc --target=mips64-elf --with-arch=vr4300 --with-tune=vr4300 --enable-languages=c,c++ --without-headers --disable-libssp --enable-multilib --disable-shared --with-gcc --with-newlib --disable-threads --disable-win32-registry --disable-nls --disable-werror --with-system-zlib
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (GCC)