From c2037d6ec8ae82aadcff2a193bcac135b39eb84c Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 21 Jun 2010 17:04:07 +0000 Subject: [PATCH] only use -fno-strict-aliasing when needed by compiler --- configure | 71 ++++++++++++++++++++++++++++++++++++++++------------ configure.in | 38 ++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 26 deletions(-) diff --git a/configure b/configure index 2eb16b94ed..d7cffff8af 100755 --- a/configure +++ b/configure @@ -5295,33 +5295,72 @@ UNIVERSAL_ARCH_FLAGS= # tweak BASECFLAGS based on compiler and platform case $GCC in yes) - # Python violates C99 rules, by casting between incompatible - # pointer types. GCC may generate bad code as a result of that, - # so use -fno-strict-aliasing if supported. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -fno-strict-aliasing" >&5 -$as_echo_n "checking whether $CC accepts -fno-strict-aliasing... " >&6; } + # Python doesn't violate C99 aliasing rules, but older versions of + # GCC produce warnings for legal Python code. Enable + # -fno-strict-aliasing on versions of GCC that support but produce + # warnings. See Issue3326 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts and needs -fno-strict-aliasing" >&5 +$as_echo_n "checking whether $CC accepts and needs -fno-strict-aliasing... " >&6; } ac_save_cc="$CC" CC="$CC -fno-strict-aliasing" - if test "$cross_compiling" = yes; then : - ac_cv_no_strict_aliasing_ok=no + save_CFLAGS="$CFLAGS" + if test "${ac_cv_no_strict_aliasing+set}" = set; then : + $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -int main() { return 0; } + + +int +main () +{ + + ; + return 0; +} + _ACEOF -if ac_fn_c_try_run "$LINENO"; then : - ac_cv_no_strict_aliasing_ok=yes +if ac_fn_c_try_compile "$LINENO"; then : + + CC="$ac_save_cc -fstrict-aliasing" + CFLAGS="$CFLAGS -Werror -Wstrict-aliasing" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + void f(int **x) {} +int +main () +{ +double *x; f((int **) &x); + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + ac_cv_no_strict_aliasing=no + else - ac_cv_no_strict_aliasing_ok=no + + ac_cv_no_strict_aliasing=yes + fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +else + + ac_cv_no_strict_aliasing=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi + CFLAGS="$save_CFLAGS" CC="$ac_save_cc" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_no_strict_aliasing_ok" >&5 -$as_echo "$ac_cv_no_strict_aliasing_ok" >&6; } - if test $ac_cv_no_strict_aliasing_ok = yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_no_strict_aliasing" >&5 +$as_echo "$ac_cv_no_strict_aliasing" >&6; } + if test $ac_cv_no_strict_aliasing = yes then BASECFLAGS="$BASECFLAGS -fno-strict-aliasing" fi diff --git a/configure.in b/configure.in index f499fccf88..0520ea4444 100644 --- a/configure.in +++ b/configure.in @@ -878,19 +878,37 @@ AC_SUBST(UNIVERSAL_ARCH_FLAGS) # tweak BASECFLAGS based on compiler and platform case $GCC in yes) - # Python violates C99 rules, by casting between incompatible - # pointer types. GCC may generate bad code as a result of that, - # so use -fno-strict-aliasing if supported. - AC_MSG_CHECKING(whether $CC accepts -fno-strict-aliasing) + # Python doesn't violate C99 aliasing rules, but older versions of + # GCC produce warnings for legal Python code. Enable + # -fno-strict-aliasing on versions of GCC that support but produce + # warnings. See Issue3326 + AC_MSG_CHECKING(whether $CC accepts and needs -fno-strict-aliasing) ac_save_cc="$CC" CC="$CC -fno-strict-aliasing" - AC_TRY_RUN([int main() { return 0; }], - ac_cv_no_strict_aliasing_ok=yes, - ac_cv_no_strict_aliasing_ok=no, - ac_cv_no_strict_aliasing_ok=no) + save_CFLAGS="$CFLAGS" + AC_CACHE_VAL(ac_cv_no_strict_aliasing, + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([[]], [[]]) + ],[ + CC="$ac_save_cc -fstrict-aliasing" + CFLAGS="$CFLAGS -Werror -Wstrict-aliasing" + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([[void f(int **x) {}]], + [[double *x; f((int **) &x);]]) + ],[ + ac_cv_no_strict_aliasing=no + ],[ + ac_cv_no_strict_aliasing=yes + ]) + ],[ + ac_cv_no_strict_aliasing=no + ])) + CFLAGS="$save_CFLAGS" CC="$ac_save_cc" - AC_MSG_RESULT($ac_cv_no_strict_aliasing_ok) - if test $ac_cv_no_strict_aliasing_ok = yes + AC_MSG_RESULT($ac_cv_no_strict_aliasing) + if test $ac_cv_no_strict_aliasing = yes then BASECFLAGS="$BASECFLAGS -fno-strict-aliasing" fi -- 2.40.0