From a4535d776ca12e4a5f6816e5e12bcc066e1ece4d Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Thu, 13 Dec 2018 16:59:21 -0700 Subject: [PATCH] test: Add undefined behaviour sanitizer to test_checks Change-Id: Id953cca99c6a6c64875185452e2ca6630cf47541 Signed-off-by: Roy Oursler --- tools/test_checks.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/test_checks.sh b/tools/test_checks.sh index 399f8c3..a5a0f45 100755 --- a/tools/test_checks.sh +++ b/tools/test_checks.sh @@ -43,6 +43,23 @@ if uname | grep -q 'Darwin' 2>&1; then fi # Build and run check tests +if [ -z "$CFLAGS" ]; then + CFLAGS='-g -O2 -fsanitize=undefined -fno-sanitize=nonnull-attribute -fsanitize-undefined-trap-on-error' + + if [ $CC ]; then + echo int main\(\)\{\}\; | $CC $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1 + elif ( command -V gcc > /dev/null ); then + echo int main\(\)\{\}\; | gcc $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1 + elif ( command -V clang > /dev/null ); then + echo int main\(\)\{\}\; | clang $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1 + fi + + if [ $sanitize ]; then + echo "Sanitizing undefined behaviour" + export CFLAGS=$CFLAGS + fi +fi + time ./autogen.sh time ./configure --prefix=$tmp_install_dir $opt_config_target time $MAKE -j $cpus