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

llvm-svn: 350683
This commit is contained in:
Peter Collingbourne 2019-01-09 00:44:13 +00:00
parent 243d0415c6
commit fdef020d80
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -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);
}