On Wed, Aug 25, 2021 at 02:43:20PM +0200, Tim Wiederhake wrote:
See comment for rationale.
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/util/glibcompat.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h
index 697687b967..fe495c5c32 100644
--- a/src/util/glibcompat.h
+++ b/src/util/glibcompat.h
@@ -86,3 +86,23 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args)
#define g_fsync vir_g_fsync
void vir_g_source_unref(GSource *src, GMainContext *ctx);
+
+/*
+ * Clang falsely tags variable definitions as unused if the only access happens
+ * during the variables destruction at scope exit. See
+ *
https://bugs.llvm.org/show_bug.cgi?id=3888 and
+ *
https://bugs.llvm.org/show_bug.cgi?id=43482.
+ */
+#if defined(__clang__)
+# define vir_g_auto(X) g_auto(X) G_GNUC_UNUSED
+# define vir_g_autolist(X) g_autolist(X) G_GNUC_UNUSED
+# define vir_g_autoptr(X) g_autoptr(X) G_GNUC_UNUSED
+# define vir_g_autoqueue(X) g_autoqueue(X) G_GNUC_UNUSED
+# define vir_g_autoslist(X) g_autoslist(X) G_GNUC_UNUSED
+#else
+# define vir_g_auto(X) g_auto(X)
+# define vir_g_autolist(X) g_autolist(X)
+# define vir_g_autoptr(X) g_autoptr(X)
+# define vir_g_autoqueue(X) g_autoqueue(X)
+# define vir_g_autoslist(X) g_autoslist(X)
+#endif /* __clang__ */
I don't think this belongs into this file. It is meant to workaround
bugs in glib, not in compilers. In addition I don't think we would like
to mix vir_g_auto and g_auto within libvirt codebase. If we need to
introduce our own wrappers we should undefine the original symbol and
replace it like we do with g_fsync for example:
Pavel