Skip to content

fix clang warnings#3915

Open
peppergrayxyz wants to merge 8 commits into
ptitSeb:mainfrom
peppergrayxyz:clang_warnings
Open

fix clang warnings#3915
peppergrayxyz wants to merge 8 commits into
ptitSeb:mainfrom
peppergrayxyz:clang_warnings

Conversation

@peppergrayxyz
Copy link
Copy Markdown
Contributor

building using clang causes some warnings:

check linker flags
neoverse-n1 (-DADLINK) warns about unsupported linker flags:

clang: warning: optimization flag '-fuse-linker-plugin' is not supported [-Wignored-optimization-argument]
clang: warning: argument unused during compilation: '-fuse-ld=gold' [-Wunused-command-line-argument]

add check for ld.gold and only use it if available

use portable inttypes
warning about format specifier mismatch:

src/os/sysinfo.c:173:26: warning: format specifies type 'unsigned long long' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
  173 |     sprintf(str, "%llu", info->frequency);
      |                   ~~~~   ^~~~~~~~~~~~~~~
      |                   %lu
src/os/sysinfo.c:193:129: warning: format specifies type 'int' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
  193 |             snprintf(branding, sizeof(branding), BOX64_BUILD_INFO_STRING_SHORT " on %.*s @%04d MHz", 28, box64_sysinfo.cpuname, box64_sysinfo.frequency / 1000000);
      |                                                                                           ~~~~                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                           %04lu

use inttypes format macros instead of format specifiers directly

print missing argument
warning about an unused parameter:

src/emu/x64int3.c:208:117: warning: data argument not used by format string [-Wformat-extra-args]
  208 |                     snprintf(buff, 256, "%04d|%p: Calling %s(\"%s\")", tid, *(void**)(R_RSP), s, (tmp)?tmp:"(nil)", (tmp2)?tmp2:"nil");
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                               ^

use array indexing
warning about the way the signature is formated:

src/wrapped/wrappedvulkan_private.h:80:1: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
src/libtools/vulkanoverlay.c:133:94: note: expanded from macro 'GO_vFpff'
  133 | #define GO_vFpff(A, B, N)      static void my_##A##_##N(void* a, float b, float c) {F3(A, #B +2, N);}
      |                                                                                     ~~~~~~~~~^~~~~~
src/wrapped/wrappedvulkan_private.h:80:1: note: use array indexing to silence this warning

follow compiler suggestion and replace #B +2 with &(#B)[2]

use proper type in function signature
warning about type mismatch:

src/wrapped/wrappedgmp.c:158:38: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
  158 |     return my->__gmp_vasprintf(strp, fmt, VARARGS);
      |                                      ^~~
  165 |     return my->__gmp_vfprintf(stream, fmt, VARARGS);
      |                                       ^~~
  176 |     return my->__gmp_vasprintf(strp, fmt, VARARGS);
      |                                      ^~~
  187 |     return my->__gmp_vfprintf(stream, fmt, VARARGS);
      |                                       ^~~

modifiy definition to use the actual type instead of void.

remove extraneous parentheses
warning about extraneous parentheses:

