Beef up configury for the undefined behaviour sanitiser.
If the compiler supports -fno-sanitize=alignment use it.
Otherwise, there will be complaints about misaligned
memory accesses. This is needed for GCC 5.1.
If that flag is not supported simply pass in -fsantize=undefined
and assume that it won't check for alignment violations (which
is true for GCC 4.9).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15351 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.ac b/configure.ac
index bac11ef..558adf3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1834,11 +1834,26 @@
 AC_SUBST(FLAG_FNO_IPA_ICF)
 
 
-# Does this compiler support -fsanitize=undefined?
+# Does this compiler support -fsanitize=undefined. This is true for
+# GCC 4.9 and newer. However, the undefined behaviour sanitiser in GCC 5.1
+# also checks for alignment violations on memory accesses which the valgrind
+# code base is sprinkled (if not littered) with. As those alignment issues
+# don't pose a problem we want to suppress warnings about them.
+# In GCC 5.1 this can be done by passing -fno-sanitize=alignment. Earlier
+# GCCs do not support that.
+#
 # Only checked for if --enable-ubsan was given.
 if test "x${vg_cv_ubsan}" = "xyes"; then
-AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined])
+AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined -fno-sanitize=alignment])
 safe_CFLAGS=$CFLAGS
+CFLAGS="-fsanitize=undefined -fno-sanitize=alignment -Werror"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+  return 0;
+]])], [
+FLAG_FSANITIZE="-fsanitize=undefined -fno-sanitize=alignment"
+LIB_UBSAN="-static-libubsan"
+AC_MSG_RESULT([yes])
+], [
 CFLAGS="-fsanitize=undefined -Werror"
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
   return 0;
@@ -1851,6 +1866,7 @@
 LIB_UBSAN=""
 AC_MSG_RESULT([no])
 ])
+])
 CFLAGS=$safe_CFLAGS
 AC_SUBST(FLAG_FSANITIZE)
 AC_SUBST(LIB_UBSAN)