Add a testcase for ubsan
This commit is contained in:
1 parent
6ead0a46b3
commit
c9817eca35
3 files changed
+51
No files matched your search
@@ -100,6 +100,9 @@ RUN cd test && \
|
|||||||
for test in stacksmash; do \
|
for test in stacksmash; do \
|
||||||
$arch-w64-mingw32-clang $test.c -o $arch/$test-asan.exe -fsanitize=address -g -gcodeview -Wl,-pdb,$arch/$test-asan.pdb || exit 1; \
|
$arch-w64-mingw32-clang $test.c -o $arch/$test-asan.exe -fsanitize=address -g -gcodeview -Wl,-pdb,$arch/$test-asan.pdb || exit 1; \
|
||||||
done; \
|
done; \
|
||||||
|
for test in ubsan; do \
|
||||||
|
$arch-w64-mingw32-clang $test.c -o $arch/$test.exe -fsanitize=undefined || exit 1; \
|
||||||
|
done; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build libssp
|
# Build libssp
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ TESTS_CPP="hello-cpp hello-exception tlstest-main exception-locale"
|
|||||||
TESTS_CPP_DLL="tlstest-lib"
|
TESTS_CPP_DLL="tlstest-lib"
|
||||||
TESTS_SSP="stacksmash"
|
TESTS_SSP="stacksmash"
|
||||||
TESTS_ASAN="stacksmash"
|
TESTS_ASAN="stacksmash"
|
||||||
|
TESTS_UBSAN="ubsan"
|
||||||
for arch in $ARCHS; do
|
for arch in $ARCHS; do
|
||||||
mkdir -p $arch
|
mkdir -p $arch
|
||||||
for test in $TESTS_C; do
|
for test in $TESTS_C; do
|
||||||
@@ -54,6 +55,16 @@ for arch in $ARCHS; do
|
|||||||
esac
|
esac
|
||||||
$arch-w64-mingw32-clang $test.c -o $arch/$test-asan.exe -fsanitize=address -g -gcodeview -Wl,-pdb,$arch/$test-asan.pdb
|
$arch-w64-mingw32-clang $test.c -o $arch/$test-asan.exe -fsanitize=address -g -gcodeview -Wl,-pdb,$arch/$test-asan.pdb
|
||||||
done
|
done
|
||||||
|
for test in $TESTS_UBSAN; do
|
||||||
|
case $arch in
|
||||||
|
# Ubsan might not require anything too x86 specific, but we don't
|
||||||
|
# build any of the sanitizer libs for anything else than x86.
|
||||||
|
i686|x86_64) ;;
|
||||||
|
*) continue ;;
|
||||||
|
esac
|
||||||
|
$arch-w64-mingw32-clang $test.c -o $arch/$test.exe -fsanitize=undefined
|
||||||
|
TESTS_EXTRA="$TESTS_EXTRA $test"
|
||||||
|
done
|
||||||
DLL="$TESTS_C_DLL $TESTS_CPP_DLL"
|
DLL="$TESTS_C_DLL $TESTS_CPP_DLL"
|
||||||
case $arch in
|
case $arch in
|
||||||
i686|x86_64)
|
i686|x86_64)
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Martin Storsjo
|
||||||
|
*
|
||||||
|
* This file is part of llvm-mingw.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int32_t var = INT32_MAX;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
char buf[10];
|
||||||
|
if (argc > 1) {
|
||||||
|
fprintf(stderr, "triggering undefined behaviour\n");
|
||||||
|
fflush(stderr);
|
||||||
|
var++;
|
||||||
|
} else {
|
||||||
|
var--;
|
||||||
|
fprintf(stderr, "%s: A test tool for undefined behaviour sanitizer. \n"
|
||||||
|
"Run this with a command line argument to trigger "
|
||||||
|
"undefined behaviour.\n", argv[0]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user