commit 8059d63339b49d37af894f861956de4b89429bee parent 6ef99181273f6d8b3a3e08ce43ac3497ff71a0c0 Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Sun, 19 Nov 2023 11:41:26 +0100 Improved sanitizer detection Diffstat:
M | configure.sh | | | 10 | +++++++--- |
M | test/test.sh | | | 12 | ++++++------ |
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/configure.sh b/configure.sh @@ -1,8 +1,9 @@ #!/bin/sh -detect() { cc -march=native -dM -E - < /dev/null | grep "$1"; } +detectarch() { cc -march=native -dM -E - </dev/null | grep "$1"; } +detectsan() { cc -fsanitize=$1 -dM -E -x c - </dev/null | grep "SANITIZE"; } -[ -n "$(detect __AVX2__)" ] && detected="AVX2" +[ -n "$(detectarch __AVX2__)" ] && detected="AVX2" TYPE=${TYPE-"$detected"} @@ -11,7 +12,10 @@ echo "Using CUBE_$TYPE" STD="-std=c99" WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function" [ "$TYPE" = "AVX2" ] && AVX="-mavx2" -[ "$(uname)" = "Linux" ] && SAN="-fsanitize=address -fsanitize=undefined" + +[ -n "$(detectsan address)" ] && ADDR="-fsanitize=address" +[ -n "$(detectsan undefined)" ] && UNDEF="-fsanitize=undefined" +SAN="$ADDR $UNDEF" CFLAGS="$STD $WFLAGS $AVX -O3" DBGFLAGS="$STD $WFLAGS $AVX -g3 -DDEBUG" diff --git a/test/test.sh b/test/test.sh @@ -1,15 +1,15 @@ #!/bin/sh +detectsan() { cc -fsanitize=$1 -dM -E -x c - </dev/null | grep "SANITIZE"; } + re="${TEST:-$@}" CC="cc -DDEBUG -std=c99 -pedantic -Wall -Wextra \ -Wno-unused-parameter -Wno-unused-function -g3 -D$CUBETYPE" -if [ "$CUBETYPE" = "CUBE_AVX2" ]; then - CC="$CC -mavx2" -fi -if [ "$(uname)" != "OpenBSD" ]; then - CC="$CC -fsanitize=address -fsanitize=undefined" -fi + +[ "$CUBETYPE" = "CUBE_AVX2" ] && CC="$CC -mavx2" +[ -n "$(detectsan address)" ] && CC="$CC -fsanitize=address" +[ -n "$(detectsan undefined)" ] && CC="$CC -fsanitize=undefined" TESTBIN="test/run" TESTOUT="test/last.out"