1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2 ; RUN: opt < %s -passes='module(sanmd-module)' -sanitizer-metadata-atomics -S | FileCheck %s
4 target 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"
5 target triple = "x86_64-unknown-linux-gnu"
7 declare void @escape(ptr)
9 @sink = global ptr null, align 4
10 @const_global = external constant i32
11 @non_const_global = global i32 0, align 4
12 @const_global_array = external constant [10 x i32]
14 define i32 @notcaptured() {
15 ; CHECK-LABEL: define {{[^@]+}}@notcaptured() {
17 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
18 ; CHECK-NEXT: store i32 42, ptr [[PTR]], align 4
19 ; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr [[PTR]], align 4
20 ; CHECK-NEXT: ret i32 [[TMP]]
23 %ptr = alloca i32, align 4
24 store i32 42, ptr %ptr, align 4
25 %tmp = load i32, ptr %ptr, align 4
29 define void @captured0() {
30 ; CHECK-LABEL: define {{[^@]+}}@captured0() !pcsections !0 {
32 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
33 ; CHECK-NEXT: call void @escape(ptr [[PTR]])
34 ; CHECK-NEXT: store i32 42, ptr [[PTR]], align 4
35 ; CHECK-NEXT: ret void
38 %ptr = alloca i32, align 4
40 call void @escape(ptr %ptr)
41 store i32 42, ptr %ptr, align 4
45 define void @captured1() {
46 ; CHECK-LABEL: define {{[^@]+}}@captured1() !pcsections !0 {
48 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
49 ; CHECK-NEXT: store ptr [[PTR]], ptr @sink, align 8
50 ; CHECK-NEXT: store i32 42, ptr [[PTR]], align 4
51 ; CHECK-NEXT: ret void
54 %ptr = alloca i32, align 4
55 ; escapes due to store into global
56 store ptr %ptr, ptr @sink, align 8
57 store i32 42, ptr %ptr, align 4
61 define void @captured2() {
62 ; CHECK-LABEL: define {{[^@]+}}@captured2() !pcsections !0 {
64 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
65 ; CHECK-NEXT: [[TMP:%.*]] = alloca ptr, align 8
66 ; CHECK-NEXT: store ptr [[PTR]], ptr [[TMP]], align 8
67 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[TMP]], align 8
68 ; CHECK-NEXT: store ptr [[TMP0]], ptr @sink, align 8
69 ; CHECK-NEXT: store i32 42, ptr [[PTR]], align 4
70 ; CHECK-NEXT: ret void
73 %ptr = alloca i32, align 4
74 %tmp = alloca ptr, align 8
76 store ptr %ptr, ptr %tmp, align 8
77 %0 = load ptr, ptr %tmp, align 8
78 store ptr %0, ptr @sink, align 8
79 store i32 42, ptr %ptr, align 4
83 define i32 @read_from_const_global() {
84 ; CHECK-LABEL: define {{[^@]+}}@read_from_const_global() {
86 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @const_global, align 4
87 ; CHECK-NEXT: ret i32 [[TMP0]]
90 %0 = load i32, ptr @const_global, align 4
94 define i32 @read_from_non_const_global() {
95 ; CHECK-LABEL: define {{[^@]+}}@read_from_non_const_global() !pcsections !0 {
97 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @non_const_global, align 4
98 ; CHECK-NEXT: ret i32 [[TMP0]]
101 %0 = load i32, ptr @non_const_global, align 4
105 define i32 @read_from_const_global_array(i32 %idx) {
106 ; CHECK-LABEL: define {{[^@]+}}@read_from_const_global_array
107 ; CHECK-SAME: (i32 [[IDX:%.*]]) {
109 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[IDX]] to i64
110 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [10 x i32], ptr @const_global_array, i64 0, i64 [[IDXPROM]]
111 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
112 ; CHECK-NEXT: ret i32 [[TMP0]]
115 %idxprom = sext i32 %idx to i64
116 %arrayidx = getelementptr inbounds [10 x i32], ptr @const_global_array, i64 0, i64 %idxprom
117 %0 = load i32, ptr %arrayidx, align 4
121 define i32 @notcaptured_and_global_access() {
122 ; CHECK-LABEL: define {{[^@]+}}@notcaptured_and_global_access() !pcsections !0 {
124 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
125 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr @non_const_global, align 4
126 ; CHECK-NEXT: store i32 [[A]], ptr [[PTR]], align 4
127 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[PTR]], align 4
128 ; CHECK-NEXT: ret i32 [[B]]
131 %ptr = alloca i32, align 4
132 %a = load i32, ptr @non_const_global, align 4
133 store i32 %a, ptr %ptr, align 4
134 %b = load i32, ptr %ptr, align 4
138 define i32 @notcaptured_and_const_global_access() {
139 ; CHECK-LABEL: define {{[^@]+}}@notcaptured_and_const_global_access() {
141 ; CHECK-NEXT: [[PTR:%.*]] = alloca i32, align 4
142 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr @const_global, align 4
143 ; CHECK-NEXT: store i32 [[A]], ptr [[PTR]], align 4
144 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[PTR]], align 4
145 ; CHECK-NEXT: ret i32 [[B]]
148 %ptr = alloca i32, align 4
149 %a = load i32, ptr @const_global, align 4
150 store i32 %a, ptr %ptr, align 4
151 %b = load i32, ptr %ptr, align 4