-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathacsm_test_sanitize_flags.m4
69 lines (65 loc) · 2.11 KB
/
acsm_test_sanitize_flags.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# AutoConf-SubModule macro ACSM_TEST_SANITIZE_FLAGS
#
# Test that a simple test program can be compiled with the sanitizer
# options.
#
# So far, the sanitizer options have worked with all the GCC 4.8
# installations I've tried, but not all versions of clang are created
# equal. For example, Apple's Mavericks/Yosemite clang compiler
# reports:
#
# $ /usr/bin/clang++ --version
# Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
#
# i.e. LLVM 3.5, but it does not support address sanitizer.
# On the other hand, if you build clang from source with the
# address sanitizer enabled, you get:
#
# $ clang++ --version
# clang version 3.5.0 (tags/RELEASE_350/final 219211)
#
# so there is no way to tell if it supports address
# sanitizer just from the version info.
AC_DEFUN([ACSM_TEST_SANITIZE_FLAGS],
[
# Save current lang and CXXFLAGS values
AC_LANG_PUSH([C++])
saveCXXFLAGS="$CXXFLAGS"
# Set CXXFLAGS to be used for the test compilation. Note:
# we don't test these flags in conjunction with any
# others... that doesn't seem to be necessary yet.
CXXFLAGS="$1"
# Tell the user what we are doing
AC_MSG_CHECKING([if compiler has support for address sanitizer])
# Try compiling and running a simple main program with
# sanitizer flags. Since address sanitizer requires
# library-level support, we want to be sure that a compiled
# executable can run, not just that the compiler accepts the
# sanitizer flags. This program does not actually have a
# memory error, otherwise configure would consider the test
# to have failed...
AC_RUN_IFELSE([AC_LANG_PROGRAM(
[],
[[
int *array = new int[100];
delete [] array;
]])],
[
# Result if program succeeds
have_address_sanitizer=yes
AC_MSG_RESULT(yes)
],
[
# Result if program fails
have_address_sanitizer=no
AC_MSG_RESULT(no)
],
[
# Result if cross-compiling
have_address_sanitizer=no
AC_MSG_RESULT(no)
])
# Restore the original lang and flags
CXXFLAGS="$saveCXXFLAGS"
AC_LANG_POP([C++])
])