• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -msan -msan-check-access-address=0 -msan-wrap-indirect-calls=zzz -msan-wrap-indirect-calls-fast=0 -S | FileCheck %s
2; RUN: opt < %s -msan -msan-check-access-address=0 -msan-wrap-indirect-calls=zzz -msan-wrap-indirect-calls-fast=1 -S | FileCheck -check-prefix=CHECK-FAST %s
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
6; Test for -msan-wrap-indirect-calls functionality.
7; Replaces indirect call to %f with a call to whatever is returned from the
8; wrapper function.
9
10; This does not depend on the sanitize_memory attribute.
11define i32 @func1(i32 (i32, i32)* nocapture %f, i32 %x, i32 %y) {
12entry:
13  %call = tail call i32 %f(i32 %x, i32 %y)
14  ret i32 %call
15}
16
17; CHECK: @func1
18; CHECK: bitcast i32 (i32, i32)* %f to void ()*
19; CHECK: call void ()* (void ()*)* @zzz(void ()*
20; CHECK: [[A:%[01-9a-z_.]+]] = bitcast void ()* {{.*}} to i32 (i32, i32)*
21; CHECK: call i32 {{.*}}[[A]](i32 {{.*}}, i32 {{.*}})
22; CHECK: ret i32
23
24; CHECK-FAST: @func1
25; CHECK-FAST: bitcast i32 (i32, i32)* %f to void ()*
26; CHECK-FAST-DAG: icmp ult void ()* {{.*}}, bitcast (i32* @__executable_start to void ()*)
27; CHECK-FAST-DAG: icmp uge void ()* {{.*}}, bitcast (i32* @_end to void ()*)
28; CHECK-FAST: or i1
29; CHECK-FAST: br i1
30; CHECK-FAST: call void ()* (void ()*)* @zzz(void ()*
31; CHECK-FAST: br label
32; CHECK-FAST: [[A:%[01-9a-z_.]+]] = phi i32 (i32, i32)* [ %f, %entry ], [ {{.*}} ]
33; CHECK-FAST: call i32 {{.*}}[[A]](i32 {{.*}}, i32 {{.*}})
34; CHECK-FAST: ret i32
35
36
37; The same test, but with a complex expression as the call target.
38
39declare i8* @callee(i32)
40
41define i8* @func2(i64 %x) #1 {
42entry:
43  %call = tail call i8* bitcast (i8* (i32)* @callee to i8* (i64)*)(i64 %x)
44  ret i8* %call
45}
46
47; CHECK: @func2
48; CHECK: call {{.*}} @zzz
49; CHECK: [[A:%[01-9a-z_.]+]] = bitcast void ()* {{.*}} to i8* (i64)*
50; CHECK: call i8* {{.*}}[[A]](i64 {{.*}})
51; CHECK: ret i8*
52
53; CHECK-FAST: @func2
54; CHECK-FAST: {{br i1 or .* icmp ult .* bitcast .* @callee .* @__executable_start.* icmp uge .* bitcast .* @callee .* @_end}}
55; CHECK-FAST: {{call .* @zzz.* bitcast .*@callee}}
56; CHECK-FAST: bitcast void ()* {{.*}} to i8* (i64)*
57; CHECK-FAST: br label
58; CHECK-FAST: [[A:%[01-9a-z_.]+]] = phi i8* (i64)* [{{.*bitcast .* @callee.*, %entry.*}}], [ {{.*}} ]
59; CHECK-FAST: call i8* {{.*}}[[A]](i64 {{.*}})
60; CHECK-FAST: ret i8*
61