<div dir="ltr">I don't like this. We should not be *copying* such large tests. <div>Please revert and find another solution (= *move* the test and make it work on more platforms). </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 1, 2016 at 5:29 AM, Filipe Cabecinhas via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: filcab<br>
Date: Thu Sep  1 07:29:13 2016<br>
New Revision: 280361<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=280361&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=280361&view=rev</a><br>
Log:<br>
Copy over most of the scariness_score test to the general tests<br>
<br>
The abort() test wasn't copied over (original case 22). This is because<br>
it doesn't work on OS X.<br>
<br>
If theres no buildbot problem with this test later today, I will<br>
minimize the Linux version.<br>
<br>
Added:<br>
    compiler-rt/trunk/test/asan/<wbr>TestCases/scariness_score_<wbr>test.cc<br>
<br>
Added: compiler-rt/trunk/test/asan/<wbr>TestCases/scariness_score_<wbr>test.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/scariness_score_test.cc?rev=280361&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>test/asan/TestCases/scariness_<wbr>score_test.cc?rev=280361&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/test/asan/<wbr>TestCases/scariness_score_<wbr>test.cc (added)<br>
+++ compiler-rt/trunk/test/asan/<wbr>TestCases/scariness_score_<wbr>test.cc Thu Sep  1 07:29:13 2016<br>
@@ -0,0 +1,191 @@<br>
+// Test how we produce the scariness score.<br>
+<br>
+// RUN: %clangxx_asan -O0 %s -o %t<br>
+// On OSX and Windows, alloc_dealloc_mismatch=1 isn't 100% reliable, so it's<br>
+// off by default. It's safe for these tests, though, so we turn it on.<br>
+// RUN: export %env_asan_opts=detect_stack_<wbr>use_after_return=1:handle_<wbr>abort=1:print_scariness=1:<wbr>alloc_dealloc_mismatch=1<br>
+// Make sure the stack is limited (may not be the default under GNU make)<br>
+// RUN: ulimit -s 4096<br>
+// RUN: not %run %t  1 2>&1 | FileCheck %s --check-prefix=CHECK1<br>
+// RUN: not %run %t  2 2>&1 | FileCheck %s --check-prefix=CHECK2<br>
+// RUN: not %run %t  3 2>&1 | FileCheck %s --check-prefix=CHECK3<br>
+// RUN: not %run %t  4 2>&1 | FileCheck %s --check-prefix=CHECK4<br>
+// RUN: not %run %t  5 2>&1 | FileCheck %s --check-prefix=CHECK5<br>
+// RUN: not %run %t  6 2>&1 | FileCheck %s --check-prefix=CHECK6<br>
+// RUN: not %run %t  7 2>&1 | FileCheck %s --check-prefix=CHECK7<br>
+// RUN: not %run %t  8 2>&1 | FileCheck %s --check-prefix=CHECK8<br>
+// RUN: not %run %t  9 2>&1 | FileCheck %s --check-prefix=CHECK9<br>
+// RUN: not %run %t 10 2>&1 | FileCheck %s --check-prefix=CHECK10<br>
+// RUN: not %run %t 11 2>&1 | FileCheck %s --check-prefix=CHECK11<br>
+// RUN: not %run %t 12 2>&1 | FileCheck %s --check-prefix=CHECK12<br>
+// RUN: not %run %t 13 2>&1 | FileCheck %s --check-prefix=CHECK13<br>
+// RUN: not %run %t 14 2>&1 | FileCheck %s --check-prefix=CHECK14<br>
+// RUN: not %run %t 15 2>&1 | FileCheck %s --check-prefix=CHECK15<br>
+// RUN: not %run %t 16 2>&1 | FileCheck %s --check-prefix=CHECK16<br>
+// RUN: not %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK17<br>
+// RUN: not %run %t 18 2>&1 | FileCheck %s --check-prefix=CHECK18<br>
+// RUN: not %run %t 19 2>&1 | FileCheck %s --check-prefix=CHECK19<br>
+// RUN: not %run %t 20 2>&1 | FileCheck %s --check-prefix=CHECK20<br>
+// RUN: not %run %t 21 2>&1 | FileCheck %s --check-prefix=CHECK21<br>
+// RUN: not %run %t 22 2>&1 | FileCheck %s --check-prefix=CHECK22<br>
+// RUN: not %run %t 23 2>&1 | FileCheck %s --check-prefix=CHECK23<br>
+// RUN: not %run %t 24 2>&1 | FileCheck %s --check-prefix=CHECK24<br>
+// RUN: not %run %t 25 2>&1 | FileCheck %s --check-prefix=CHECK25<br>
+// RUN: not %run %t 26 2>&1 | FileCheck %s --check-prefix=CHECK26<br>
+// Parts of the test are too platform-specific:<br>
+// REQUIRES: x86_64-target-arch<br>
+// REQUIRES: shell<br>
+#include <stdlib.h><br>
+#include <stdio.h><br>
+#include <string.h><br>
+<br>
+#include <sanitizer/asan_interface.h><br>
+<br>
+enum ReadOrWrite { Read = 0, Write = 1 };<br>
+<br>
+struct S32 {<br>
+  char x[32];<br>
+};<br>
+<br>
+template<class T><br>
+void HeapBuferOverflow(int Idx, ReadOrWrite w) {<br>
+  T *t = new T[100];<br>
+  static T sink;<br>
+  if (w)<br>
+    t[100 + Idx] = T();<br>
+  else<br>
+    sink = t[100 + Idx];<br>
+  delete [] t;<br>
+}<br>
+<br>
+template<class T><br>
+void HeapUseAfterFree(int Idx, ReadOrWrite w) {<br>
+  T *t = new T[100];<br>
+  static T sink;<br>
+  sink = t[0];<br>
+  delete [] t;<br>
+  if (w)<br>
+    t[Idx] = T();<br>
+  else<br>
+    sink = t[Idx];<br>
+}<br>
+<br>
+template<class T><br>
+void StackBufferOverflow(int Idx, ReadOrWrite w) {<br>
+  T t[100];<br>
+  static T sink;<br>
+  sink = t[Idx];<br>
+  if (w)<br>
+    t[100 + Idx] = T();<br>
+  else<br>
+    sink = t[100 + Idx];<br>
+}<br>
+<br>
+template<class T><br>
+T *LeakStack() {<br>
+  T t[100];<br>
+  static volatile T *x;<br>
+  x = &t[0];<br>
+  return (T*)x;<br>
+}<br>
+<br>
+template<class T><br>
+void StackUseAfterReturn(int Idx, ReadOrWrite w) {<br>
+  static T sink;<br>
+  T *t = LeakStack<T>();<br>
+  if (w)<br>
+    t[100 + Idx] = T();<br>
+  else<br>
+    sink = t[100 + Idx];<br>
+}<br>
+<br>
+char    g1[100];<br>
+short   g2[100];<br>
+int     g4[100];<br>
+int64_t g8[100];<br>
+S32     gm[100];<br>
+<br>
+void DoubleFree() {<br>
+  int *x = new int;<br>
+  static volatile int two = 2;<br>
+  for (int i = 0; i < two; i++)<br>
+    delete x;<br>
+}<br>
+<br>
+void StackOverflow(int Idx) {<br>
+  int some_stack[10000];<br>
+  static volatile int *x;<br>
+  x = &some_stack[0];<br>
+  if (Idx > 0)<br>
+    StackOverflow(Idx - 1);<br>
+}<br>
+<br>
+void UseAfterPoison() {<br>
+  int buf[100];<br>
+  __asan_poison_memory_region(<wbr>buf, sizeof(buf));<br>
+  static volatile int sink;<br>
+  sink = buf[42];<br>
+}<br>
+<br>
+int main(int argc, char **argv) {<br>
+  char arr[100];<br>
+  static volatile int zero = 0;<br>
+  static volatile int *zero_ptr = 0;<br>
+  static volatile int *wild_addr = (int*)0x10000000; // System-dependent.<br>
+  if (argc != 2) return 1;<br>
+  int kind = atoi(argv[1]);<br>
+  switch (kind) {<br>
+    case 1: HeapBuferOverflow<char>(0, Read); break;<br>
+    case 2: HeapBuferOverflow<int>(0, Read); break;<br>
+    case 3: HeapBuferOverflow<short>(0, Write); break;<br>
+    case 4: HeapBuferOverflow<int64_t>(2, Write); break;<br>
+    case 5: HeapBuferOverflow<S32>(4, Write); break;<br>
+    case 6: HeapUseAfterFree<char>(0, Read); break;<br>
+    case 7: HeapUseAfterFree<int>(0, Write); break;<br>
+    case 8: HeapUseAfterFree<int64_t>(0, Read); break;<br>
+    case 9: HeapUseAfterFree<S32>(0, Write); break;<br>
+    case 10: StackBufferOverflow<char>(0, Write); break;<br>
+    case 11: StackBufferOverflow<int64_t>(<wbr>0, Read); break;<br>
+    case 12: StackBufferOverflow<int>(4, Write); break;<br>
+    case 13: StackUseAfterReturn<char>(0, Read); break;<br>
+    case 14: StackUseAfterReturn<S32>(0, Write); break;<br>
+    case 15: g1[zero + 100] = 0; break;<br>
+    case 16: gm[0] = gm[zero + 100 + 1]; break;<br>
+    case 17: DoubleFree(); break;<br>
+    case 18: StackOverflow(1000000); break;<br>
+    case 19: *zero_ptr = 0; break;<br>
+    case 20: *wild_addr = 0; break;<br>
+    case 21: zero = *wild_addr; break;<br>
+    case 22: ((void (*)(void))wild_addr)(); break;<br>
+    case 23: delete (new int[10]); break;<br>
+    case 24: free((char*)malloc(100) + 10); break;<br>
+    case 25: memcpy(arr, arr+10, 20);  break;<br>
+    case 26: UseAfterPoison(); break;<br>
+    // CHECK1: SCARINESS: 12 (1-byte-read-heap-buffer-<wbr>overflow)<br>
+    // CHECK2: SCARINESS: 17 (4-byte-read-heap-buffer-<wbr>overflow)<br>
+    // CHECK3: SCARINESS: 33 (2-byte-write-heap-buffer-<wbr>overflow)<br>
+    // CHECK4: SCARINESS: 52 (8-byte-write-heap-buffer-<wbr>overflow-far-from-bounds)<br>
+    // CHECK5: SCARINESS: 55 (multi-byte-write-heap-buffer-<wbr>overflow-far-from-bounds)<br>
+    // CHECK6: SCARINESS: 40 (1-byte-read-heap-use-after-<wbr>free)<br>
+    // CHECK7: SCARINESS: 46 (4-byte-write-heap-use-after-<wbr>free)<br>
+    // CHECK8: SCARINESS: 51 (8-byte-read-heap-use-after-<wbr>free)<br>
+    // CHECK9: SCARINESS: 55 (multi-byte-write-heap-use-<wbr>after-free)<br>
+    // CHECK10: SCARINESS: 46 (1-byte-write-stack-buffer-<wbr>overflow)<br>
+    // CHECK11: SCARINESS: 38 (8-byte-read-stack-buffer-<wbr>overflow)<br>
+    // CHECK12: SCARINESS: 61 (4-byte-write-stack-buffer-<wbr>overflow-far-from-bounds)<br>
+    // CHECK13: SCARINESS: 50 (1-byte-read-stack-use-after-<wbr>return)<br>
+    // CHECK14: SCARINESS: 65 (multi-byte-write-stack-use-<wbr>after-return)<br>
+    // CHECK15: SCARINESS: 31 (1-byte-write-global-buffer-<wbr>overflow)<br>
+    // CHECK16: SCARINESS: 36 (multi-byte-read-global-<wbr>buffer-overflow-far-from-<wbr>bounds)<br>
+    // CHECK17: SCARINESS: 42 (double-free)<br>
+    // CHECK18: SCARINESS: 10 (stack-overflow)<br>
+    // CHECK19: SCARINESS: 10 (null-deref)<br>
+    // CHECK20: SCARINESS: 30 (wild-addr-write)<br>
+    // CHECK21: SCARINESS: 20 (wild-addr-read)<br>
+    // CHECK22: SCARINESS: 60 (wild-jump)<br>
+    // CHECK23: SCARINESS: 10 (alloc-dealloc-mismatch)<br>
+    // CHECK24: SCARINESS: 40 (bad-free)<br>
+    // CHECK25: SCARINESS: 10 (memcpy-param-overlap)<br>
+    // CHECK26: SCARINESS: 27 (4-byte-read-use-after-poison)<br>
+  }<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>