[compiler-rt] r179271 - [asan] add heavy_uar_test (disabled); fix lint

Kostya Serebryany kcc at google.com
Thu Apr 11 04:29:08 PDT 2013


Author: kcc
Date: Thu Apr 11 06:29:07 2013
New Revision: 179271

URL: http://llvm.org/viewvc/llvm-project?rev=179271&view=rev
Log:
[asan] add heavy_uar_test (disabled); fix lint

Added:
    compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc
Modified:
    compiler-rt/trunk/lib/asan/lit_tests/time_interceptor.cc

Added: compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc?rev=179271&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/Linux/heavy_uar_test.cc Thu Apr 11 06:29:07 2013
@@ -0,0 +1,46 @@
+// XFAIL *
+// RUN: %clangxx_asan -fsanitize=use-after-return -m64 -O0 %s -o %t && \
+// RUN:   %t 2>&1 | %symbolize | FileCheck %s
+// RUN: %clangxx_asan -fsanitize=use-after-return -m64 -O2 %s -o %t && \
+// RUN:   %t 2>&1 | %symbolize | FileCheck %s
+// RUN: %clangxx_asan -fsanitize=use-after-return -m32 -O2 %s -o %t && \
+// RUN:   %t 2>&1 | %symbolize | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+__attribute__((noinline))
+inline char *pretend_to_do_something(char *x) {
+  __asm__ __volatile__("" : : "r" (x) : "memory");
+  return x;
+}
+
+__attribute__((noinline))
+char *LeakStack() {
+  char x[1024];
+  memset(x, 0, sizeof(x));
+  return pretend_to_do_something(x);
+}
+
+__attribute__((noinline))
+void RecuriveFunctionWithStackFrame(int depth) {
+  if (depth <= 0) return;
+  char x[1000];
+  memset(x, 0, sizeof(x));
+  pretend_to_do_something(x);
+  RecuriveFunctionWithStackFrame(depth - 1);
+  memset(x, 0, sizeof(x));
+}
+
+int main(int argc, char **argv) {
+  char *stale_stack = LeakStack();
+  RecuriveFunctionWithStackFrame(10);
+  RecuriveFunctionWithStackFrame(20);
+  RecuriveFunctionWithStackFrame(30);
+  stale_stack[100]++;
+  // CHECK: ERROR: AddressSanitizer: stack-use-after-return on address
+  // CHECK: is located in stack of thread T0 at offset 132 in frame
+  // CHECK:  in LeakStack(){{.*}}heavy_uar_test.cc:
+  // CHECK: [32, 1056) 'x'
+  return 0;
+}

Modified: compiler-rt/trunk/lib/asan/lit_tests/time_interceptor.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/time_interceptor.cc?rev=179271&r1=179270&r2=179271&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/time_interceptor.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/time_interceptor.cc Thu Apr 11 06:29:07 2013
@@ -11,10 +11,10 @@ int main() {
   time_t *tm = (time_t*)malloc(sizeof(time_t));
   free(tm);
   time_t t = time(NULL);
-  fprintf(stderr, "Time: %s\n", ctime(&t));
+  fprintf(stderr, "Time: %s\n", ctime(&t));  // NOLINT
   // CHECK: {{Time: .* .* .*}}
   t = time(tm);
-  printf("Time: %s\n", ctime(&t));
+  printf("Time: %s\n", ctime(&t));  // NOLINT
   // CHECK: use-after-free
   return 0;
 }





More information about the llvm-commits mailing list