summaryrefslogtreecommitdiff
path: root/test/sanitizer_common
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2019-02-26 07:43:01 +0000
committerClement Courbet <courbet@google.com>2019-02-26 07:43:01 +0000
commitb9d79a0d9c8b36d590ab50544cf4389fd21ac281 (patch)
tree561ac56dd92bc69dca03acaae16c4c7b1fdae2bc /test/sanitizer_common
parent54f7bd8bcc2ab94f726deb980d90530674f08cc1 (diff)
downloadcompiler-rt-b9d79a0d9c8b36d590ab50544cf4389fd21ac281.tar.gz
[compiler-rt] Intercept the bcmp() function.
Summary: I have not introduced a separate hook for `bcmp()` as I don't think there should be any reason for a sanitizer to treat it differently from `memcmp()`. This is only enabled when building on POSIX with GNU extensions. Context: this is to avoid losing coverage when emitting `bcmp() == 0` instead of `memcmp() == 0` in llvm, see https://reviews.llvm.org/D56593. Reviewers: mgorny, krytarowski, vitalybuka, dvyukov Subscribers: kubamracek, dberris, delcypher, jdoerfert, #sanitizers, llvm-commits, jyknight Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58379 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354851 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/sanitizer_common')
-rw-r--r--test/sanitizer_common/TestCases/Posix/weak_hook_test.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
index 9176a524d..9439e5181 100644
--- a/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
+++ b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc
@@ -6,8 +6,11 @@
// XFAIL: lsan
// XFAIL: ubsan
-#include <string.h>
#include <assert.h>
+#include <string.h>
+#if defined(_GNU_SOURCE)
+#include <strings.h> // for bcmp
+#endif
bool seen_memcmp, seen_strncmp, seen_strncasecmp, seen_strcmp, seen_strcasecmp,
seen_strstr, seen_strcasestr, seen_memmem;
@@ -59,6 +62,13 @@ int main() {
int_sink = memcmp(s1, s2, sizeof(s2));
assert(seen_memcmp);
+#if defined(_GNU_SOURCE) || defined(__NetBSD__) || defined(__FreeBSD__) || \
+ defined(__OpenBSD__)
+ seen_memcmp = false;
+ int_sink = bcmp(s1, s2, sizeof(s2));
+ assert(seen_memcmp);
+#endif
+
int_sink = strncmp(s1, s2, sizeof(s2));
assert(seen_strncmp);