• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck %s
2; RUN: opt < %s -msan -S | FileCheck %s
3
4target datalayout = "E-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128"
5target triple = "mips64--linux"
6
7define i32 @foo(i32 %guard, ...) {
8  %vl = alloca i8*, align 8
9  %1 = bitcast i8** %vl to i8*
10  call void @llvm.lifetime.start.p0i8(i64 32, i8* %1)
11  call void @llvm.va_start(i8* %1)
12  call void @llvm.va_end(i8* %1)
13  call void @llvm.lifetime.end.p0i8(i64 32, i8* %1)
14  ret i32 0
15}
16
17; First, check allocation of the save area.
18
19; CHECK-LABEL: @foo
20; CHECK: [[A:%.*]] = load {{.*}} @__msan_va_arg_overflow_size_tls
21; CHECK: [[B:%.*]] = add i64 0, [[A]]
22; CHECK: [[C:%.*]] = alloca {{.*}} [[B]]
23
24; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[C]], i8* align 8 bitcast ({{.*}} @__msan_va_arg_tls to i8*), i64 [[B]], i1 false)
25
26declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
27declare void @llvm.va_start(i8*) #2
28declare void @llvm.va_end(i8*) #2
29declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
30
31define i32 @bar() {
32  %1 = call i32 (i32, ...) @foo(i32 0, i32 1, i64 2, double 3.000000e+00)
33  ret i32 %1
34}
35
36; Save the incoming shadow value from the arguments in the __msan_va_arg_tls
37; array.  The first argument is stored at position 4, since it's right
38; justified.
39; CHECK-LABEL: @bar
40; CHECK: store i32 0, i32* inttoptr (i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 4) to i32*), align 8
41; CHECK: store i64 0, i64* inttoptr (i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 8) to i64*), align 8
42; CHECK: store i64 0, i64* inttoptr (i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 16) to i64*), align 8
43; CHECK: store {{.*}} 24, {{.*}} @__msan_va_arg_overflow_size_tls
44
45; Check multiple fixed arguments.
46declare i32 @foo2(i32 %g1, i32 %g2, ...)
47define i32 @bar2() {
48  %1 = call i32 (i32, i32, ...) @foo2(i32 0, i32 1, i64 2, double 3.000000e+00)
49  ret i32 %1
50}
51
52; CHECK-LABEL: @bar2
53; CHECK: store i64 0, i64* getelementptr inbounds ([100 x i64], [100 x i64]* @__msan_va_arg_tls, i32 0, i32 0), align 8
54; CHECK: store i64 0, i64* inttoptr (i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 8) to i64*), align 8
55; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
56
57; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are
58; passed to a variadic function.
59define dso_local i64 @many_args() {
60entry:
61  %ret = call i64 (i64, ...) @sum(i64 120,
62    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
63    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
64    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
65    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
66    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
67    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
68    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
69    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
70    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
71    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
72    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1,
73    i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1
74  )
75  ret i64 %ret
76}
77
78; If the size of __msan_va_arg_tls changes the second argument of `add` must also be changed.
79; CHECK-LABEL: @many_args
80; CHECK: i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 792)
81; CHECK-NOT: i64 add (i64 ptrtoint ([100 x i64]* @__msan_va_arg_tls to i64), i64 800)
82declare i64 @sum(i64 %n, ...)
83