Skip to contentSkip to conversation

meson.build: Fix glib -Wno-unused-function workaround

PATCH Applied Nicolas Saenz Julienne 3 participants 3 messages May 24, 2023 – May 25, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meson.build: Fix glib -Wno-unused-function workaround

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")

---

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(-)
meson.build +1 -1
index ef181ff2df..71a4fcee52 100644
@@ -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],
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 78 lines · Nicolas Saenz Julienne

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")

---

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(-)
meson.build +0 -0
index ef181ff2df..71a4fcee52 100644

meson.build if not cc.compiles(''' · line 783

Quoted 5 lines
meson.build +1 -1
@@ -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!