1 ; RUN: opt -lowertypetests -S %s | FileCheck --check-prefix=FULL %s
2 ; RUN: opt -lowertypetests -lowertypetests-summary-action=import -lowertypetests-read-summary=%p/Inputs/cfi-direct-call1.yaml -S %s | FileCheck --check-prefix=THIN %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux"
7 define hidden i32 @local_func1() !type !3 !type !4 {
11 define hidden i32 @local_func2() !type !3 !type !4 {
15 define hidden i32 @local_func3(i32 %i) local_unnamed_addr !type !5 !type !6 {
17 %add = add nsw i32 %i, 44
21 declare !type !3 !type !4 extern_weak i32 @extern_weak()
22 declare !type !3 !type !4 i32 @extern_decl()
23 declare i1 @llvm.type.test(i8*, metadata)
25 define hidden i32 @main(i32 %argc) {
27 %cmp.i = icmp sgt i32 %argc, 1
28 %fptr1 = select i1 %cmp.i, i32 ()* @local_func1, i32 ()* @local_func2
29 %fptr2 = select i1 %cmp.i, i32 ()* @extern_weak, i32 ()* @extern_decl
30 %0 = bitcast i32 ()* %fptr1 to i8*
31 %1 = tail call i1 @llvm.type.test(i8* nonnull %0, metadata !"_ZTSFivE")
33 %call2 = tail call i32 %fptr1()
34 %2 = bitcast i32 ()* %fptr2 to i8*
35 %3 = tail call i1 @llvm.type.test(i8* %2, metadata !"_ZTSFivE")
37 %call4 = tail call i32 %fptr2()
38 %call5 = tail call i32 @extern_decl()
39 %call7 = tail call i32 @extern_weak()
40 %call6 = tail call i32 @local_func1()
41 %call8 = tail call i32 @local_func3(i32 4)
45 !3 = !{i64 0, !"_ZTSFivE"}
46 !4 = !{i64 0, !"_ZTSFivE.generalized"}
47 !5 = !{i64 0, !"_ZTSFiiE"}
48 !6 = !{i64 0, !"_ZTSFiiE.generalized"}
50 ; Make sure local_func1 and local_func2 have been renamed to <name>.cfi
51 ; FULL: define hidden i32 @local_func1.cfi()
52 ; FULL: define hidden i32 @local_func2.cfi()
54 ; There are no indirect calls of local_func3 type, it should not be renamed
55 ; FULL: define hidden i32 @local_func3(i32 %i)
57 ; Indirect references to local_func1 and local_func2 must to through jump table
58 ; FULL: %fptr1 = select i1 %cmp.i, i32 ()* @local_func1, i32 ()* @local_func2
60 ; Indirect references to extern_weak and extern_decl must go through jump table
61 ; FULL: %fptr2 = select i1 %cmp.i, i32 ()* select (i1 icmp ne (i32 ()* @extern_weak, i32 ()* null), i32 ()* bitcast ([8 x i8]* getelementptr inbounds ([4 x [8 x i8]], [4 x [8 x i8]]* bitcast (void ()* @.cfi.jumptable to [4 x [8 x i8]]*), i64 0, i64 2) to i32 ()*), i32 ()* null), i32 ()* bitcast ([8 x i8]* getelementptr inbounds ([4 x [8 x i8]], [4 x [8 x i8]]* bitcast (void ()* @.cfi.jumptable to [4 x [8 x i8]]*), i64 0, i64 3) to i32 ()*)
63 ; Direct calls to extern_weak and extern_decl should go to original names
64 ; FULL: %call5 = tail call i32 @extern_decl()
65 ; FULL: %call7 = tail call i32 @extern_weak()
67 ; Direct call to local_func1 should to the renamed version
68 ; FULL: %call6 = tail call i32 @local_func1.cfi()
70 ; local_func3 hasn't been renamed, direct call should go to the original name
71 ; FULL: %call8 = tail call i32 @local_func3(i32 4)
73 ; Check which jump table entries are created
74 ; FULL: define private void @.cfi.jumptable(){{.*}}
76 ; FULL-NEXT: call void asm{{.*}}local_func1.cfi{{.*}}local_func2.cfi{{.*}}extern_weak{{.*}}extern_decl
78 ; Make sure all local functions have been renamed to <name>.cfi
79 ; THIN: define hidden i32 @local_func1.cfi()
80 ; THIN: define hidden i32 @local_func2.cfi()
81 ; THIN: define hidden i32 @local_func3.cfi(i32 %i){{.*}}
83 ; Indirect references to local_func1 and local_func2 must to through jump table
84 ; THIN: %fptr1 = select i1 %cmp.i, i32 ()* @local_func1, i32 ()* @local_func2
86 ; Indirect references to extern_weak and extern_decl must go through jump table
87 ; THIN: %fptr2 = select i1 %cmp.i, i32 ()* select (i1 icmp ne (i32 ()* @extern_weak, i32 ()* null), i32 ()* @extern_weak.cfi_jt, i32 ()* null), i32 ()* @extern_decl.cfi_jt
89 ; Direct calls to extern_weak and extern_decl should go to original names
90 ; THIN: %call5 = tail call i32 @extern_decl()
91 ; THIN: %call7 = tail call i32 @extern_weak()
93 ; Direct call to local_func1 should to the renamed version
94 ; THIN: %call6 = tail call i32 @local_func1.cfi()
95 ; THIN: %call8 = tail call i32 @local_func3.cfi(i32 4)