1 ; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck \
3 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
4 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \
5 ; RUN: -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN"
6 ; RUN: opt < %s -msan-check-access-address=0 -S \
7 ; RUN: -passes="msan<track-origins=1>" 2>&1 | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN"
8 ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN
9 ; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \
10 ; RUN: -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN"
11 ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN
13 ; Test that shadow and origin are stored for variadic function params.
15 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
16 target triple = "x86_64-unknown-linux-gnu"
18 %struct.__va_list_tag = type { i32, i32, i8*, i8* }
20 define dso_local i32 @test(i32 %a, i32 %b, i32 %c) local_unnamed_addr {
22 %call = tail call i32 (i32, ...) @sum(i32 3, i32 %a, i32 %b, i32 %c)
26 ; CHECK: store i32 0, {{.*}} @__msan_param_tls {{.*}} i64 8
27 ; CHECK: store i32 0, {{.*}} @__msan_param_tls {{.*}} i64 16
28 ; CHECK: store i32 0, {{.*}} @__msan_param_tls {{.*}} i64 24
29 ; CHECK: store i32 0, {{.*}} @__msan_va_arg_tls {{.*}} i64 8
30 ; CHECK-ORIGIN: store i32 0, {{.*}} @__msan_va_arg_origin_tls {{.*}} i64 8
31 ; CHECK: store i32 0, {{.*}} @__msan_va_arg_tls {{.*}} i64 16
32 ; CHECK-ORIGIN: store i32 0, {{.*}} @__msan_va_arg_origin_tls {{.*}} i64 16
33 ; CHECK: store i32 0, {{.*}} @__msan_va_arg_tls {{.*}} i64 24
34 ; CHECK-ORIGIN: store i32 0, {{.*}} @__msan_va_arg_origin_tls {{.*}} i64 24
36 define dso_local i32 @sum(i32 %n, ...) local_unnamed_addr #0 {
38 %args = alloca [1 x %struct.__va_list_tag], align 16
39 %0 = bitcast [1 x %struct.__va_list_tag]* %args to i8*
40 call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %0) #2
41 call void @llvm.va_start(i8* nonnull %0)
42 %cmp9 = icmp sgt i32 %n, 0
43 br i1 %cmp9, label %for.body.lr.ph, label %for.end
45 ; CHECK: [[VA_ARG_TLS:%[_0-9a-z]+]] = bitcast {{.*}} @__msan_va_arg_tls
46 ; CHECK: call void @llvm.memcpy.{{.*}} [[SHADOW_COPY:%[_0-9a-z]+]], {{.*}} [[VA_ARG_TLS]]
47 ; CHECK-ORIGIN: [[VA_ARG_ORIGIN_TLS:%[_0-9a-z]+]] = bitcast {{.*}} @__msan_va_arg_origin_tls
48 ; CHECK-ORIGIN: call void @llvm.memcpy{{.*}} [[ORIGIN_COPY:%[_0-9a-z]+]], {{.*}} [[VA_ARG_ORIGIN_TLS]]
50 ; CHECK: call void @llvm.va_start
51 ; CHECK: call void @llvm.memcpy.{{.*}}, {{.*}} [[SHADOW_COPY]], i{{.*}} [[REGSAVE:[0-9]+]]
52 ; CHECK-ORIGIN: call void @llvm.memcpy.{{.*}}, {{.*}} [[ORIGIN_COPY]], i{{.*}} [[REGSAVE]]
54 ; CHECK: [[OVERFLOW_SHADOW:%[_0-9a-z]+]] = getelementptr i8, i8* [[SHADOW_COPY]], i{{.*}} [[REGSAVE]]
55 ; CHECK: call void @llvm.memcpy.{{.*}}[[OVERFLOW_SHADOW]]
56 ; CHECK-ORIGIN: [[OVERFLOW_ORIGIN:%[_0-9a-z]+]] = getelementptr i8, i8* [[ORIGIN_COPY]], i{{.*}} [[REGSAVE]]
57 ; CHECK-ORIGIN: call void @llvm.memcpy.{{.*}}[[OVERFLOW_ORIGIN]]
59 for.body.lr.ph: ; preds = %entry
60 %gp_offset_p = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %args, i64 0, i64 0, i32 0
61 %1 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %args, i64 0, i64 0, i32 3
62 %overflow_arg_area_p = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %args, i64 0, i64 0, i32 2
63 %gp_offset.pre = load i32, i32* %gp_offset_p, align 16
66 for.body: ; preds = %vaarg.end, %for.body.lr.ph
67 %gp_offset = phi i32 [ %gp_offset.pre, %for.body.lr.ph ], [ %gp_offset12, %vaarg.end ]
68 %sum.011 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %vaarg.end ]
69 %i.010 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %vaarg.end ]
70 %fits_in_gp = icmp ult i32 %gp_offset, 41
71 br i1 %fits_in_gp, label %vaarg.in_reg, label %vaarg.in_mem
73 vaarg.in_reg: ; preds = %for.body
74 %reg_save_area = load i8*, i8** %1, align 16
75 %2 = sext i32 %gp_offset to i64
76 %3 = getelementptr i8, i8* %reg_save_area, i64 %2
77 %4 = add i32 %gp_offset, 8
78 store i32 %4, i32* %gp_offset_p, align 16
81 vaarg.in_mem: ; preds = %for.body
82 %overflow_arg_area = load i8*, i8** %overflow_arg_area_p, align 8
83 %overflow_arg_area.next = getelementptr i8, i8* %overflow_arg_area, i64 8
84 store i8* %overflow_arg_area.next, i8** %overflow_arg_area_p, align 8
87 vaarg.end: ; preds = %vaarg.in_mem, %vaarg.in_reg
88 %gp_offset12 = phi i32 [ %4, %vaarg.in_reg ], [ %gp_offset, %vaarg.in_mem ]
89 %vaarg.addr.in = phi i8* [ %3, %vaarg.in_reg ], [ %overflow_arg_area, %vaarg.in_mem ]
90 %vaarg.addr = bitcast i8* %vaarg.addr.in to i32*
91 %5 = load i32, i32* %vaarg.addr, align 4
92 %add = add nsw i32 %5, %sum.011
93 %inc = add nuw nsw i32 %i.010, 1
94 %exitcond = icmp eq i32 %inc, %n
95 br i1 %exitcond, label %for.end, label %for.body
97 for.end: ; preds = %vaarg.end, %entry
98 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %vaarg.end ]
99 call void @llvm.va_end(i8* nonnull %0)
100 call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %0) #2
105 ; Function Attrs: argmemonly nounwind
106 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
108 ; Function Attrs: nounwind
109 declare void @llvm.va_start(i8*) #2
111 ; Function Attrs: nounwind
112 declare void @llvm.va_end(i8*) #2
114 ; Function Attrs: argmemonly nounwind
115 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
117 declare dso_local i80 @sum_i80(i32, ...) local_unnamed_addr
119 ; Unaligned types like i80 should also work.
120 define dso_local i80 @test_i80(i80 %a, i80 %b, i80 %c) local_unnamed_addr {
122 %call = tail call i80 (i32, ...) @sum_i80(i32 3, i80 %a, i80 %b, i80 %c)