meson: Run some compiler checks using -Wno-unused-value
RFC PATCH 1/1 meson: Run some compiler checks using -Wno-unused-value
When running Clang static analyzer on macOS I'm getting:
include/qemu/osdep.h:634:8: error: redefinition of 'iovec'
634 | struct iovec {
| ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_iovec_t.h:31:8: note: previous definition is here
31 | struct iovec {
| ^
1 error generated.Looking at meson-logs.txt, the analyzer enables -Wunused-value making meson generated code to fail:
Code:
#include <sys/uio.h>
void bar(void) {
sizeof(struct iovec);
}
-----------
stderr:
meson-private/tmpe8_1b_00/testfile.c:3:13: error: expression result unused [-Werror,-Wunused-value]
3 | sizeof(struct iovec);
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
-----------
Checking for type "struct iovec" : NO
Code:
#include <utmpx.h>
void bar(void) {
sizeof(struct utmpx);
}
-----------
stderr:
meson-private/tmp3n0u490p/testfile.c:3:13: error: expression result unused [-Werror,-Wunused-value]
3 | sizeof(struct utmpx);
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
-----------
Checking for type "struct utmpx" : NO
Code:
#include <getopt.h>
int main(void) {
/* If it's not defined as a macro, try to use as a symbol */
#ifndef optreset
optreset;
#endif
return 0;
}
-----------
stderr:
meson-private/tmp1rzob_os/testfile.c:6:17: error: expression result unused [-Werror,-Wunused-value]
6 | optreset;
| ^~~~~~~~
1 error generated.
-----------
Header "getopt.h" has symbol "optreset" : NO
Code:
#include <vmnet/vmnet.h>
int main(void) {
/* If it's not defined as a macro, try to use as a symbol */
#ifndef VMNET_BRIDGED_MODE
VMNET_BRIDGED_MODE;
#endif
return 0;
}
-----------
stderr:
meson-private/tmpl9jgsxpt/testfile.c:6:17: error: expression result unused [-Werror,-Wunused-value]
6 | VMNET_BRIDGED_MODE;
| ^~~~~~~~~~~~~~~~~~
1 error generated.
-----------
Header "vmnet/vmnet.h" has symbol "VMNET_BRIDGED_MODE" with dependency appleframeworks: NO
../meson.build:1174: WARNING: vmnet.framework API is outdated, disablingFix by explicitly disabling -Wunused-value from these meson checks.
---
RFC: Probably meson should do that in has_header_symbol() / has_type()?
--- meson.build | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
meson.build +7 -4
@@ -1166,7 +1166,8 @@ cocoa = dependency('appleframeworks', vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet')) if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h', 'VMNET_BRIDGED_MODE', - dependencies: vmnet) + dependencies: vmnet, + args: '-Wno-unused-value') vmnet = not_found if get_option('vmnet').enabled() error('vmnet.framework API is outdated')
@@ -2690,7 +2691,7 @@ config_host_data.set('CONFIG_RTNETLINK', config_host_data.set('CONFIG_SYSMACROS', cc.has_header_symbol('sys/sysmacros.h', 'makedev')) config_host_data.set('HAVE_OPTRESET', - cc.has_header_symbol('getopt.h', 'optreset')) + cc.has_header_symbol('getopt.h', 'optreset', args: '-Wno-unused-value')) config_host_data.set('HAVE_IPPROTO_MPTCP', cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
@@ -2708,10 +2709,12 @@ config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', # has_type config_host_data.set('CONFIG_IOVEC', cc.has_type('struct iovec', - prefix: '#include <sys/uio.h>')) + prefix: '#include <sys/uio.h>', + args: '-Wno-unused-value')) config_host_data.set('HAVE_UTMPX', cc.has_type('struct utmpx', - prefix: '#include <utmpx.h>')) + prefix: '#include <utmpx.h>', + args: '-Wno-unused-value')) config_host_data.set('CONFIG_EVENTFD', cc.links(''' #include <sys/eventfd.h>
Signature · 1 line
2.45.2
Quoted 1 line · Philippe Mathieu-Daudé
When running Clang static analyzer on macOS I'm getting:
snip
Quoted 5 lines
Fix by explicitly disabling -Wunused-value from these meson checks.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC: Probably meson should do that inhas_header_symbol()/has_type()?
How are you enabling the use of static analyzers ? There are several different ways to change compiler options and I vaguely recall some approaches can trip up meson.
Quoted 45 lines
--- meson.build | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)meson.build +7
-4@@ -1166,7 +1166,8 @@ cocoa = dependency('appleframeworks', vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet')) if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h', 'VMNET_BRIDGED_MODE', - dependencies: vmnet) + dependencies: vmnet, + args: '-Wno-unused-value') vmnet = not_found if get_option('vmnet').enabled() error('vmnet.framework API is outdated')@@ -2690,7 +2691,7 @@ config_host_data.set('CONFIG_RTNETLINK', config_host_data.set('CONFIG_SYSMACROS', cc.has_header_symbol('sys/sysmacros.h', 'makedev')) config_host_data.set('HAVE_OPTRESET', - cc.has_header_symbol('getopt.h', 'optreset')) + cc.has_header_symbol('getopt.h', 'optreset', args: '-Wno-unused-value')) config_host_data.set('HAVE_IPPROTO_MPTCP', cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))@@ -2708,10 +2709,12 @@ config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', # has_type config_host_data.set('CONFIG_IOVEC', cc.has_type('struct iovec', - prefix: '#include <sys/uio.h>')) + prefix: '#include <sys/uio.h>', + args: '-Wno-unused-value')) config_host_data.set('HAVE_UTMPX', cc.has_type('struct utmpx', - prefix: '#include <utmpx.h>')) + prefix: '#include <utmpx.h>', + args: '-Wno-unused-value')) config_host_data.set('CONFIG_EVENTFD', cc.links(''' #include <sys/eventfd.h>Signature · 1 line
2.45.2
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 8 lines · Daniel P. Berrangé
Quoted 1 line · Philippe Mathieu-Daudé
When running Clang static analyzer on macOS I'm getting:
snip
Quoted 2 lines
Fix by explicitly disabling -Wunused-value from these meson checks.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC: Probably meson should do that inhas_header_symbol()/has_type()?How are you enabling the use of static analyzers ? There are several different ways to change compiler options and I vaguely recall some approaches can trip up meson.
I prefix my build with 'scan-build':
$ scan-build make scan-build: Using '/usr/bin/clang' for static analysis config-host.mak is out-of-date, running configure C compiler for the host machine: clang (clang 16.0.0 "Apple clang version 16.0.0 (clang-1600.0.26.4)")
You can reproduce without using scan-build by passing --extra-cflags=-Wunused-value to ./configure.
We have a "disable some undesirable warnings" section in warn_flags[] in meson.build. If we want to ignore unused we should add it there, but I'd rather not ignore them ;)
Quoted 49 lines
Quoted 46 lines
--- meson.build | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)meson.build +7
-4@@ -1166,7 +1166,8 @@ cocoa = dependency('appleframeworks', vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet')) if vmnet.found() and not cc.has_header_symbol('vmnet/vmnet.h', 'VMNET_BRIDGED_MODE', - dependencies: vmnet) + dependencies: vmnet, + args: '-Wno-unused-value') vmnet = not_found if get_option('vmnet').enabled() error('vmnet.framework API is outdated')@@ -2690,7 +2691,7 @@ config_host_data.set('CONFIG_RTNETLINK', config_host_data.set('CONFIG_SYSMACROS', cc.has_header_symbol('sys/sysmacros.h', 'makedev')) config_host_data.set('HAVE_OPTRESET', - cc.has_header_symbol('getopt.h', 'optreset')) + cc.has_header_symbol('getopt.h', 'optreset', args: '-Wno-unused-value')) config_host_data.set('HAVE_IPPROTO_MPTCP', cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))@@ -2708,10 +2709,12 @@ config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', # has_type config_host_data.set('CONFIG_IOVEC', cc.has_type('struct iovec', - prefix: '#include <sys/uio.h>')) + prefix: '#include <sys/uio.h>', + args: '-Wno-unused-value')) config_host_data.set('HAVE_UTMPX', cc.has_type('struct utmpx', - prefix: '#include <utmpx.h>')) + prefix: '#include <utmpx.h>', + args: '-Wno-unused-value')) config_host_data.set('CONFIG_EVENTFD', cc.links(''' #include <sys/eventfd.h>Signature · 1 line
2.45.2With regards,
Daniel