[compiler-rt] r301837 - [asan] speed up small memcpy (> 32 but <= 64 bytes)

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 14:05:29 PDT 2017


Author: kcc
Date: Mon May  1 16:05:29 2017
New Revision: 301837

URL: http://llvm.org/viewvc/llvm-project?rev=301837&view=rev
Log:
[asan] speed up small memcpy (> 32 but <= 64 bytes)

Added:
    compiler-rt/trunk/test/asan/TestCases/small_memcpy_test.cc
Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=301837&r1=301836&r2=301837&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon May  1 16:05:29 2017
@@ -37,12 +37,19 @@
 namespace __asan {
 
 // Return true if we can quickly decide that the region is unpoisoned.
+// We assume that a redzone is at least 16 bytes.
 static inline bool QuickCheckForUnpoisonedRegion(uptr beg, uptr size) {
   if (size == 0) return true;
   if (size <= 32)
     return !AddressIsPoisoned(beg) &&
            !AddressIsPoisoned(beg + size - 1) &&
            !AddressIsPoisoned(beg + size / 2);
+  if (size <= 64)
+    return !AddressIsPoisoned(beg) &&
+           !AddressIsPoisoned(beg + size / 4) &&
+           !AddressIsPoisoned(beg + size - 1) &&
+           !AddressIsPoisoned(beg + 3 * size / 4) &&
+           !AddressIsPoisoned(beg + size / 2);
   return false;
 }
 

Added: compiler-rt/trunk/test/asan/TestCases/small_memcpy_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/small_memcpy_test.cc?rev=301837&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/small_memcpy_test.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/small_memcpy_test.cc Mon May  1 16:05:29 2017
@@ -0,0 +1,28 @@
+// Test that small memcpy works correctly.
+
+// RUN: %clangxx_asan %s -o %t
+// RUN: not %run %t 8 24 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: not %run %t 16 32 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: not %run %t 24 40 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: not %run %t 32 48 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: not %run %t 40 56 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: not %run %t 48 64 2>&1 | FileCheck %s --check-prefix=CHECK
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <sanitizer/asan_interface.h>
+
+int main(int argc, char **argv) {
+  assert(argc == 3);
+  size_t poison_from = atoi(argv[1]);
+  size_t poison_to = atoi(argv[2]);
+  assert(poison_from <= poison_to);
+  char A1[64], A2[64];
+  fprintf(stderr, "%zd %zd\n", poison_from, poison_to - poison_from);
+  __asan_poison_memory_region(&A1[0] + poison_from, poison_to - poison_from);
+  memcpy(A1, A2, sizeof(A1));
+// CHECK: AddressSanitizer: use-after-poison
+  return 0;
+}




More information about the llvm-commits mailing list