[hwasan] extend the stack-uar test
authorKostya Serebryany <kcc@google.com>
Thu, 11 Oct 2018 01:05:18 +0000 (01:05 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 11 Oct 2018 01:05:18 +0000 (01:05 +0000)
llvm-svn: 344213

compiler-rt/test/hwasan/TestCases/stack-uar.c

index 2c59b17..8af56a9 100644 (file)
@@ -1,23 +1,37 @@
+// Tests use-after-return detection and reporting.
 // RUN: %clang_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: stable-runtime
 
-#include <stdlib.h>
-#include <sanitizer/hwasan_interface.h>
+void USE(void *x) { // pretend_to_do_something(void *x)
+  __asm__ __volatile__("" : : "r" (x) : "memory");
+}
 
 __attribute__((noinline))
-char *f() {
+char *buggy() {
   char z[0x1000];
   char *volatile p = z;
   return p;
 }
 
+__attribute__((noinline)) void Unrelated1() { int A[2]; USE(&A[0]); }
+__attribute__((noinline)) void Unrelated2() { int BB[3]; USE(&BB[0]); }
+__attribute__((noinline)) void Unrelated3() { int CCC[4]; USE(&CCC[0]); }
+
 int main() {
-  return *f();
+  char *p = buggy();
+  Unrelated1();
+  Unrelated2();
+  Unrelated3();
+  return *p;
   // CHECK: READ of size 1 at
-  // CHECK: #0 {{.*}} in main{{.*}}stack-uar.c:16
-
+  // CHECK: #0 {{.*}} in main{{.*}}stack-uar.c:[[@LINE-2]]
   // CHECK: is located in stack of thread
+  // CHECK: Previosly allocated frames:
+  // CHECK: Unrelated3
+  // CHECK: Unrelated2
+  // CHECK: Unrelated1
+  // CHECK: buggy
 
   // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
 }