diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2019-01-09 00:44:13 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-01-09 00:44:13 +0000 |
commit | b53518b4870d430a41f4b37cc076c7eb090982da (patch) | |
tree | 42e6e3be40d97e37260496e75fc26af0eda2135d | |
parent | eb52eec5f49e5020dee345a7165eb9c87f94a11b (diff) | |
download | compiler-rt-b53518b4870d430a41f4b37cc076c7eb090982da.tar.gz |
hwasan: Ignore loads and stores of size 0.
Now that memory intrinsics are instrumented, it's more likely that
CheckAddressSized will be called with size 0. (It was possible before
with IR like:
%val = load [0 x i8], [0 x i8]* %ptr
but I don't think clang will generate IR like that and the optimizer
would normally remove it by the time it got anywhere near our pass
anyway). The right thing to do in both cases is to disable the
addressing checks (since the underlying memory intrinsic is a no-op),
so that's what we do.
Differential Revision: https://reviews.llvm.org/D56465
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@350683 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/hwasan/hwasan_checks.h | 3 | ||||
-rw-r--r-- | test/hwasan/TestCases/mem-intrinsics-zero-size.c | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/hwasan/hwasan_checks.h b/lib/hwasan/hwasan_checks.h index 39321a28b..688b5e2be 100644 --- a/lib/hwasan/hwasan_checks.h +++ b/lib/hwasan/hwasan_checks.h @@ -61,7 +61,8 @@ __attribute__((always_inline, nodebug)) static void CheckAddress(uptr p) { template <ErrorAction EA, AccessType AT> __attribute__((always_inline, nodebug)) static void CheckAddressSized(uptr p, uptr sz) { - CHECK_NE(0, sz); + if (sz == 0) + return; tag_t ptr_tag = GetTagFromPointer(p); uptr ptr_raw = p & ~kAddressTagMask; tag_t *shadow_first = (tag_t *)MemToShadow(ptr_raw); diff --git a/test/hwasan/TestCases/mem-intrinsics-zero-size.c b/test/hwasan/TestCases/mem-intrinsics-zero-size.c new file mode 100644 index 000000000..bcb8e0771 --- /dev/null +++ b/test/hwasan/TestCases/mem-intrinsics-zero-size.c @@ -0,0 +1,10 @@ +// RUN: %clang_hwasan %s -o %t && %run %t + +#include <string.h> + +int main() { + char a[1]; + memset(a, 0, 0); + memmove(a, a, 0); + memcpy(a, a, 0); +} |