xref: /llvm-project/llvm/test/Instrumentation/DataFlowSanitizer/musttailcall.ll (revision 66c3444f4cc5c1f70ec33e7806f8236a39b6adc2)
1; RUN: opt < %s -passes=dfsan -S | FileCheck %s
2; RUN: opt < %s -passes=dfsan -dfsan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,CHECK_ORIGIN
3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4target triple = "x86_64-unknown-linux-gnu"
5
6declare i32 @f(i32)
7
8; CHECK-LABEL: @inner_callee.dfsan
9define i32 @inner_callee(i32) {
10  %r = call i32 @f(i32 %0)
11
12  ; COMM: Store here will be loaded in @outer_caller
13  ; CHECK: store{{.*}}__dfsan_retval_tls
14  ; CHECK_ORIGIN-NEXT: store{{.*}}__dfsan_retval_origin_tls
15  ; CHECK-NEXT: ret i32
16  ret i32 %r
17}
18
19; CHECK-LABEL: @musttail_call.dfsan
20define i32 @musttail_call(i32) {
21  ; CHECK: store{{.*}}__dfsan_arg_tls
22  ; CHECK-NEXT: musttail call i32 @inner_callee.dfsan
23  %r = musttail call i32 @inner_callee(i32 %0)
24
25  ; For "musttail" calls we can not insert any shadow manipulating code between
26  ; call and the return instruction. And we don't need to, because everything is
27  ; taken care of in the callee.
28  ; This is similar to the function above, but the last load and store of
29  ; __dfsan_retval_tls can be elided because we know about the musttail.
30
31  ; CHECK-NEXT: ret i32
32  ret i32 %r
33}
34
35; CHECK-LABEL: @outer_caller.dfsan
36define i32 @outer_caller() {
37  ; CHECK: call{{.*}}@musttail_call.dfsan
38  ; CHECK-NEXT: load{{.*}}__dfsan_retval_tls
39  ; CHECK_ORIGIN-NEXT: load{{.*}}__dfsan_retval_origin_tls
40  %r = call i32 @musttail_call(i32 0)
41
42  ; CHECK-NEXT: store{{.*}}__dfsan_retval_tls
43  ; CHECK_ORIGIN-NEXT: store{{.*}}__dfsan_retval_origin_tls
44  ; CHECK-NEXT: ret i32
45  ret i32 %r
46}
47
48declare ptr @mismatching_callee(i32)
49
50; CHECK-LABEL: define ptr @mismatching_musttail_call.dfsan
51define ptr @mismatching_musttail_call(i32) {
52  %r = musttail call ptr @mismatching_callee(i32 %0)
53  ; CHECK: musttail call ptr @mismatching_callee.dfsan
54  ; COMM: No instrumentation between call and ret.
55  ; CHECK-NEXT: ret ptr
56  ret ptr %r
57}
58