Linux: fix build after e78c5951 - ASAN support
[scilab.git] / scilab / m4 / compiler.m4
index 7eec777..2c2a09f 100644 (file)
@@ -82,6 +82,7 @@ AC_ARG_ENABLE(address-sanitizer,
     AS_HELP_STRING([--enable-address-sanitizer], [Enable AddressSanitizer instrumentation]))
 
 # Check if -fsanitize=address is supported at compile time and link time
+saved_CFLAGS="$CFLAGS"
 saved_LDFLAGS="$LDFLAGS"
 asan_supported=no
 
@@ -89,19 +90,14 @@ CFLAGS="$CFLAGS -fsanitize=address"
 LDFLAGS="$LDFLAGS -fsanitize=address"
 AC_MSG_CHECKING([whether the C compiler accepts -fsanitize=address])
 AC_LANG_PUSH(C)
-AC_RUN_IFELSE([AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]], [])], [AC_MSG_RESULT([yes]); asan_supported=yes], [AC_MSG_RESULT([no])])
+AC_RUN_IFELSE([AC_LANG_PROGRAM([[const char hw[] = "Hello, AddressSanitizer\n";]], [])], [AC_MSG_RESULT([yes]); asan_supported=yes], [AC_MSG_RESULT([no])])
 AC_LANG_POP(C)
 
+CFLAGS="$saved_CFLAGS"
 LDFLAGS="$saved_LDFLAGS"
-if test "x$asan_supported" == "xno" -a "x$enable_address_sanitizer" == "xyes";
-  then
+if test "x$asan_supported" == "xno" -a "x$enable_address_sanitizer" == "xyes"; then
     AC_MSG_ERROR([The $CC compiler does not support the options -fsanitize=address . Update your compiler and/or install the AddressSanitizer runtime library.])
-fi
-
-if test "x$asan_supported" == "xno";
-  then
-    echo "fsanitize=address not supported, AddressSanitizer disabled"
-  else
+elif test "x$enable_address_sanitizer" == "xyes"; then
     COMPILER_CFLAGS="$COMPILER_CFLAGS -fsanitize=address"
     COMPILER_CXXFLAGS="$COMPILER_CXXFLAGS -fsanitize=address"
     COMPILER_LDFLAGS="$COMPILER_LDFLAGS -fsanitize=address"