[compiler-rt] r189457 - [asan]: fix a CHECK failure in use-after-return mode; enable and fix stack-use-after-return.cc; add a test for UAR mode in asan_noinst_test

Kostya Serebryany kcc at google.com
Wed Aug 28 01:59:24 PDT 2013


Author: kcc
Date: Wed Aug 28 03:59:23 2013
New Revision: 189457

URL: http://llvm.org/viewvc/llvm-project?rev=189457&view=rev
Log:
[asan]: fix a CHECK failure in use-after-return mode; enable and fix stack-use-after-return.cc; add a test for UAR mode in asan_noinst_test 

Modified:
    compiler-rt/trunk/lib/asan/asan_fake_stack.cc
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc
    compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc

Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=189457&r1=189456&r2=189457&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Wed Aug 28 03:59:23 2013
@@ -107,11 +107,11 @@ void FakeStack::AllocateOneSizeClass(upt
   //       size_class, new_mem, new_mem + ClassMmapSize(size_class),
   //       ClassMmapSize(size_class));
   uptr i;
-  for (i = 0; i < ClassMmapSize(size_class);
-       i += ClassSize(size_class)) {
+  uptr size = ClassSize(size_class);
+  for (i = 0; i + size <= ClassMmapSize(size_class); i += size) {
     size_classes_[size_class].FifoPush((FakeFrame*)(new_mem + i));
   }
-  CHECK(i == ClassMmapSize(size_class));
+  CHECK_LE(i, ClassMmapSize(size_class));
   allocated_size_classes_[size_class] = new_mem;
 }
 

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc?rev=189457&r1=189456&r2=189457&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/stack-use-after-return.cc Wed Aug 28 03:59:23 2013
@@ -1,15 +1,21 @@
-// XFAIL: *
 // RUN: %clangxx_asan -fsanitize=use-after-return -O0 %s -o %t && \
-// RUN:   %t 2>&1 | FileCheck %s
+// RUN:   not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -fsanitize=use-after-return -O1 %s -o %t && \
-// RUN:   %t 2>&1 | FileCheck %s
+// RUN:   not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -fsanitize=use-after-return -O2 %s -o %t && \
-// RUN:   %t 2>&1 | FileCheck %s
+// RUN:   not %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -fsanitize=use-after-return -O3 %s -o %t && \
-// RUN:   %t 2>&1 | FileCheck %s
+// RUN:   not %t 2>&1 | FileCheck %s
+// Regression test for a CHECK failure with small stack size and large frame.
+// RUN: %clangxx_asan -fsanitize=use-after-return -O3 %s -o %t -DkSize=10000 && \
+// RUN: (ulimit -s 65;  not %t) 2>&1 | FileCheck %s
 
 #include <stdio.h>
 
+#ifndef kSize
+# define kSize 1
+#endif
+
 __attribute__((noinline))
 char *Ident(char *x) {
   fprintf(stderr, "1: %p\n", x);
@@ -18,8 +24,8 @@ char *Ident(char *x) {
 
 __attribute__((noinline))
 char *Func1() {
-  char local;
-  return Ident(&local);
+  char local[kSize];
+  return Ident(local);
 }
 
 __attribute__((noinline))
@@ -28,7 +34,7 @@ void Func2(char *x) {
   *x = 1;
   // CHECK: WRITE of size 1 {{.*}} thread T0
   // CHECK:     #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]]
-  // CHECK: is located {{.*}} in frame <{{.*}}Func1{{.*}}> of T0's stack
+  // CHECK: is located in stack of thread T0 at offset
 }
 
 int main(int argc, char **argv) {

Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=189457&r1=189456&r2=189457&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Wed Aug 28 03:59:23 2013
@@ -793,3 +793,12 @@ TEST(AddressSanitizerInterface, CallocRe
     }
   }
 }
+
+TEST(AddressSanitizerInterface, FakeStack) {
+  for (int iter = 0; iter < 1000; iter++) {
+    for (int size = 8; size <= (1 << 14); size += 8) {
+      uptr p = __asan_stack_malloc(size, 0x12345678);
+      CHECK(p);
+    }
+  }
+}





More information about the llvm-commits mailing list