On 5/6/21 6:30 AM, Martin Kletzander wrote:
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])
Do we really need to skip compiling the example altogether, or can we just modify CFLAGS to add -Wno-strict-aliasing to prevent the failure? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org