I'm running Address sanitizer on my unitests. Cmake looks something like this:
cmake -G"Unix Makefiles" \
-DCMAKE_CXX_COMPILER=clang++-9 \
-DCMAKE_C_COMPILER=clang-9 \
-DCMAKE_C_FLAGS='-fsanitize=address -fsanitize-address-use-after-scope' \
-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize-address-use-after-scope' \
The running command is
make clean
ASAN_OPTIONS=detect_stack_use_after_return=1 make a.out -j
ASAN_OPTIONS=detect_stack_use_after_return=1 LSAN_OPTIONS=verbosity=1 ./a.out
The unitests are written in gtest framework.
There is some unitest that by definition should make illegal access to out of array boundaries. And I want to know how I can suppress this test
TEST_F(classA, testA) {
some_struct a;
a.p = 100;
ASSERT_FALSE(&foo());
}
I saw here the option to suppress function but I don't know how to apply it on a unitest function https://github.com/google/sanitizers/wiki/AddressSanitizer
#if defined(__clang__) || defined (__GNUC__)
# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#else
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
#endif
...
ATTRIBUTE_NO_SANITIZE_ADDRESS
void ThisFunctionWillNotBeInstrumented() {...}