Temporary fix for bug 4254 - a _lot_ of strict aliasing warnings Ozkan Sezer A horde of strict aliasing violation warnings are emitted from joystick layer, and also from a few other places. This happens with gcc-4.4.7 on Linux CentOS 6.10. Some other sysjoystick would possibly have the same warnings. Attached my full log here. Example entry: src/joystick/SDL_joystick.c: In function 'SDL_GetJoystickGUIDInfo': src/joystick/SDL_joystick.c:1094: warning: dereferencing pointer '({anonymous})' does break strict-aliasing rules
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 89b4aa3..e80d275 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -418,6 +418,11 @@ if(USE_GCC OR USE_CLANG)
endif()
endif()
+ check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
+ if(HAVE_GCC_NO_STRICT_ALIASING)
+ list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
+ endif()
+
check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
diff --git a/configure b/configure
index 7e21bed..d0bb5b0 100755
--- a/configure
+++ b/configure
@@ -19396,6 +19396,43 @@ $as_echo "$have_gcc_fvisibility" >&6; }
fi
}
+CheckNoStrictAliasing()
+{
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -fno-strict-aliasing option" >&5
+$as_echo_n "checking for GCC -fno-strict-aliasing option... " >&6; }
+ have_gcc_no_strict_aliasing=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -fno-strict-aliasing"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ int x = 0;
+
+int
+main ()
+{
+
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ have_gcc_no_strict_aliasing=yes
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_no_strict_aliasing" >&5
+$as_echo "$have_gcc_no_strict_aliasing" >&6; }
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_no_strict_aliasing = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -fno-strict-aliasing"
+ fi
+}
+
CheckStackBoundary()
{
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -mpreferred-stack-boundary option" >&5
@@ -24334,6 +24371,7 @@ fi
CheckWarnAll
+CheckNoStrictAliasing
CheckEventSignals
@@ -24402,8 +24440,8 @@ case "$host" in
CheckOpenGLESX11
CheckVulkan
CheckWayland
- CheckLibUDev
CheckInputEvents
+ CheckLibUDev
CheckDBus
CheckIME
CheckIBus
diff --git a/configure.ac b/configure.ac
index b76c4d2..0f637ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1329,6 +1329,29 @@ CheckVisibilityHidden()
fi
}
+dnl See if GCC's -fno-strict-aliasingis supported.
+dnl Reference: https://bugzilla.libsdl.org/show_bug.cgi?id=4254
+CheckNoStrictAliasing()
+{
+ AC_MSG_CHECKING(for GCC -fno-strict-aliasing option)
+ have_gcc_no_strict_aliasing=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -fno-strict-aliasing"
+ AC_TRY_COMPILE([
+ int x = 0;
+ ],[
+ ],[
+ have_gcc_no_strict_aliasing=yes
+ ])
+ AC_MSG_RESULT($have_gcc_no_strict_aliasing)
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_no_strict_aliasing = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -fno-strict-aliasing"
+ fi
+}
+
dnl See if GCC's -mpreferred-stack-boundary is supported.
dnl Reference: http://bugzilla.libsdl.org/show_bug.cgi?id=1296
CheckStackBoundary()
@@ -3263,6 +3286,7 @@ AS_HELP_STRING([--enable-foregrounding-signal], [number to use for magic foregro
dnl Do this on all platforms, before everything else (other things might want to override it).
CheckWarnAll
+CheckNoStrictAliasing
dnl Do this for every platform, but for some it doesn't mean anything, but better to catch it here anyhow.
CheckEventSignals