1 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+ibt -x86-indirect-branch-tracking < %s | FileCheck %s --check-prefix=ALL --check-prefix=X86_64
2 ; RUN: llc -mtriple=i386-unknown-unknown -mattr=+ibt -x86-indirect-branch-tracking < %s | FileCheck %s --check-prefix=ALL --check-prefix=X86
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; Checks ENDBR insertion in case of indirect branch IR instruction.
8 ;; Also since the function is not internal, make sure that endbr32/64 was
9 ;; added at the beginning of the function.
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ; X86_64-NEXT: endbr64
21 ; X86_64-NEXT: endbr64
24 %0 = select i1 undef, i8* blockaddress(@test1, %bb), i8* blockaddress(@test1, %bb6) ; <i8*> [#uses=1]
25 indirectbr i8* %0, [label %bb, label %bb6]
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;; Checks ENDBR insertion in case of switch case statement.
38 ;; Also since the function is not internal, ENDBR instruction should be
39 ;; added to its first basic block.
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 define i32 @test2(i32 %a) {
48 ; X86_64-NEXT: endbr64
54 ; X86_64-NEXT: endbr64
57 ; X86_64-NEXT: endbr64
60 ; X86_64-NEXT: endbr64
63 ; X86_64-NEXT: endbr64
66 %retval = alloca i32, align 4
67 %a.addr = alloca i32, align 4
68 store i32 %a, i32* %a.addr, align 4
69 %0 = load i32, i32* %a.addr, align 4
70 switch i32 %0, label %sw.default [
78 sw.bb: ; preds = %entry
79 store i32 5, i32* %retval, align 4
82 sw.bb1: ; preds = %entry
83 store i32 7, i32* %retval, align 4
86 sw.bb2: ; preds = %entry
87 store i32 2, i32* %retval, align 4
90 sw.bb3: ; preds = %entry
91 store i32 32, i32* %retval, align 4
94 sw.bb4: ; preds = %entry
95 store i32 73, i32* %retval, align 4
98 sw.default: ; preds = %entry
99 store i32 0, i32* %retval, align 4
102 return: ; preds = %sw.default, %sw.bb4, %sw.bb3, %sw.bb2, %sw.bb1, %sw.bb
103 %1 = load i32, i32* %retval, align 4
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 ;; Checks ENDBR insertion in case of indirect call instruction.
111 ;; The new instruction should be added to the called function (test6)
112 ;; although it is internal.
113 ;; Also since the function is not internal, ENDBR instruction should be
114 ;; added to its first basic block.
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 define void @test3() {
123 %f = alloca i32 (...)*, align 8
124 store i32 (...)* bitcast (i32 (i32)* @test6 to i32 (...)*), i32 (...)** %f, align 8
125 %0 = load i32 (...)*, i32 (...)** %f, align 8
126 %call = call i32 (...) %0()
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133 ;; Checks ENDBR insertion in case of setjmp-like function calls.
134 ;; Also since the function is not internal, ENDBR instruction should be
135 ;; added to its first basic block.
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
138 @buf = internal global [5 x i8*] zeroinitializer
139 declare i8* @llvm.frameaddress(i32)
140 declare i8* @llvm.stacksave()
141 declare i32 @llvm.eh.sjlj.setjmp(i8*)
143 define i32 @test4() {
148 ; X86_64-NEXT: endbr64
150 %fp = tail call i8* @llvm.frameaddress(i32 0)
151 store i8* %fp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 0), align 16
152 %sp = tail call i8* @llvm.stacksave()
153 store i8* %sp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 2), align 16
154 %r = tail call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([5 x i8*]* @buf to i8*))
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 ;; Checks ENDBR insertion in case of internal function.
162 ;; Since the function is internal and its address was not taken,
163 ;; make sure that endbr32/64 was not added at the beginning of the
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
167 define internal i8 @test5(){
169 ; X86_64-NOT: endbr64
174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 ;; Checks ENDBR insertion in case of function that its was address taken.
178 ;; Since the function's address was taken by test3() and despite being
179 ;; internal, check for added endbr32/64 at the beginning of the function.
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 define internal i32 @test6(i32 %a) {
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192 ;; Checks ENDBR insertion in case of non-intrenal function.
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 define i32 @test7() {