From 3d3d9d69fb6488f733629ecbc59fc0a74fb4de38 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Thu, 11 Oct 2018 01:05:18 +0000 Subject: [PATCH] [hwasan] extend the stack-uar test llvm-svn: 344213 --- compiler-rt/test/hwasan/TestCases/stack-uar.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler-rt/test/hwasan/TestCases/stack-uar.c b/compiler-rt/test/hwasan/TestCases/stack-uar.c index 2c59b17..8af56a9 100644 --- a/compiler-rt/test/hwasan/TestCases/stack-uar.c +++ b/compiler-rt/test/hwasan/TestCases/stack-uar.c @@ -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 -#include +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 } -- 2.7.4