src/wrapped32/wrappeddbus.c:541:18: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
  541 |         if((type == (int)'s')) {
      |             ~~~~~^~~~~~~~~~~
src/wrapped32/wrappeddbus.c:541:18: note: remove extraneous parentheses around the comparison to silence this warning

@ksco
Copy link
Copy Markdown
Collaborator

ksco commented May 29, 2026

Thank you for merging this!

Comment thread CMakeLists.txt Outdated
Copy link
Copy Markdown
Owner

@ptitSeb ptitSeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the needs of a C++ compiler.

building for neoverse-n1 (-DADLINK) with clang warns about unsupported
linker flags:
```
clang: warning: optimization flag '-fuse-linker-plugin' is not supported [-Wignored-optimization-argument]
clang: warning: argument unused during compilation: '-fuse-ld=gold' [-Wunused-command-line-argument]
```

add check for ld.gold and only use it if available

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building using clang warns about format specifier mismatch

```
src/os/sysinfo.c:173:26: warning: format specifies type 'unsigned long long' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
  173 |     sprintf(str, "%llu", info->frequency);
      |                   ~~~~   ^~~~~~~~~~~~~~~
      |                   %lu
src/os/sysinfo.c:193:129: warning: format specifies type 'int' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
  193 |             snprintf(branding, sizeof(branding), BOX64_BUILD_INFO_STRING_SHORT " on %.*s @%04d MHz", 28, box64_sysinfo.cpuname, box64_sysinfo.frequency / 1000000);
      |                                                                                           ~~~~                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                           %04lu
```

use inttypes format macros instead of format specifiers directly

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building using clangs warns about an unused parameter:
```
src/emu/x64int3.c:208:117: warning: data argument not used by format string [-Wformat-extra-args]
  208 |                     snprintf(buff, 256, "%04d|%p: Calling %s(\"%s\")", tid, *(void**)(R_RSP), s, (tmp)?tmp:"(nil)", (tmp2)?tmp2:"nil");
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                               ^
```

print the missing parameter

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building using clang warns about the way the signature is formated:

```
src/wrapped/wrappedvulkan_private.h:80:1: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
src/libtools/vulkanoverlay.c:133:94: note: expanded from macro 'GO_vFpff'
  133 | #define GO_vFpff(A, B, N)      static void my_##A##_##N(void* a, float b, float c) {F3(A, #B +2, N);}
      |                                                                                     ~~~~~~~~~^~~~~~
src/wrapped/wrappedvulkan_private.h:80:1: note: use array indexing to silence this warning
```

follow compiler suggestion and replace `#B +2` with `&(#B)[2]`

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building using clang warns about extraneous parentheses

```
src/wrapped32/wrappeddbus.c:541:18: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
  541 |         if((type == (int)'s')) {
      |             ~~~~~^~~~~~~~~~~
src/wrapped32/wrappeddbus.c:541:18: note: remove extraneous parentheses around the comparison to silence this warning
```

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building on clang warns about type mismatch:

```
src/wrapped/wrappedgmp.c:158:38: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
  158 |     return my->__gmp_vasprintf(strp, fmt, VARARGS);
      |                                      ^~~
  165 |     return my->__gmp_vfprintf(stream, fmt, VARARGS);
      |                                       ^~~
  176 |     return my->__gmp_vasprintf(strp, fmt, VARARGS);
      |                                      ^~~
  187 |     return my->__gmp_vfprintf(stream, fmt, VARARGS);
      |                                       ^~~
```

modifiy definition to use the actual type instead of void.

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
building using clang warns about excess elements in initalizer

```
src/wrapped/wrappercallback.h:16:53: warning: excess elements in struct initializer [-Wexcess-initializers]
   16 | static TYPENAME(LIBNAME) TYPENAME2(my_, LIBNAME) = {0};
      |                                                     ^
```

Signed-off-by: Pepper Gray <hello@peppergray.xyz>
@peppergrayxyz
Copy link
Copy Markdown
Contributor Author

peppergrayxyz commented May 29, 2026

I changed CXX to C and I added these as well:

excess elements in initializer
building using clang warns about excess elements in initializer

src/wrapped/wrappercallback.h:16:53: warning: excess elements in struct initializer [-Wexcess-initializers]
   16 | static TYPENAME(LIBNAME) TYPENAME2(my_, LIBNAME) = {0};
      |                                                     ^

remove excessive argument
building using clans warns about too many arguments:

src/wrapped32/wrappedopenal.c:104:41: warning: too many arguments in call to 'fillALProcWrapper32'
  104 |         fillALProcWrapper32(emu->context);
      |         ~~~~~~~~~~~~~~~~~~~             ^
src/wrapped32/wrappedopenal.c:104:28: warning: passing arguments to 'fillALProcWrapper32' without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
  104 |         fillALProcWrapper32(emu->context);
      |                            ^

Remove the argument, because the function doesn't take any

building using clans warns about too many arguments:

```
src/wrapped32/wrappedopenal.c:104:41: warning: too many arguments in call to 'fillALProcWrapper32'
  104 |         fillALProcWrapper32(emu->context);
      |         ~~~~~~~~~~~~~~~~~~~             ^
src/wrapped32/wrappedopenal.c:104:28: warning: passing arguments to 'fillALProcWrapper32' without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
  104 |         fillALProcWrapper32(emu->context);
      |                            ^
```

fillALProcWrapper32 takes no arguments

Signed-off-by: Pepper Gray <hello@peppergray.xyz>

static library_t* my_lib = NULL;
static TYPENAME(LIBNAME) TYPENAME2(my_, LIBNAME) = {0};
static TYPENAME(LIBNAME) TYPENAME2(my_, LIBNAME) = {};
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that a C23 feature? There are people that use old compiler, pretty sure that will not work there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, true... I just checked with clang and gcc but hadn't older compilers in mind. Is there actually any reason for the initializer? Since this is static anyway, it could be removed altogether

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, this warning appear only on a couple of file, and I think a solution is to remove the include file, because the structure is empty, the whole include file is not usefull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants