[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler



At some point GCC added some optimisations and checks that started emitting
warnings on harmless code:

  ...dereferencing type-punned pointer will break strict-aliasing rules...

This was later fixed, but can still break the build (or report warnings) on old
GCCs (e.g. 7.5.0) when building the libev example.

Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 configure.ac | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/configure.ac b/configure.ac
index 19b7bfdb5d2a..3b51354346cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,6 +247,30 @@ PKG_CHECK_MODULES([LIBEV], [libev], [
         AC_MSG_WARN([ev.h not found, some examples will not be compiled])
     ])
 ])
+
+AS_IF([test "x$LIBEV_LIBS" != "x"], [
+    old_CFLAGS="$CFLAGS"
+    CFLAGS="-Werror=strict-aliasing -O2"
+    AC_MSG_CHECKING([if the compiler is new enough for good aliasing rules])
+    AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([
+            #include <ev.h>
+
+            static void cb (struct ev_loop *l, ev_timer *t, int e) { }
+            static ev_timer timer;
+        ], [
+            ev_timer_init (&timer, cb, 0, .1);
+        ])
+    ], [
+        AC_MSG_RESULT([yes])
+    ], [
+        AC_MSG_RESULT([no])
+        AC_SUBST([LIBEV_CFLAGS], [""])
+        AC_SUBST([LIBEV_LIBS], [""])
+        AC_MSG_WARN([compiler is probably too old to compile with libev without errors, some examples will not be compiled])
+    ])
+    CFLAGS="$old_CFLAGS"
+])
 AM_CONDITIONAL([HAVE_LIBEV], [test "x$LIBEV_LIBS" != "x"])
 
 dnl FUSE 3 is optional to build the nbdfuse program.
-- 
2.31.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]