[libvirt] [PATCH] turn off strict-aliasing warnings in two files

Without these changes and with gcc-4.4, I'd get 4 warnings (2 in each file) about strict-aliasing violations. -Wstrict-aliasing is worth keeping in general, so I have disabled it only for the two offending files. The #if avoids the pragma on versions of gcc that don't recognize it.
From 7d7f8e5dd9754d2bbca1a0ec2f3a47d4eae9df30 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Fri, 6 Feb 2009 11:45:39 +0100 Subject: [PATCH] turn off strict-aliasing warnings in two files
* qemud/qemud.c: Disable gcc's strict-aliasing warnings in this file. * src/bridge.c: Likewise. --- qemud/qemud.c | 5 +++++ src/bridge.c | 5 +++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/qemud/qemud.c b/qemud/qemud.c index effb336..c3521e3 100644 --- a/qemud/qemud.c +++ b/qemud/qemud.c @@ -21,6 +21,11 @@ * Author: Daniel P. Berrange <berrange@redhat.com> */ +/* Tell gcc not to warn about aliasing (e.g., sockaddr_in) in this file. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + #include <config.h> #include <sys/types.h> diff --git a/src/bridge.c b/src/bridge.c index 8e577dd..62fa711 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -19,6 +19,11 @@ * Mark McLoughlin <markmc@redhat.com> */ +/* Tell gcc not to warn about aliasing (e.g., sockaddr_in) in this file. */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + #include <config.h> #if defined(WITH_BRIDGE) -- 1.6.1.2.511.gc5d3f

On Fri, Feb 06, 2009 at 07:31:46PM +0100, Jim Meyering wrote:
Without these changes and with gcc-4.4, I'd get 4 warnings (2 in each file) about strict-aliasing violations. -Wstrict-aliasing is worth keeping in general, so I have disabled it only for the two offending files.
Can you show what lines / code trigger the warnings and/r just post the warnings themselves ? Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

"Daniel P. Berrange" <berrange@redhat.com> wrote:
On Fri, Feb 06, 2009 at 07:31:46PM +0100, Jim Meyering wrote:
Without these changes and with gcc-4.4, I'd get 4 warnings (2 in each file) about strict-aliasing violations. -Wstrict-aliasing is worth keeping in general, so I have disabled it only for the two offending files.
Can you show what lines / code trigger the warnings and/r just post the warnings themselves ?
bridge.c:657: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:658: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules qemud.c:671: warning: dereferencing pointer 'sa.72' does break strict-aliasing rules qemud.c:674: warning: dereferencing pointer 'sa.73' does break strict-aliasing rules bridge.c: if ((ret = inet_pton(AF_INET, addr, &inaddr)) < 0) return errno; else if (ret == 0) return EINVAL; ((struct sockaddr_in *)&ifr.ifr_data)->sin_family = AF_INET; ((struct sockaddr_in *)&ifr.ifr_data)->sin_addr = inaddr; qemud.c: if (getsockname(sock->fd, (struct sockaddr *)(&sa), &salen) < 0) goto cleanup; if (sa.ss_family == AF_INET) sock->port = htons(((struct sockaddr_in*)&sa)->sin_port); #ifdef AF_INET6 else if (sa.ss_family == AF_INET6) sock->port = htons(((struct sockaddr_in6*)&sa)->sin6_port);

On Fri, Feb 06, 2009 at 08:12:24PM +0100, Jim Meyering wrote:
"Daniel P. Berrange" <berrange@redhat.com> wrote:
On Fri, Feb 06, 2009 at 07:31:46PM +0100, Jim Meyering wrote:
Without these changes and with gcc-4.4, I'd get 4 warnings (2 in each file) about strict-aliasing violations. -Wstrict-aliasing is worth keeping in general, so I have disabled it only for the two offending files.
Can you show what lines / code trigger the warnings and/r just post the warnings themselves ?
bridge.c:657: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules bridge.c:658: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules qemud.c:671: warning: dereferencing pointer 'sa.72' does break strict-aliasing rules qemud.c:674: warning: dereferencing pointer 'sa.73' does break strict-aliasing rules
Oh, this is a little more scary that previous GCC warnings, which merely say it 'might' break aliasing rules. GCC is clear here that it 'does' break aliasing rules, so IMHO we need to change the code, rather than turn off the warning. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
Jim Meyering