Skip to content

Commit

Permalink
Do not turn off strict-aliasing optimizations
Browse files Browse the repository at this point in the history
Issue #322 (bdwgc).

* CMakeLists.txt (HAVE_FLAG_F_NO_STRICT_ALIASING): Remove.
* CMakeLists.txt [HAVE_FLAG_F_NO_STRICT_ALIASING]
(add_compile_options): Do not add -fno-strict-aliasing.
* build.zig (build): Do not add "-fno-strict-aliasing" to flags; update
comment.
* configure.ac [$GCC=yes] (ac_cv_fno_strict_aliasing): Do not define.
* configure.ac [$GCC=yes]: Do not check if -fno-strict-aliasing is
supported.
* configure.ac [$GCC=yes && $ac_cv_fno_strict_aliasing=yes] (CFLAGS):
Do not append -fno-strict-aliasing.
* docs/platforms/README.win64: Do not mention -fno-strict-aliasing.
* extra/gc.c: Remove -fno-strict-aliasing from comment.
  • Loading branch information
ivmai committed Oct 22, 2024
1 parent 6e8ccad commit 99463af
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 37 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,6 @@ else()
endif(WIN32)
endif()

# Disable strict aliasing optimizations.
# It could re-enabled back by a flag passed in CFLAGS_EXTRA.
check_c_compiler_flag(-fno-strict-aliasing HAVE_FLAG_F_NO_STRICT_ALIASING)
if (HAVE_FLAG_F_NO_STRICT_ALIASING)
add_compile_options(-fno-strict-aliasing)
endif()

# Extra user-defined flags to pass both to C and C++ compilers.
if (DEFINED CFLAGS_EXTRA)
separate_arguments(CFLAGS_EXTRA_LIST UNIX_COMMAND "${CFLAGS_EXTRA}")
Expand Down
3 changes: 1 addition & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,11 @@ pub fn build(b: *std.Build) void {
// TODO: declare that the libraries do not refer to external symbols
// of build_shared_libs.

// zig cc supports these flags.
// zig cc supports this flag.
flags.appendSlice(&.{
// TODO: -Wno-unused-command-line-argument
// Prevent "__builtin_return_address with nonzero argument is unsafe".
"-Wno-frame-address",
"-fno-strict-aliasing",
}) catch unreachable;

if (build_shared_libs) {
Expand Down
25 changes: 0 additions & 25 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -432,31 +432,6 @@ fi
AM_CONDITIONAL([ASM_WITH_CPP_UNSUPPORTED],
[test $compiler_xlc = yes -o $compiler_suncc = yes])

if test "$GCC" = yes; then
# Disable aliasing optimization unless forced to.
AC_MSG_CHECKING([whether compiler supports -fno-strict-aliasing])
ac_cv_fno_strict_aliasing=no
for cflag in $CFLAGS; do
case "$cflag" in
-fstrict-aliasing)
# Opposite option already present
ac_cv_fno_strict_aliasing=skipped
break
;;
esac
done
if test "$ac_cv_fno_strict_aliasing" != skipped; then
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fno-strict-aliasing"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
[ac_cv_fno_strict_aliasing=yes])
CFLAGS="$old_CFLAGS"
AS_IF([test "$ac_cv_fno_strict_aliasing" = yes],
[CFLAGS="$CFLAGS -fno-strict-aliasing"])
fi
AC_MSG_RESULT($ac_cv_fno_strict_aliasing)
fi

# Check for getcontext (uClibc can be configured without it, for example)
AC_CHECK_FUNC([getcontext], [],
[AC_DEFINE([NO_GETCONTEXT], [1], [Missing getcontext function.])])
Expand Down
2 changes: 0 additions & 2 deletions docs/platforms/README.win64
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ support - this could be done by passing "disable_threads=1" argument to nmake.
Note that some warnings have been explicitly turned off in the makefile.

VC++ note: to suppress warnings -D_CRT_SECURE_NO_DEPRECATE is used.

gcc note: -fno-strict-aliasing should be used if optimizing.
2 changes: 1 addition & 1 deletion extra/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* Tip: to get the highest level of compiler optimizations, the typical */
/* compiler options (GCC) to use are: */
/* -O3 -fno-strict-aliasing -march=native -Wall -fprofile-generate/use */
/* -O3 -march=native -Wall -fprofile-generate/use */

/* Warning: GCC for Linux (for C++ clients only): Use -fexceptions both */
/* for GC and the client otherwise GC_thread_exit_proc() is not */
Expand Down

0 comments on commit 99463af

Please sign in to comment.