blob: e88741553d5bb08118a78e1efa4db08b5843733a [file] [log] [blame]
Matt Morehouse5c7fc762017-08-18 18:43:30 +00001; This check verifies that stack depth instrumentation works correctly.
2; RUN: opt < %s -sancov -sanitizer-coverage-level=1 \
Matt Morehouse6ec75952017-08-25 22:01:21 +00003; RUN: -sanitizer-coverage-stack-depth -S | FileCheck %s --enable-var-scope
Matt Morehouse5c7fc762017-08-18 18:43:30 +00004; RUN: opt < %s -sancov -sanitizer-coverage-level=3 \
5; RUN: -sanitizer-coverage-stack-depth -sanitizer-coverage-trace-pc-guard \
Matt Morehouse6ec75952017-08-25 22:01:21 +00006; RUN: -S | FileCheck %s --enable-var-scope
Matt Morehouse5c7fc762017-08-18 18:43:30 +00007
8target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
Matt Morehouseb1fa8252017-08-22 21:28:29 +000011; CHECK: @__sancov_lowest_stack = thread_local(initialexec) global i64 -1
Matt Morehouse5c7fc762017-08-18 18:43:30 +000012@__sancov_lowest_stack = thread_local global i64 0, align 8
13
14define i32 @foo() {
15entry:
16; CHECK-LABEL: define i32 @foo
Matt Morehouse6ec75952017-08-25 22:01:21 +000017; CHECK: [[framePtr:%[^ \t]+]] = call i8* @llvm.frameaddress(i32 0)
18; CHECK: [[frameInt:%[^ \t]+]] = ptrtoint i8* [[framePtr]] to [[$intType:i[0-9]+]]
19; CHECK: [[lowest:%[^ \t]+]] = load [[$intType]], [[$intType]]* @__sancov_lowest_stack
20; CHECK: [[cmp:%[^ \t]+]] = icmp ult [[$intType]] [[frameInt]], [[lowest]]
21; CHECK: br i1 [[cmp]], label %[[ifLabel:[^ \t]+]], label
22; CHECK: <label>:[[ifLabel]]:
23; CHECK: store [[$intType]] [[frameInt]], [[$intType]]* @__sancov_lowest_stack
Matt Morehouse5c7fc762017-08-18 18:43:30 +000024; CHECK: ret i32 7
25
26 ret i32 7
27}
28
29define i32 @bar() {
30entry:
31; CHECK-LABEL: define i32 @bar
32; CHECK: [[framePtr:%[^ \t]+]] = call i8* @llvm.frameaddress(i32 0)
Matt Morehouse6ec75952017-08-25 22:01:21 +000033; CHECK: [[frameInt:%[^ \t]+]] = ptrtoint i8* [[framePtr]] to [[$intType]]
34; CHECK: [[lowest:%[^ \t]+]] = load [[$intType]], [[$intType]]* @__sancov_lowest_stack
35; CHECK: [[cmp:%[^ \t]+]] = icmp ult [[$intType]] [[frameInt]], [[lowest]]
Matt Morehouse5c7fc762017-08-18 18:43:30 +000036; CHECK: br i1 [[cmp]], label %[[ifLabel:[^ \t]+]], label
37; CHECK: <label>:[[ifLabel]]:
Matt Morehouse6ec75952017-08-25 22:01:21 +000038; CHECK: store [[$intType]] [[frameInt]], [[$intType]]* @__sancov_lowest_stack
Matt Morehouse5c7fc762017-08-18 18:43:30 +000039; CHECK: %call = call i32 @foo()
40; CHECK: ret i32 %call
41
42 %call = call i32 @foo()
43 ret i32 %call
44}
45
46define weak_odr hidden i64* @_ZTW21__sancov_lowest_stack() {
47 ret i64* @__sancov_lowest_stack
48}