1 ; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
4 target triple = "loongarch64-unknown-linux-gnu"
6 ;; First, check allocation of the save area.
7 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
8 declare void @llvm.va_start(ptr) #2
9 declare void @llvm.va_end(ptr) #2
10 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
11 define i32 @foo(i32 %guard, ...) {
13 ; CHECK: [[TMP1:%.*]] = load {{.*}} @__msan_va_arg_overflow_size_tls
14 ; CHECK: [[TMP3:%.*]] = alloca {{.*}} [[TMP1]]
15 ; CHECK: call void @llvm.memset.p0.i64(ptr align 8 [[TMP3]], i8 0, i64 [[TMP1]], i1 false)
16 ; CHECK: [[TMP4:%.*]] = call i64 @llvm.umin.i64(i64 [[TMP1]], i64 800)
17 ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP3]], ptr align 8 @__msan_va_arg_tls, i64 [[TMP4]], i1 false)
19 %vl = alloca ptr, align 8
20 call void @llvm.lifetime.start.p0(i64 32, ptr %vl)
21 call void @llvm.va_start(ptr %vl)
22 call void @llvm.va_end(ptr %vl)
23 call void @llvm.lifetime.end.p0(i64 32, ptr %vl)
27 ;; Save the incoming shadow value from the arguments in the __msan_va_arg_tls
31 ; CHECK: store i32 0, ptr @__msan_va_arg_tls, align 8
32 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
33 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 16) to ptr), align 8
34 ; CHECK: store {{.*}} 24, {{.*}} @__msan_va_arg_overflow_size_tls
36 %1 = call i32 (i32, ...) @foo(i32 0, i32 1, i64 2, double 3.000000e+00)
40 ;; Check multiple fixed arguments.
41 declare i32 @foo2(i32 %g1, i32 %g2, ...)
44 ; CHECK: store i64 0, ptr @__msan_va_arg_tls, align 8
45 ; CHECK: store i64 0, ptr inttoptr (i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 8) to ptr), align 8
46 ; CHECK: store {{.*}} 16, {{.*}} @__msan_va_arg_overflow_size_tls
48 %1 = call i32 (i32, i32, ...) @foo2(i32 0, i32 1, i64 2, double 3.000000e+00)
52 ;; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are
53 ;; passed to a variadic function.
54 declare i64 @sum(i64 %n, ...)
55 define dso_local i64 @many_args() {
56 ;; If the size of __msan_va_arg_tls changes the second argument of `add` must also be changed.
57 ; CHECK-LABEL: @many_args
58 ; CHECK: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 792)
59 ; CHECK-NOT: i64 add (i64 ptrtoint (ptr @__msan_va_arg_tls to i64), i64 800)
62 %ret = call i64 (i64, ...) @sum(i64 120,
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 i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1