1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 2
2 ;; Check the cases involving internal CFI instrumented functions where we do not expect functions to be merged.
3 ; RUN: opt -S -passes=mergefunc < %s | FileCheck %s
4 ; RUN: opt -S -passes=mergefunc,lowertypetests < %s | FileCheck --check-prefix=LOWERTYPETESTS %s
6 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux"
9 @0 = private unnamed_addr constant { i16, i16, [12 x i8] } { i16 -1, i16 0, [12 x i8] c"'int (int)'\00" }
11 ; Function Attrs: noinline nounwind optnone
12 define dso_local i32 @f(i32 noundef %arg) #0 !type !3 !type !4 {
14 %arg.addr = alloca i32, align 4
15 %a = alloca i32, align 4
16 %b = alloca i32, align 4
17 store i32 %arg, ptr %arg.addr, align 4
18 store i32 0, ptr %b, align 4
19 %0 = load i32, ptr %arg.addr, align 4
20 %cmp = icmp sgt i32 %0, 0
21 br i1 %cmp, label %if.then, label %if.end
23 if.then: ; preds = %entry
24 store i32 1, ptr %a, align 4
27 if.end: ; preds = %if.then, %entry
28 %1 = load i32, ptr %a, align 4
29 %2 = load i32, ptr %b, align 4
30 %add = add nsw i32 %1, %2
34 ; Function Attrs: noinline nounwind optnone
35 define dso_local i32 @f_thunk(i32 noundef %arg) #0 !type !3 !type !4 {
37 %arg.addr = alloca i32, align 4
38 %a = alloca i32, align 4
39 %b = alloca i32, align 4
40 store i32 %arg, ptr %arg.addr, align 4
41 store i32 0, ptr %b, align 4
42 %0 = load i32, ptr %arg.addr, align 4
43 %cmp = icmp sgt i32 %0, 0
44 br i1 %cmp, label %if.then, label %if.end
46 if.then: ; preds = %entry
47 store i32 1, ptr %a, align 4
50 if.end: ; preds = %if.then, %entry
51 %1 = load i32, ptr %a, align 4
52 %2 = load i32, ptr %b, align 4
53 %add = add nsw i32 %1, %2
57 ; Function Attrs: noinline nounwind optnone
58 define dso_local i32 @g(i32 noundef %b) #0 !type !3 !type !4 {
60 %b.addr = alloca i32, align 4
61 %fp = alloca ptr, align 8
62 store i32 %b, ptr %b.addr, align 4
63 %0 = load i32, ptr %b.addr, align 4
64 %tobool = icmp ne i32 %0, 0
65 %1 = zext i1 %tobool to i64
66 %cond = select i1 %tobool, ptr @f, ptr @f_thunk
67 store ptr %cond, ptr %fp, align 8
68 %2 = load ptr, ptr %fp, align 8
69 %3 = call i1 @llvm.type.test(ptr %2, metadata !"_ZTSFiiE"), !nosanitize !5
70 br i1 %3, label %cont, label %trap, !nosanitize !5
72 trap: ; preds = %entry
73 call void @llvm.ubsantrap(i8 2) #3, !nosanitize !5
74 unreachable, !nosanitize !5
76 cont: ; preds = %entry
77 %4 = load i32, ptr %b.addr, align 4
78 %call = call i32 %2(i32 noundef %4)
82 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
83 declare i1 @llvm.type.test(ptr, metadata) #1
85 ; Function Attrs: cold noreturn nounwind
86 declare void @llvm.ubsantrap(i8 immarg) #2
88 attributes #0 = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
89 attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
90 attributes #2 = { cold noreturn nounwind }
91 attributes #3 = { noreturn nounwind }
93 !llvm.module.flags = !{!0, !1}
95 !0 = !{i32 1, !"wchar_size", i32 4}
96 !1 = !{i32 4, !"CFI Canonical Jump Tables", i32 0}
97 !3 = !{i64 0, !"_ZTSFiiE"}
98 !4 = !{i64 0, !"_ZTSFiiE.generalized"}
100 ; CHECK-LABEL: define dso_local i32 @f
101 ; CHECK-SAME: (i32 noundef [[ARG:%.*]]) #[[ATTR0:[0-9]+]] !type [[META2:![0-9]+]] !type [[META3:![0-9]+]] {
103 ; CHECK-NEXT: [[ARG_ADDR:%.*]] = alloca i32, align 4
104 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
105 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
106 ; CHECK-NEXT: store i32 [[ARG]], ptr [[ARG_ADDR]], align 4
107 ; CHECK-NEXT: store i32 0, ptr [[B]], align 4
108 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARG_ADDR]], align 4
109 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP0]], 0
110 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
112 ; CHECK-NEXT: store i32 1, ptr [[A]], align 4
113 ; CHECK-NEXT: br label [[IF_END]]
115 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
116 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[B]], align 4
117 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP2]]
118 ; CHECK-NEXT: ret i32 [[ADD]]
121 ; CHECK-LABEL: define dso_local i32 @g
122 ; CHECK-SAME: (i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META2]] !type [[META3]] {
124 ; CHECK-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
125 ; CHECK-NEXT: [[FP:%.*]] = alloca ptr, align 8
126 ; CHECK-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 4
127 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[B_ADDR]], align 4
128 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
129 ; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[TOBOOL]] to i64
130 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], ptr @f, ptr @f_thunk
131 ; CHECK-NEXT: store ptr [[COND]], ptr [[FP]], align 8
132 ; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[FP]], align 8
133 ; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.type.test(ptr [[TMP2]], metadata !"_ZTSFiiE"), !nosanitize [[META4:![0-9]+]]
134 ; CHECK-NEXT: br i1 [[TMP3]], label [[CONT:%.*]], label [[TRAP:%.*]], !nosanitize [[META4]]
136 ; CHECK-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !nosanitize [[META4]]
137 ; CHECK-NEXT: unreachable, !nosanitize [[META4]]
139 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[B_ADDR]], align 4
140 ; CHECK-NEXT: [[CALL:%.*]] = call i32 [[TMP2]](i32 noundef [[TMP4]])
141 ; CHECK-NEXT: ret i32 [[CALL]]
144 ; CHECK-LABEL: define dso_local i32 @f_thunk
145 ; CHECK-SAME: (i32 noundef [[TMP0:%.*]]) #[[ATTR0]] !type [[META2]] !type [[META3]] {
146 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i32 @f(i32 noundef [[TMP0]]) #[[ATTR0]]
147 ; CHECK-NEXT: ret i32 [[TMP2]]
150 ; LOWERTYPETESTS-LABEL: define dso_local i32 @f
151 ; LOWERTYPETESTS-SAME: (i32 noundef [[ARG:%.*]]) #[[ATTR0:[0-9]+]] !type [[META2:![0-9]+]] !type [[META3:![0-9]+]] {
152 ; LOWERTYPETESTS-NEXT: entry:
153 ; LOWERTYPETESTS-NEXT: [[ARG_ADDR:%.*]] = alloca i32, align 4
154 ; LOWERTYPETESTS-NEXT: [[A:%.*]] = alloca i32, align 4
155 ; LOWERTYPETESTS-NEXT: [[B:%.*]] = alloca i32, align 4
156 ; LOWERTYPETESTS-NEXT: store i32 [[ARG]], ptr [[ARG_ADDR]], align 4
157 ; LOWERTYPETESTS-NEXT: store i32 0, ptr [[B]], align 4
158 ; LOWERTYPETESTS-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARG_ADDR]], align 4
159 ; LOWERTYPETESTS-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP0]], 0
160 ; LOWERTYPETESTS-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
161 ; LOWERTYPETESTS: if.then:
162 ; LOWERTYPETESTS-NEXT: store i32 1, ptr [[A]], align 4
163 ; LOWERTYPETESTS-NEXT: br label [[IF_END]]
164 ; LOWERTYPETESTS: if.end:
165 ; LOWERTYPETESTS-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
166 ; LOWERTYPETESTS-NEXT: [[TMP2:%.*]] = load i32, ptr [[B]], align 4
167 ; LOWERTYPETESTS-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP2]]
168 ; LOWERTYPETESTS-NEXT: ret i32 [[ADD]]
171 ; LOWERTYPETESTS-LABEL: define dso_local i32 @g
172 ; LOWERTYPETESTS-SAME: (i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META2]] !type [[META3]] {
173 ; LOWERTYPETESTS-NEXT: entry:
174 ; LOWERTYPETESTS-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
175 ; LOWERTYPETESTS-NEXT: [[FP:%.*]] = alloca ptr, align 8
176 ; LOWERTYPETESTS-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 4
177 ; LOWERTYPETESTS-NEXT: [[TMP0:%.*]] = load i32, ptr [[B_ADDR]], align 4
178 ; LOWERTYPETESTS-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
179 ; LOWERTYPETESTS-NEXT: [[TMP1:%.*]] = zext i1 [[TOBOOL]] to i64
180 ; LOWERTYPETESTS-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], ptr @.cfi.jumptable, ptr getelementptr inbounds ([2 x [8 x i8]], ptr @.cfi.jumptable, i64 0, i64 1)
181 ; LOWERTYPETESTS-NEXT: store ptr [[COND]], ptr [[FP]], align 8
182 ; LOWERTYPETESTS-NEXT: [[TMP2:%.*]] = load ptr, ptr [[FP]], align 8
183 ; LOWERTYPETESTS-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[TMP2]] to i64
184 ; LOWERTYPETESTS-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], ptrtoint (ptr @.cfi.jumptable to i64)
185 ; LOWERTYPETESTS-NEXT: [[TMP5:%.*]] = lshr i64 [[TMP4]], 3
186 ; LOWERTYPETESTS-NEXT: [[TMP6:%.*]] = shl i64 [[TMP4]], 61
187 ; LOWERTYPETESTS-NEXT: [[TMP7:%.*]] = or i64 [[TMP5]], [[TMP6]]
188 ; LOWERTYPETESTS-NEXT: [[TMP8:%.*]] = icmp ule i64 [[TMP7]], 1
189 ; LOWERTYPETESTS-NEXT: br i1 [[TMP8]], label [[CONT:%.*]], label [[TRAP:%.*]], !nosanitize [[META4:![0-9]+]]
190 ; LOWERTYPETESTS: trap:
191 ; LOWERTYPETESTS-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META4]]
192 ; LOWERTYPETESTS-NEXT: unreachable, !nosanitize [[META4]]
193 ; LOWERTYPETESTS: cont:
194 ; LOWERTYPETESTS-NEXT: [[TMP9:%.*]] = load i32, ptr [[B_ADDR]], align 4
195 ; LOWERTYPETESTS-NEXT: [[CALL:%.*]] = call i32 [[TMP2]](i32 noundef [[TMP9]])
196 ; LOWERTYPETESTS-NEXT: ret i32 [[CALL]]
199 ; LOWERTYPETESTS-LABEL: define dso_local i32 @f_thunk
200 ; LOWERTYPETESTS-SAME: (i32 noundef [[TMP0:%.*]]) #[[ATTR0]] !type [[META2]] !type [[META3]] {
201 ; LOWERTYPETESTS-NEXT: [[TMP2:%.*]] = tail call i32 @f(i32 noundef [[TMP0]]) #[[ATTR0]]
202 ; LOWERTYPETESTS-NEXT: ret i32 [[TMP2]]
205 ; LOWERTYPETESTS-LABEL: define private void @.cfi.jumptable
206 ; LOWERTYPETESTS-SAME: () #[[ATTR3:[0-9]+]] align 8 {
207 ; LOWERTYPETESTS-NEXT: entry:
208 ; LOWERTYPETESTS-NEXT: call void asm sideeffect "jmp ${0:c}@plt\0Aint3\0Aint3\0Aint3\0Ajmp ${1:c}@plt\0Aint3\0Aint3\0Aint3\0A", "s,s"(ptr @f, ptr @f_thunk)
209 ; LOWERTYPETESTS-NEXT: unreachable