Matt Morehouse | 5c7fc76 | 2017-08-18 18:43:30 +0000 | [diff] [blame^] | 1 | ; This check verifies that stack depth instrumentation works correctly. |
| 2 | ; RUN: opt < %s -sancov -sanitizer-coverage-level=1 \ |
| 3 | ; RUN: -sanitizer-coverage-stack-depth -S | FileCheck %s --enable-var-scope |
| 4 | ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 \ |
| 5 | ; RUN: -sanitizer-coverage-stack-depth -sanitizer-coverage-trace-pc-guard \ |
| 6 | ; RUN: -S | FileCheck %s --enable-var-scope |
| 7 | |
| 8 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 9 | target triple = "x86_64-unknown-linux-gnu" |
| 10 | |
| 11 | ; CHECK: @__sancov_lowest_stack = thread_local global i64 -1 |
| 12 | @__sancov_lowest_stack = thread_local global i64 0, align 8 |
| 13 | |
| 14 | define i32 @foo() { |
| 15 | entry: |
| 16 | ; CHECK-LABEL: define i32 @foo |
| 17 | ; CHECK: [[framePtr:%[^ \t]+]] = call i8* @llvm.frameaddress(i32 0) |
| 18 | ; CHECK: [[frameInt:%[^ \t]+]] = ptrtoint i8* [[framePtr]] to [[$intType:i[0-9]+]] |
| 19 | ; CHECK: [[lowestPtr:%[^ \t]+]] = call [[$intType]]* @_ZTW21__sancov_lowest_stack |
| 20 | ; CHECK: [[lowestInt:%[^ \t]+]] = load [[$intType]], [[$intType]]* [[lowestPtr]] |
| 21 | ; CHECK: [[cmp:%[^ \t]+]] = icmp ult [[$intType]] [[frameInt]], [[lowestInt]] |
| 22 | ; CHECK: br i1 [[cmp]], label %[[ifLabel:[^ \t]+]], label |
| 23 | ; CHECK: <label>:[[ifLabel]]: |
| 24 | ; CHECK: store [[$intType]] [[frameInt]], [[$intType]]* [[lowestPtr]] |
| 25 | ; CHECK: ret i32 7 |
| 26 | |
| 27 | ret i32 7 |
| 28 | } |
| 29 | |
| 30 | define i32 @bar() { |
| 31 | entry: |
| 32 | ; CHECK-LABEL: define i32 @bar |
| 33 | ; CHECK: [[framePtr:%[^ \t]+]] = call i8* @llvm.frameaddress(i32 0) |
| 34 | ; CHECK: [[frameInt:%[^ \t]+]] = ptrtoint i8* [[framePtr]] to [[$intType]] |
| 35 | ; CHECK: [[lowestPtr:%[^ \t]+]] = call [[$intType]]* @_ZTW21__sancov_lowest_stack |
| 36 | ; CHECK: [[lowestInt:%[^ \t]+]] = load [[$intType]], [[$intType]]* [[lowestPtr]] |
| 37 | ; CHECK: [[cmp:%[^ \t]+]] = icmp ult [[$intType]] [[frameInt]], [[lowestInt]] |
| 38 | ; CHECK: br i1 [[cmp]], label %[[ifLabel:[^ \t]+]], label |
| 39 | ; CHECK: <label>:[[ifLabel]]: |
| 40 | ; CHECK: store [[$intType]] [[frameInt]], [[$intType]]* [[lowestPtr]] |
| 41 | ; CHECK: %call = call i32 @foo() |
| 42 | ; CHECK: ret i32 %call |
| 43 | |
| 44 | %call = call i32 @foo() |
| 45 | ret i32 %call |
| 46 | } |
| 47 | |
| 48 | define weak_odr hidden i64* @_ZTW21__sancov_lowest_stack() { |
| 49 | ret i64* @__sancov_lowest_stack |
| 50 | } |