From 345996c6208b281233074362a8d81295e2e711d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 31 Aug 2021 15:05:15 +0100 Subject: [PATCH] meson: avoid bogus warnings from clang and g_autoptr MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Clang has previously had trouble with G_DEFINE_AUTOPTR_CLEANUP_FUNC generated code, thinking it was unused. We turn off -Wunused-function to avoid tripping up on that with CLang. New Clang has started having trouble with g_autoptr now too. In usage scenarios where the variable is set, but never again read, it thinks it is unused not realizing the destructor has useful side effects. For this we have to skip -Wunused-but-set-variable on CLang. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrangé --- build-aux/syntax-check.mk | 2 +- meson.build | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2058af0b77..5c5a2a8771 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1589,7 +1589,7 @@ exclude_file_name_regexp--sc_prohibit_canonicalize_file_name = \ ^(build-aux/syntax-check\.mk|tests/virfilemock\.c)$$ exclude_file_name_regexp--sc_prohibit_raw_allocation = \ - ^(docs/advanced-tests\.rst|src/util/viralloc\.[ch]|examples/.*|tests/(securityselinuxhelper|(vircgroup|nss)mock|commandhelper)\.c|tools/wireshark/src/packet-libvirt\.c|tools/nss/libvirt_nss(_leases|_macs)?\.c)$$ + ^(meson\.build|docs/advanced-tests\.rst|src/util/viralloc\.[ch]|examples/.*|tests/(securityselinuxhelper|(vircgroup|nss)mock|commandhelper)\.c|tools/wireshark/src/packet-libvirt\.c|tools/nss/libvirt_nss(_leases|_macs)?\.c)$$ exclude_file_name_regexp--sc_prohibit_readlink = \ ^src/(util/virutil|lxc/lxc_container)\.c$$ diff --git a/meson.build b/meson.build index 9d493ccd9e..a8c99ac4b1 100644 --- a/meson.build +++ b/meson.build @@ -470,6 +470,27 @@ if get_option('warning_level') == '2' supported_cc_flags += [ '-Wno-unused-function' ] endif + if supported_cc_flags.contains('-Wunused-but-set-variable') + # Clang complains about unused variables in many scenarios related + # to attribute((cleanup)) aka g_auto* + w_unused_but_set_var_args = [ '-Wunused-but-set-variable', '-Werror' ] + w_unused_but_set_var_code = ''' + static inline void free_pointer (void *p) { + void **pp = (void**)p; + free (*pp); + } + + int main(void) { + __attribute__((cleanup(free_pointer))) char *buffer = 0x0; + buffer = 0x1; + } + ''' + # We previously turned on unused-but-set-variable, so we must turn + # it off again explicitly now. + if not cc.compiles(w_unused_but_set_var_code, args: w_unused_but_set_var_args) + supported_cc_flags += [ '-Wno-unused-but-set-variable' ] + endif + endif endif add_project_arguments(supported_cc_flags, language: 'c') -- 2.47.2