[compiler-rt] r350683 - hwasan: Ignore loads and stores of size 0.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 16:44:13 PST 2019


Author: pcc
Date: Tue Jan  8 16:44:13 2019
New Revision: 350683

URL: http://llvm.org/viewvc/llvm-project?rev=350683&view=rev
Log:
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

Added:
    compiler-rt/trunk/test/hwasan/TestCases/mem-intrinsics-zero-size.c
Modified:
    compiler-rt/trunk/lib/hwasan/hwasan_checks.h

Modified: compiler-rt/trunk/lib/hwasan/hwasan_checks.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_checks.h?rev=350683&r1=350682&r2=350683&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_checks.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_checks.h Tue Jan  8 16:44:13 2019
@@ -61,7 +61,8 @@ __attribute__((always_inline, nodebug))
 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);

Added: compiler-rt/trunk/test/hwasan/TestCases/mem-intrinsics-zero-size.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/hwasan/TestCases/mem-intrinsics-zero-size.c?rev=350683&view=auto
==============================================================================
--- compiler-rt/trunk/test/hwasan/TestCases/mem-intrinsics-zero-size.c (added)
+++ compiler-rt/trunk/test/hwasan/TestCases/mem-intrinsics-zero-size.c Tue Jan  8 16:44:13 2019
@@ -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);
+}




More information about the llvm-commits mailing list