Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fb904e

Browse files
vitalybukalinuxlonelyeagle
authored andcommitted
[NFC][LowerTypeTests] Add AArch64 and X86 jump table tests with debug info (llvm#192735) (llvm#193358)
It just recommits test copied from non dbg version. Implementation is llvm#192736. This is the same as llvm#192735, accidentally merged into spr/users branch.
1 parent 35cae56 commit 0fb904e

2 files changed

Lines changed: 176 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals --include-generated-funcs
2+
; RUN: opt -S -passes=lowertypetests -mtriple=aarch64-unknown-linux-gnu %s | FileCheck --check-prefixes=AARCH64 %s
3+
4+
; Test for the jump table generation with branch protection on AArch64
5+
6+
target datalayout = "e-p:64:64"
7+
8+
@0 = private unnamed_addr constant [2 x ptr] [ptr @f, ptr @g], align 16
9+
10+
11+
define void @f() !type !0 {
12+
ret void
13+
}
14+
15+
define internal void @g() !type !0 {
16+
ret void
17+
}
18+
19+
!0 = !{i32 0, !"typeid1"}
20+
21+
declare i1 @llvm.type.test(ptr %ptr, metadata %bitset) nounwind readnone
22+
23+
define i1 @foo(ptr %p) {
24+
%x = call i1 @llvm.type.test(ptr %p, metadata !"typeid1")
25+
ret i1 %x
26+
}
27+
28+
!llvm.module.flags = !{!1, !2, !3}
29+
!1 = !{i32 4, !"branch-target-enforcement", i32 1}
30+
!2 = !{i32 7, !"Dwarf Version", i32 5}
31+
!3 = !{i32 2, !"Debug Info Version", i32 3}
32+
33+
34+
;.
35+
; AARCH64: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [2 x ptr] [ptr @f, ptr @g], align 16
36+
; AARCH64: @[[GLOB1:[0-9]+]] = private constant [0 x i8] zeroinitializer
37+
; AARCH64: @f = alias [8 x i8], ptr @.cfi.jumptable
38+
; AARCH64: @g = internal alias [8 x i8], getelementptr inbounds ([2 x [8 x i8]], ptr @.cfi.jumptable, i64 0, i64 1)
39+
;.
40+
; AARCH64-LABEL: @f.cfi(
41+
; AARCH64-NEXT: ret void
42+
;
43+
;
44+
; AARCH64-LABEL: @g.cfi(
45+
; AARCH64-NEXT: ret void
46+
;
47+
;
48+
; AARCH64-LABEL: @foo(
49+
; AARCH64-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P:%.*]] to i64
50+
; AARCH64-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr getelementptr (i8, ptr @.cfi.jumptable, i64 8) to i64), [[TMP1]]
51+
; AARCH64-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 3)
52+
; AARCH64-NEXT: [[TMP4:%.*]] = icmp ule i64 [[TMP3]], 1
53+
; AARCH64-NEXT: ret i1 [[TMP4]]
54+
;
55+
;
56+
; AARCH64: Function Attrs: naked noinline
57+
; AARCH64-LABEL: @.cfi.jumptable(
58+
; AARCH64-NEXT: entry:
59+
; AARCH64-NEXT: call void asm sideeffect "bti c\0Ab $0\0A", "s"(ptr @f.cfi)
60+
; AARCH64-NEXT: call void asm sideeffect "bti c\0Ab $0\0A", "s"(ptr @g.cfi)
61+
; AARCH64-NEXT: unreachable
62+
;
63+
;.
64+
; AARCH64: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
65+
; AARCH64: attributes #[[ATTR1:[0-9]+]] = { naked noinline }
66+
; AARCH64: attributes #[[ATTR2:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
67+
;.
68+
; AARCH64: [[META0:![0-9]+]] = !{i32 4, !"branch-target-enforcement", i32 1}
69+
; AARCH64: [[META1:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
70+
; AARCH64: [[META2:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
71+
; AARCH64: [[META3:![0-9]+]] = !{i32 0, !"typeid1"}
72+
;.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
2+
;; Test jump table generation with Indirect Branch Tracking on x86.
3+
; RUN: opt -S -passes=lowertypetests -mtriple=i686 %s | FileCheck --check-prefixes=X86_32 %s
4+
; RUN: opt -S -passes=lowertypetests -mtriple=x86_64 %s | FileCheck --check-prefixes=X86_64 %s
5+
6+
@0 = private unnamed_addr constant [2 x ptr] [ptr @f, ptr @g], align 16
7+
8+
define void @f() !type !0 {
9+
ret void
10+
}
11+
12+
define internal void @g() !type !0 {
13+
ret void
14+
}
15+
16+
declare i1 @llvm.type.test(ptr %ptr, metadata %bitset) nounwind readnone
17+
18+
define i1 @foo(ptr %p) {
19+
%x = call i1 @llvm.type.test(ptr %p, metadata !"typeid1")
20+
ret i1 %x
21+
}
22+
23+
!llvm.module.flags = !{!1, !2, !3}
24+
!0 = !{i32 0, !"typeid1"}
25+
!1 = !{i32 8, !"cf-protection-branch", i32 1}
26+
!2 = !{i32 7, !"Dwarf Version", i32 5}
27+
!3 = !{i32 2, !"Debug Info Version", i32 3}
28+
29+
30+
;.
31+
; X86_32: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [2 x ptr] [ptr @f, ptr @g], align 16
32+
; X86_32: @[[GLOB1:[0-9]+]] = private constant [0 x i8] zeroinitializer
33+
; X86_32: @f = alias [16 x i8], ptr @.cfi.jumptable
34+
; X86_32: @g = internal alias [16 x i8], getelementptr inbounds ([2 x [16 x i8]], ptr @.cfi.jumptable, i32 0, i32 1)
35+
;.
36+
; X86_64: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [2 x ptr] [ptr @f, ptr @g], align 16
37+
; X86_64: @[[GLOB1:[0-9]+]] = private constant [0 x i8] zeroinitializer
38+
; X86_64: @f = alias [16 x i8], ptr @.cfi.jumptable
39+
; X86_64: @g = internal alias [16 x i8], getelementptr inbounds ([2 x [16 x i8]], ptr @.cfi.jumptable, i64 0, i64 1)
40+
;.
41+
; X86_32-LABEL: @f.cfi(
42+
; X86_32-NEXT: ret void
43+
;
44+
;
45+
; X86_32-LABEL: @g.cfi(
46+
; X86_32-NEXT: ret void
47+
;
48+
;
49+
; X86_32-LABEL: @foo(
50+
; X86_32-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P:%.*]] to i32
51+
; X86_32-NEXT: [[TMP2:%.*]] = sub i32 ptrtoint (ptr getelementptr (i8, ptr @.cfi.jumptable, i32 16) to i32), [[TMP1]]
52+
; X86_32-NEXT: [[TMP3:%.*]] = call i32 @llvm.fshr.i32(i32 [[TMP2]], i32 [[TMP2]], i32 4)
53+
; X86_32-NEXT: [[TMP4:%.*]] = icmp ule i32 [[TMP3]], 1
54+
; X86_32-NEXT: ret i1 [[TMP4]]
55+
;
56+
;
57+
; X86_32-LABEL: @.cfi.jumptable(
58+
; X86_32-NEXT: entry:
59+
; X86_32-NEXT: call void asm sideeffect "endbr32\0Ajmp ${0:c}@plt\0A.balign 16, 0xcc\0A", "s"(ptr @f.cfi)
60+
; X86_32-NEXT: call void asm sideeffect "endbr32\0Ajmp ${0:c}@plt\0A.balign 16, 0xcc\0A", "s"(ptr @g.cfi)
61+
; X86_32-NEXT: unreachable
62+
;
63+
;
64+
; X86_64-LABEL: @f.cfi(
65+
; X86_64-NEXT: ret void
66+
;
67+
;
68+
; X86_64-LABEL: @g.cfi(
69+
; X86_64-NEXT: ret void
70+
;
71+
;
72+
; X86_64-LABEL: @foo(
73+
; X86_64-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P:%.*]] to i64
74+
; X86_64-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr getelementptr (i8, ptr @.cfi.jumptable, i64 16) to i64), [[TMP1]]
75+
; X86_64-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 4)
76+
; X86_64-NEXT: [[TMP4:%.*]] = icmp ule i64 [[TMP3]], 1
77+
; X86_64-NEXT: ret i1 [[TMP4]]
78+
;
79+
;
80+
; X86_64-LABEL: @.cfi.jumptable(
81+
; X86_64-NEXT: entry:
82+
; X86_64-NEXT: call void asm sideeffect "endbr64\0Ajmp ${0:c}@plt\0A.balign 16, 0xcc\0A", "s"(ptr @f.cfi)
83+
; X86_64-NEXT: call void asm sideeffect "endbr64\0Ajmp ${0:c}@plt\0A.balign 16, 0xcc\0A", "s"(ptr @g.cfi)
84+
; X86_64-NEXT: unreachable
85+
;
86+
;.
87+
; X86_32: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
88+
; X86_32: attributes #[[ATTR1:[0-9]+]] = { naked nocf_check noinline }
89+
; X86_32: attributes #[[ATTR2:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
90+
;.
91+
; X86_64: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
92+
; X86_64: attributes #[[ATTR1:[0-9]+]] = { naked nocf_check noinline }
93+
; X86_64: attributes #[[ATTR2:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
94+
;.
95+
; X86_32: [[META0:![0-9]+]] = !{i32 8, !"cf-protection-branch", i32 1}
96+
; X86_32: [[META1:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
97+
; X86_32: [[META2:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
98+
; X86_32: [[META3:![0-9]+]] = !{i32 0, !"typeid1"}
99+
;.
100+
; X86_64: [[META0:![0-9]+]] = !{i32 8, !"cf-protection-branch", i32 1}
101+
; X86_64: [[META1:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}
102+
; X86_64: [[META2:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
103+
; X86_64: [[META3:![0-9]+]] = !{i32 0, !"typeid1"}
104+
;.

0 commit comments

Comments
 (0)