Skip to content

Commit

Permalink
configure: Disable strict aliasing.
Browse files Browse the repository at this point in the history
The C standard allows compilers to do type-based alias analysis, which
means that the compiler is allowed to assume that pointers to objects of
different types are pointers to different objects.  For example, a compiler
may assume that "uint16_t *a" and "uint32_t *b" point to different and
nonoverlapping locations because the pointed-to types are different.  This
can lead to surprising "optimizations" with compilers that by default do
this kind of analysis, which includes GCC and Clang.

The one escape clause that the C standard gives us is that character types
must be assumed to alias any other object.  We've always tried to use this
escape clause to avoid problems with type-based alias analysis in the past.
I think that we should continue to try to do this in the future.  It's hard
to tell what compiler we might want to use in the future, and one never
knows what kind of control that compiler allows over alias analysis.

However, recently I helped another developer debug a nasty and confusing
issue, which turned out to be the result of a surprising compiler
optimization due to alias analysis.  I've seen enough of these that I don't
think it's worthwhile to risk more problems than we have to.  Thus, this
commit turns off type-based alias analysis in GCC and Clang.

Linus Torvalds thinks that type-base alias analysis is not sane, at least
as GCC implements it: https://lkml.org/lkml/2003/2/26/158

The GCC manual says that -Wstrict-aliasing is only effective without
-fno-strict-aliasing, otherwise I'd keep -Wstrict-aliasing also.

Indications are that MSVC doesn't do type-based alias analysis by default.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
  • Loading branch information
blp committed Oct 1, 2014
1 parent d25e2f5 commit 538919d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -104,14 +104,14 @@ OVS_ENABLE_OPTION([-Wformat-security])
OVS_ENABLE_OPTION([-Wno-format-zero-length])
OVS_ENABLE_OPTION([-Wswitch-enum])
OVS_ENABLE_OPTION([-Wunused-parameter])
OVS_ENABLE_OPTION([-Wstrict-aliasing])
OVS_ENABLE_OPTION([-Wbad-function-cast])
OVS_ENABLE_OPTION([-Wcast-align])
OVS_ENABLE_OPTION([-Wstrict-prototypes])
OVS_ENABLE_OPTION([-Wold-style-definition])
OVS_ENABLE_OPTION([-Wmissing-prototypes])
OVS_ENABLE_OPTION([-Wmissing-field-initializers])
OVS_ENABLE_OPTION([-Wthread-safety])
OVS_ENABLE_OPTION([-fno-strict-aliasing])
OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED])
OVS_CONDITIONAL_CC_OPTION([-Wno-unused-parameter], [HAVE_WNO_UNUSED_PARAMETER])
OVS_ENABLE_WERROR
Expand Down

0 comments on commit 538919d

Please sign in to comment.