[PATCH] D56465: hwasan: Ignore loads and stores of size 0.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 16:39:14 PST 2019


pcc created this revision.
pcc added a reviewer: eugenis.
Herald added a subscriber: kubamracek.

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 anyhere 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.


Repository:
  rL LLVM

https://reviews.llvm.org/D56465

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


Index: compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c
===================================================================
--- /dev/null
+++ compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c
@@ -0,0 +1,10 @@
+// RUN: %clang_hwasan %s -DTEST_NO=1 -o %t && %run %t
+
+#include <string.h>
+
+int main() {
+  char a[1];
+  memset(a, 0, 0);
+  memmove(a, a, 0);
+  memcpy(a, a, 0);
+}
Index: compiler-rt/lib/hwasan/hwasan_checks.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan_checks.h
+++ compiler-rt/lib/hwasan/hwasan_checks.h
@@ -61,7 +61,8 @@
 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56465.180768.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190109/13562653/attachment.bin>


More information about the llvm-commits mailing list