[llvm-commits] [compiler-rt] r161935 - in /compiler-rt/trunk/lib/asan/lit_tests: global-overflow.cc heap-overflow.cc large_func_test.cc lit.cfg memcmp_test.cc null_deref.cc sanity_check_pure_c.c sleep_before_dying.c stack-overflow.cc stack-use-af

Kostya Serebryany kcc at google.com
Wed Aug 15 02:16:37 PDT 2012


On Wed, Aug 15, 2012 at 12:29 PM, Alexey Samsonov <samsonov at google.com>wrote:

> Author: samsonov
> Date: Wed Aug 15 03:29:17 2012
> New Revision: 161935
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161935&view=rev
> Log:
> [ASan] port remaining output and feature tests to lit. TODO: we should in
> fact run most of the tests for 32/64 bits and for all optimization levels
>
yes, please!

>
> Added:
>     compiler-rt/trunk/lib/asan/lit_tests/global-overflow.cc
>     compiler-rt/trunk/lib/asan/lit_tests/heap-overflow.cc
>     compiler-rt/trunk/lib/asan/lit_tests/large_func_test.cc
>     compiler-rt/trunk/lib/asan/lit_tests/memcmp_test.cc
>     compiler-rt/trunk/lib/asan/lit_tests/null_deref.cc
>     compiler-rt/trunk/lib/asan/lit_tests/sanity_check_pure_c.c
>     compiler-rt/trunk/lib/asan/lit_tests/sleep_before_dying.c
>     compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc
>     compiler-rt/trunk/lib/asan/lit_tests/stack-use-after-return.cc
>     compiler-rt/trunk/lib/asan/lit_tests/strip_path_prefix.c
>     compiler-rt/trunk/lib/asan/lit_tests/strncpy-overflow.cc
>     compiler-rt/trunk/lib/asan/lit_tests/use-after-free.cc
> Modified:
>     compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/global-overflow.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/global-overflow.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/global-overflow.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/global-overflow.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,19 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | FileCheck %s
> +
> +#include <string.h>
> +int main(int argc, char **argv) {
> +  static char XXX[10];
> +  static char YYY[10];
> +  static char ZZZ[10];
> +  memset(XXX, 0, 10);
> +  memset(YYY, 0, 10);
> +  memset(ZZZ, 0, 10);
> +  int res = YYY[argc * 10];  // BOOOM
> +  // CHECK: {{READ of size 1 at 0x.* thread T0}}
> +  // CHECK: {{    #0 0x.* in main .*global-overflow.cc:12}}
> +  // CHECK: {{0x.* is located 0 bytes to the right of global variable}}
> +  // CHECK:   {{.*YYY.* of size 10}}
> +  res += XXX[argc] + ZZZ[argc];
> +  return res;
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/heap-overflow.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/heap-overflow.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/heap-overflow.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/heap-overflow.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,26 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer > %t.output
> +// RUN: FileCheck %s < %t.output
> +// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
> +
> +#include <stdlib.h>
> +#include <string.h>
> +int main(int argc, char **argv) {
> +  char *x = (char*)malloc(10 * sizeof(char));
> +  memset(x, 0, 10);
> +  int res = x[argc * 10];  // BOOOM
> +  // CHECK: {{READ of size 1 at 0x.* thread T0}}
> +  // CHECK: {{    #0 0x.* in main .*heap-overflow.cc:11}}
> +  // CHECK: {{0x.* is located 0 bytes to the right of 10-byte region}}
> +  // CHECK: {{allocated by thread T0 here:}}
> +
> +  // CHECK-Linux: {{    #0 0x.* in .*malloc}}
> +  // CHECK-Linux: {{    #1 0x.* in main .*heap-overflow.cc:9}}
> +
> +  // CHECK-Darwin: {{    #0 0x.* in .*mz_malloc.*}}
> +  // CHECK-Darwin: {{    #1 0x.* in malloc_zone_malloc.*}}
> +  // CHECK-Darwin: {{    #2 0x.* in malloc.*}}
> +  // CHECK-Darwin: {{    #3 0x.* in main heap-overflow.cc:9}}
> +  free(x);
> +  return res;
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/large_func_test.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/large_func_test.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/large_func_test.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/large_func_test.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,53 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt > %t.output
> +// RUN: FileCheck %s < %t.output
> +// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
> +
> +#include <stdlib.h>
> +__attribute__((noinline))
> +static void LargeFunction(int *x, int zero) {
> +  x[0]++;
> +  x[1]++;
> +  x[2]++;
> +  x[3]++;
> +  x[4]++;
> +  x[5]++;
> +  x[6]++;
> +  x[7]++;
> +  x[8]++;
> +  x[9]++;
> +
> +  x[zero + 111]++;  // we should report this exact line
> +
> +  x[10]++;
> +  x[11]++;
> +  x[12]++;
> +  x[13]++;
> +  x[14]++;
> +  x[15]++;
> +  x[16]++;
> +  x[17]++;
> +  x[18]++;
> +  x[19]++;
> +}
> +
> +int main(int argc, char **argv) {
> +  int *x = new int[100];
> +  LargeFunction(x, argc - 1);
> +  delete x;
> +}
> +
> +// CHECK: {{.*ERROR: AddressSanitizer heap-buffer-overflow on address}}
> +// CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
> +// CHECK: {{READ of size 4 at 0x.* thread T0}}
> +
> +// atos incorrectly extracts the symbol name for the static functions on
> +// Darwin.
> +// CHECK-Linux:  {{    #0 0x.* in LargeFunction.*large_func_test.cc:20}}
> +// CHECK-Darwin: {{    #0 0x.* in .*LargeFunction.*large_func_test.cc:20}}
> +
> +// CHECK: {{    #1 0x.* in main .*large_func_test.cc:36}}
> +// CHECK: {{0x.* is located 44 bytes to the right of 400-byte region}}
> +// CHECK: {{allocated by thread T0 here:}}
> +// CHECK: {{    #0 0x.* in operator new.*}}
> +// CHECK: {{    #1 0x.* in main .*large_func_test.cc:35}}
>
> Modified: compiler-rt/trunk/lib/asan/lit_tests/lit.cfg
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/lit.cfg?rev=161935&r1=161934&r2=161935&view=diff
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/lit.cfg (original)
> +++ compiler-rt/trunk/lib/asan/lit_tests/lit.cfg Wed Aug 15 03:29:17 2012
> @@ -42,5 +42,12 @@
>    lit.fatal("Can't find symbolizer script on path %r" % symbolizer)
>  config.substitutions.append( ('%symbolizer', (" " + symbolizer + " " )))
>
> +# Define CHECK-%os to check for OS-dependent output.
> +config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
> +
>  # Default test suffixes.
>  config.suffixes = ['.c', '.cc', '.cpp']
> +
> +# AddressSanitizer tests are currently supported on Linux and Darwin only.
> +if config.host_os not in ['Linux', 'Darwin']:
> +  config.unsupported = True
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/memcmp_test.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/memcmp_test.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/memcmp_test.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/memcmp_test.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,13 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt | FileCheck %s
> +
> +#include <string.h>
> +int main(int argc, char **argv) {
> +  char a1[] = {argc, 2, 3, 4};
> +  char a2[] = {1, 2*argc, 3, 4};
> +  int res = memcmp(a1, a2, 4 + argc);  // BOOM
> +  // CHECK: AddressSanitizer stack-buffer-overflow
> +  // CHECK: {{#0.*memcmp}}
> +  // CHECK: {{#1.*main}}
> +  return res;
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/null_deref.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/null_deref.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/null_deref.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/null_deref.cc Wed Aug 15 03:29:17
> 2012
> @@ -0,0 +1,22 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt > %t.output
> +// RUN: FileCheck %s < %t.output
> +// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
> +
> +__attribute__((noinline))
> +static void NullDeref(int *ptr) {
> +  ptr[10]++;
> +}
> +int main() {
> +  NullDeref((int*)0);
> +}
> +
> +// CHECK: {{.*ERROR: AddressSanitizer crashed on unknown address}}
> +// CHECK:   {{0x0*00028 .*pc 0x.*}}
> +// CHECK: {{AddressSanitizer can not provide additional info.}}
> +
> +// atos on Mac cannot extract the symbol name correctly.
> +// CHECK-Linux: {{    #0 0x.* in NullDeref.*null_deref.cc:8}}
> +// CHECK-Darwin: {{    #0 0x.* in .*NullDeref.*null_deref.cc:8}}
> +
> +// CHECK: {{    #1 0x.* in main.*null_deref.cc:11}}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/sanity_check_pure_c.c
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/sanity_check_pure_c.c?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/sanity_check_pure_c.c (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/sanity_check_pure_c.c Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,15 @@
> +// Sanity checking a test in pure C.
> +// RUN: %clang -g -faddress-sanitizer -O2 %s -o %t
> +// RUN: %t 2>&1 | FileCheck %s
> +
> +// Sanity checking a test in pure C with -pie.
> +// RUN: %clang -g -faddress-sanitizer -O2 %s -pie -o %t
> +// RUN: %t 2>&1 | FileCheck %s
> +
> +#include <stdlib.h>
> +int main() {
> +  char *x = (char*)malloc(10 * sizeof(char));
> +  free(x);
> +  return x[5];
> +  // CHECK: heap-use-after-free
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/sleep_before_dying.c
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/sleep_before_dying.c?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/sleep_before_dying.c (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/sleep_before_dying.c Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,10 @@
> +// RUN: %clang -g -faddress-sanitizer -O2 %s -o %t
> +// RUN: ASAN_OPTIONS="sleep_before_dying=1" %t 2>&1 | FileCheck %s
> +
> +#include <stdlib.h>
> +int main() {
> +  char *x = (char*)malloc(10 * sizeof(char));
> +  free(x);
> +  return x[5];
> +  // CHECK: Sleeping for 1 second
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,13 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | FileCheck %s
> +
> +#include <string.h>
> +int main(int argc, char **argv) {
> +  char x[10];
> +  memset(x, 0, 10);
> +  int res = x[argc * 10];  // BOOOM
> +  // CHECK: {{READ of size 1 at 0x.* thread T0}}
> +  // CHECK: {{    #0 0x.* in main .*stack-overflow.cc:8}}
> +  // CHECK: {{Address 0x.* is .* frame <main>}}
> +  return res;
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/stack-use-after-return.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/stack-use-after-return.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/stack-use-after-return.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/stack-use-after-return.cc Wed Aug
> 15 03:29:17 2012
> @@ -0,0 +1,31 @@
> +// XFAIL: *
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt | FileCheck %s
> +
> +#include <stdio.h>
> +
> +__attribute__((noinline))
> +char *Ident(char *x) {
> +  fprintf(stderr, "1: %p\n", x);
> +  return x;
> +}
> +
> +__attribute__((noinline))
> +char *Func1() {
> +  char local;
> +  return Ident(&local);
> +}
> +
> +__attribute__((noinline))
> +void Func2(char *x) {
> +  fprintf(stderr, "2: %p\n", x);
> +  *x = 1;
> +  // CHECK: {{WRITE of size 1 .* thread T0}}
> +  // CHECK: {{    #0.*Func2.*stack-use-after-return.cc:18}}
> +  // CHECK: {{is located in frame <.*Func1.*> of T0's stack}}
> +}
> +
> +int main(int argc, char **argv) {
> +  Func2(Func1());
> +  return 0;
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/strip_path_prefix.c
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/strip_path_prefix.c?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/strip_path_prefix.c (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/strip_path_prefix.c Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,12 @@
> +// RUN: %clang -g -faddress-sanitizer -O2 %s -o %t
> +// RUN: ASAN_OPTIONS="strip_path_prefix='/'" %t 2>&1 | FileCheck %s
> +
> +#include <stdlib.h>
> +int main() {
> +  char *x = (char*)malloc(10 * sizeof(char));
> +  free(x);
> +  return x[5];
> +  // Check that paths in error report don't start with slash.
> +  // CHECK: heap-use-after-free
> +  // CHECK-NOT: #0 0x{{.*}} ({{[/].*}})
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/strncpy-overflow.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/strncpy-overflow.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/strncpy-overflow.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/strncpy-overflow.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,28 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt > %t.output
> +// RUN: FileCheck %s < %t.output
> +// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
> +
> +#include <string.h>
> +#include <stdlib.h>
> +int main(int argc, char **argv) {
> +  char *hello = (char*)malloc(6);
> +  strcpy(hello, "hello");
> +  char *short_buffer = (char*)malloc(9);
> +  strncpy(short_buffer, hello, 10);  // BOOM
> +  // CHECK: {{WRITE of size 1 at 0x.* thread T0}}
> +  // CHECK-Linux: {{    #0 0x.* in .*strncpy}}
> +  // CHECK-Darwin: {{    #0 0x.* in wrap_strncpy}}
> +  // CHECK: {{    #1 0x.* in main .*strncpy-overflow.cc:12}}
> +  // CHECK: {{0x.* is located 0 bytes to the right of 9-byte region}}
> +  // CHECK: {{allocated by thread T0 here:}}
> +
> +  // CHECK-Linux: {{    #0 0x.* in .*malloc}}
> +  // CHECK-Linux: {{    #1 0x.* in main .*strncpy-overflow.cc:11}}
> +
> +  // CHECK-Darwin: {{    #0 0x.* in .*mz_malloc.*}}
> +  // CHECK-Darwin: {{    #1 0x.* in malloc_zone_malloc.*}}
> +  // CHECK-Darwin: {{    #2 0x.* in malloc.*}}
> +  // CHECK-Darwin: {{    #3 0x.* in main .*strncpy-overflow.cc:11}}
> +  return short_buffer[8];
> +}
>
> Added: compiler-rt/trunk/lib/asan/lit_tests/use-after-free.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/use-after-free.cc?rev=161935&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/lib/asan/lit_tests/use-after-free.cc (added)
> +++ compiler-rt/trunk/lib/asan/lit_tests/use-after-free.cc Wed Aug 15
> 03:29:17 2012
> @@ -0,0 +1,35 @@
> +// RUN: %clang_asan -m64 -O2 %s -o %t
> +// RUN: %t 2>&1 | %symbolizer | c++filt > %t.output
> +// RUN: FileCheck %s < %t.output
> +// RUN: FileCheck %s --check-prefix=CHECK-%os < %t.output
> +
> +#include <stdlib.h>
> +int main() {
> +  char *x = (char*)malloc(10 * sizeof(char));
> +  free(x);
> +  return x[5];
> +  // CHECK: {{.*ERROR: AddressSanitizer heap-use-after-free on address}}
> +  // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
> +  // CHECK: {{READ of size 1 at 0x.* thread T0}}
> +  // CHECK: {{    #0 0x.* in main .*use-after-free.cc:10}}
> +  // CHECK: {{0x.* is located 5 bytes inside of 10-byte region
> .0x.*,0x.*}}
> +  // CHECK: {{freed by thread T0 here:}}
> +
> +  // CHECK-Linux: {{    #0 0x.* in .*free}}
> +  // CHECK-Linux: {{    #1 0x.* in main .*use-after-free.cc:9}}
> +
> +  // CHECK-Darwin: {{    #0 0x.* in .*mz_free.*}}
> +  // We override free() on Darwin, thus no malloc_zone_free
> +  // CHECK-Darwin: {{    #1 0x.* in wrap_free}}
> +  // CHECK-Darwin: {{    #2 0x.* in main .*use-after-free.cc:9}}
> +
> +  // CHECK: {{previously allocated by thread T0 here:}}
> +
> +  // CHECK-Linux: {{    #0 0x.* in .*malloc}}
> +  // CHECK-Linux: {{    #1 0x.* in main .*use-after-free.cc:8}}
> +
> +  // CHECK-Darwin: {{    #0 0x.* in .*mz_malloc.*}}
> +  // CHECK-Darwin: {{    #1 0x.* in malloc_zone_malloc.*}}
> +  // CHECK-Darwin: {{    #2 0x.* in malloc.*}}
> +  // CHECK-Darwin: {{    #3 0x.* in main .*use-after-free.cc:8}}
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120815/907f925e/attachment.html>


More information about the llvm-commits mailing list