From a8001f03e1df8b0ed8ecad68c0c97b7ce4f54c42 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 27 Jul 2021 11:16:58 -0600 Subject: [PATCH] Added -fno-strict-aliasing to CFLAGS when the compiler supports it and autotools are in use. --- configure.ac | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/configure.ac b/configure.ac index 1283aa75a..12f721271 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,25 @@ AC_CANONICAL_TARGET AC_CONFIG_HEADERS([config.h]) + +## +# Check to see if the compiler supports -fno-strict-aliasing and, if so, +# add that to the C compiler flags. This is in support of https://github.com/Unidata/netcdf-c/issues/1983. +## +SAVE_CFLAGS="${CFLAGS}" +AC_LANG_PUSH([C]) +CFLAGS="${CFLAGS} -fno-strict-aliasing" + +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ + [int i = 0;]])], + [have_no_strict_aliasing=yes], + [have_no_strict_aliasing=no]) +AC_MSG_CHECKING([whether compiler supports -fno-strict-aliasing]) +AC_MSG_RESULT([$have_no_strict_aliasing]) +AC_LANG_POP([C]) +if test $have_no_strict_aliasing = no; then + CFLAGS=$SAVE_CFLAGS +fi ## # Some files need to exist in build directories # that do not correspond to their source directory, or