[PATCH] meson.build: Fix glib -Wno-unused-function workaround

Nicolas Saenz Julienne posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230524173123.66483-1-nsaenz@amazon.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] meson.build: Fix glib -Wno-unused-function workaround
Posted by Nicolas Saenz Julienne 1 year ago
We want to only enable '-Wno-unused-function' if glib's version is
smaller than '2.57.2' and has a G_DEFINE_AUTOPTR_CLEANUP_FUNC()
implementation that doesn't take into account unused functions. But the
compilation test isn't working as intended as '-Wunused-function' isn't
enabled while running it.

Let's enable it.

Fixes: fc9a809e0d28 ("build: move glib detection and workarounds to meson")
Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>

---

Meson logs before:

  Running compile:
  Working directory:  /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk
  Command line:  clang -m64 -mcx16 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk/testfile.c -o /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk/output.obj -c -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu11 -Werror

  Code:

    #include <glib.h>
    typedef struct Foo {
      int i;
    } Foo;
    static void foo_free(Foo *f)
    {
      g_free(f);
    }
    G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
    int main(void) { return 0; }
  Compiler stdout:

  Compiler stderr:


Meson logs after:

  Running compile:
  Working directory:  /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u
  Command line:  clang -m64 -mcx16 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/testfile.c -o /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/output.obj -c -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu11 -Wunused-function -Werror

  Code:

    #include <glib.h>
    typedef struct Foo {
      int i;
    } Foo;
    static void foo_free(Foo *f)
    {
      g_free(f);
    }
    G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
    int main(void) { return 0; }
  Compiler stdout:

  Compiler stderr:
   /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/testfile.c:10:3: error: unused function 'glib_autoptr_cleanup_Foo' [-Werror,-Wunused-function]
    G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
    ^
  /usr/include/glib-2.0/glib/gmacros.h:461:22: note: expanded from macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC'
    static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); }         \
                       ^
  /usr/include/glib-2.0/glib/gmacros.h:441:43: note: expanded from macro '_GLIB_AUTOPTR_FUNC_NAME'
  #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
                                            ^
  <scratch space>:58:1: note: expanded from here
  glib_autoptr_cleanup_Foo
  ^

 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index ef181ff2df..71a4fcee52 100644
--- a/meson.build
+++ b/meson.build
@@ -780,7 +780,7 @@ if not cc.compiles('''
     g_free(f);
   }
   G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
-  int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Werror'])
+  int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Wunused-function', '-Werror'])
   glib_cflags += cc.get_supported_arguments('-Wno-unused-function')
 endif
 glib = declare_dependency(dependencies: [glib_pc, gmodule],
-- 
2.39.2
Re: [PATCH] meson.build: Fix glib -Wno-unused-function workaround
Posted by Paolo Bonzini 1 year ago
Queued, thanks.

Paolo
Re: [PATCH] meson.build: Fix glib -Wno-unused-function workaround
Posted by Philippe Mathieu-Daudé 1 year ago
On 24/5/23 19:31, Nicolas Saenz Julienne wrote:
> We want to only enable '-Wno-unused-function' if glib's version is
> smaller than '2.57.2' and has a G_DEFINE_AUTOPTR_CLEANUP_FUNC()
> implementation that doesn't take into account unused functions. But the
> compilation test isn't working as intended as '-Wunused-function' isn't
> enabled while running it.
> 
> Let's enable it.
> 
> Fixes: fc9a809e0d28 ("build: move glib detection and workarounds to meson")
> Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>
> 
> ---
> 
> Meson logs before:
> 
>    Running compile:
>    Working directory:  /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk
>    Command line:  clang -m64 -mcx16 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk/testfile.c -o /local/home/nsaenz/c/qemu/build/meson-private/tmp5fgb3xnk/output.obj -c -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu11 -Werror
> 
>    Code:
> 
>      #include <glib.h>
>      typedef struct Foo {
>        int i;
>      } Foo;
>      static void foo_free(Foo *f)
>      {
>        g_free(f);
>      }
>      G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
>      int main(void) { return 0; }
>    Compiler stdout:
> 
>    Compiler stderr:
> 
> 
> Meson logs after:
> 
>    Running compile:
>    Working directory:  /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u
>    Command line:  clang -m64 -mcx16 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/testfile.c -o /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/output.obj -c -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu11 -Wunused-function -Werror
> 
>    Code:
> 
>      #include <glib.h>
>      typedef struct Foo {
>        int i;
>      } Foo;
>      static void foo_free(Foo *f)
>      {
>        g_free(f);
>      }
>      G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
>      int main(void) { return 0; }
>    Compiler stdout:
> 
>    Compiler stderr:
>     /local/home/nsaenz/c/qemu/build/meson-private/tmp1fnp2s4u/testfile.c:10:3: error: unused function 'glib_autoptr_cleanup_Foo' [-Werror,-Wunused-function]
>      G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
>      ^
>    /usr/include/glib-2.0/glib/gmacros.h:461:22: note: expanded from macro 'G_DEFINE_AUTOPTR_CLEANUP_FUNC'
>      static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); }         \
>                         ^
>    /usr/include/glib-2.0/glib/gmacros.h:441:43: note: expanded from macro '_GLIB_AUTOPTR_FUNC_NAME'
>    #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
>                                              ^
>    <scratch space>:58:1: note: expanded from here
>    glib_autoptr_cleanup_Foo
>    ^
> 
>   meson.build | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index ef181ff2df..71a4fcee52 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -780,7 +780,7 @@ if not cc.compiles('''
>       g_free(f);
>     }
>     G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
> -  int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Werror'])
> +  int main(void) { return 0; }''', dependencies: glib_pc, args: ['-Wunused-function', '-Werror'])

Oops, thanks!

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>