Temporary fix for bug 4254 - a _lot_ of strict aliasing warnings
authorSam Lantinga <slouken@libsdl.org>
Sat, 08 Jun 2019 18:32:29 -0700
changeset 128041a330416800d
parent 12803 70d338e248c8
child 12805 00a1aa5a1fc0
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
CMakeLists.txt
configure
configure.ac
     1.1 --- a/CMakeLists.txt	Sat Jun 08 18:22:18 2019 -0700
     1.2 +++ b/CMakeLists.txt	Sat Jun 08 18:32:29 2019 -0700
     1.3 @@ -418,6 +418,11 @@
     1.4      endif()
     1.5    endif()
     1.6  
     1.7 +  check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
     1.8 +  if(HAVE_GCC_NO_STRICT_ALIASING)
     1.9 +    list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
    1.10 +  endif()
    1.11 +
    1.12    check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
    1.13    if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
    1.14      check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
     2.1 --- a/configure	Sat Jun 08 18:22:18 2019 -0700
     2.2 +++ b/configure	Sat Jun 08 18:32:29 2019 -0700
     2.3 @@ -19396,6 +19396,43 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +CheckNoStrictAliasing()
     2.8 +{
     2.9 +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -fno-strict-aliasing option" >&5
    2.10 +$as_echo_n "checking for GCC -fno-strict-aliasing option... " >&6; }
    2.11 +    have_gcc_no_strict_aliasing=no
    2.12 +
    2.13 +    save_CFLAGS="$CFLAGS"
    2.14 +    CFLAGS="$save_CFLAGS -fno-strict-aliasing"
    2.15 +    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    2.16 +/* end confdefs.h.  */
    2.17 +
    2.18 +    int x = 0;
    2.19 +
    2.20 +int
    2.21 +main ()
    2.22 +{
    2.23 +
    2.24 +
    2.25 +  ;
    2.26 +  return 0;
    2.27 +}
    2.28 +_ACEOF
    2.29 +if ac_fn_c_try_compile "$LINENO"; then :
    2.30 +
    2.31 +    have_gcc_no_strict_aliasing=yes
    2.32 +
    2.33 +fi
    2.34 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    2.35 +    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_no_strict_aliasing" >&5
    2.36 +$as_echo "$have_gcc_no_strict_aliasing" >&6; }
    2.37 +    CFLAGS="$save_CFLAGS"
    2.38 +
    2.39 +    if test x$have_gcc_no_strict_aliasing = xyes; then
    2.40 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -fno-strict-aliasing"
    2.41 +    fi
    2.42 +}
    2.43 +
    2.44  CheckStackBoundary()
    2.45  {
    2.46      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -mpreferred-stack-boundary option" >&5
    2.47 @@ -24334,6 +24371,7 @@
    2.48  
    2.49  
    2.50  CheckWarnAll
    2.51 +CheckNoStrictAliasing
    2.52  
    2.53  CheckEventSignals
    2.54  
    2.55 @@ -24402,8 +24440,8 @@
    2.56          CheckOpenGLESX11
    2.57          CheckVulkan
    2.58          CheckWayland
    2.59 +        CheckInputEvents
    2.60          CheckLibUDev
    2.61 -        CheckInputEvents
    2.62          CheckDBus
    2.63          CheckIME
    2.64          CheckIBus
     3.1 --- a/configure.ac	Sat Jun 08 18:22:18 2019 -0700
     3.2 +++ b/configure.ac	Sat Jun 08 18:32:29 2019 -0700
     3.3 @@ -1329,6 +1329,29 @@
     3.4      fi
     3.5  }
     3.6  
     3.7 +dnl See if GCC's -fno-strict-aliasingis supported.
     3.8 +dnl  Reference: https://bugzilla.libsdl.org/show_bug.cgi?id=4254
     3.9 +CheckNoStrictAliasing()
    3.10 +{
    3.11 +    AC_MSG_CHECKING(for GCC -fno-strict-aliasing option)
    3.12 +    have_gcc_no_strict_aliasing=no
    3.13 +
    3.14 +    save_CFLAGS="$CFLAGS"
    3.15 +    CFLAGS="$save_CFLAGS -fno-strict-aliasing"
    3.16 +    AC_TRY_COMPILE([
    3.17 +    int x = 0;
    3.18 +    ],[
    3.19 +    ],[
    3.20 +    have_gcc_no_strict_aliasing=yes
    3.21 +    ])
    3.22 +    AC_MSG_RESULT($have_gcc_no_strict_aliasing)
    3.23 +    CFLAGS="$save_CFLAGS"
    3.24 +
    3.25 +    if test x$have_gcc_no_strict_aliasing = xyes; then
    3.26 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -fno-strict-aliasing"
    3.27 +    fi
    3.28 +}
    3.29 +
    3.30  dnl See if GCC's -mpreferred-stack-boundary is supported.
    3.31  dnl  Reference: http://bugzilla.libsdl.org/show_bug.cgi?id=1296
    3.32  CheckStackBoundary()
    3.33 @@ -3263,6 +3286,7 @@
    3.34  
    3.35  dnl Do this on all platforms, before everything else (other things might want to override it).
    3.36  CheckWarnAll
    3.37 +CheckNoStrictAliasing
    3.38  
    3.39  dnl Do this for every platform, but for some it doesn't mean anything, but better to catch it here anyhow.
    3.40  CheckEventSignals