xref: /llvm-project/clang/test/CodeGen/X86/cet-builtins.c (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1 // RUN: %clang_cc1 -ffreestanding %s -triple=i386-unknown-unknown -target-feature +shstk -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=I386 --check-prefix=CHECK
2 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +shstk  -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=X86_64  --check-prefix=CHECK
3 
4 #include <immintrin.h>
5 
test_incsspd(int a)6 void test_incsspd(int a) {
7   // CHECK-LABEL: @test_incsspd
8   // CHECK:       call void @llvm.x86.incsspd(i32 %{{[0-9]+}})
9   _incsspd(a);
10 }
11 
12 #ifdef __x86_64__
test_incsspq(int a)13 void test_incsspq(int a) {
14   // X86_64-LABEL: @test_incsspq
15   // X86_64:       call void @llvm.x86.incsspq(i64 %{{[a-z0-9.]+}})
16   _incsspq(a);
17 }
18 
test_inc_ssp(unsigned int a)19 void test_inc_ssp(unsigned int a) {
20   // X86_64-LABEL: @test_inc_ssp
21   // X86_64:       call void @llvm.x86.incsspq(i64 %{{[a-z0-9.]+}})
22   _inc_ssp(a);
23 }
24 #else
25 
test_inc_ssp(unsigned int a)26 void test_inc_ssp(unsigned int a) {
27   // I386-LABEL: @test_inc_ssp
28   // I386:       call void @llvm.x86.incsspd(i32 %{{[0-9]+}})
29   _inc_ssp(a);
30 }
31 
32 #endif
33 
test_rdsspd(unsigned int a)34 unsigned int test_rdsspd(unsigned int a) {
35   // CHECK-LABEL: @test_rdsspd
36   // CHECK:       call i32 @llvm.x86.rdsspd(i32 %{{[a-z0-9.]+}})
37   return _rdsspd(a);
38 }
39 
test_rdsspd_i32(void)40 unsigned int test_rdsspd_i32(void) {
41   // CHECK-LABEL: @test_rdsspd_i32
42   // CHECK:       call i32 @llvm.x86.rdsspd(i32 %{{[a-z0-9.]+}})
43   return _rdsspd_i32();
44 }
45 
46 #ifdef __x86_64__
test_rdsspq(unsigned long long a)47 unsigned long long test_rdsspq(unsigned long long a) {
48   // X86_64-LABEL: @test_rdsspq
49   // X86_64:       call i64 @llvm.x86.rdsspq(i64 %{{[a-z0-9.]+}})
50   return _rdsspq(a);
51 }
52 
test_rdsspq_i64(void)53 unsigned long long test_rdsspq_i64(void) {
54   // X86_64-LABEL: @test_rdsspq_i64
55   // X86_64:       call i64 @llvm.x86.rdsspq(i64 %{{[a-z0-9.]+}})
56   return _rdsspq_i64();
57 }
58 
test_get_ssp(void)59 unsigned long long test_get_ssp(void) {
60   // X86_64-LABEL: @test_get_ssp
61   // X86_64:       call i64 @llvm.x86.rdsspq(i64 0)
62   return _get_ssp();
63 }
64 
65 #else
66 
test_get_ssp(void)67 unsigned int test_get_ssp(void) {
68   // I386-LABEL: @test_get_ssp
69   // I386:       call i32 @llvm.x86.rdsspd(i32 0)
70   return _get_ssp();
71 }
72 
73 #endif
74 
test_saveprevssp(void)75 void  test_saveprevssp(void) {
76   // CHECK-LABEL: @test_saveprevssp
77   // CHECK:       call void @llvm.x86.saveprevssp()
78   _saveprevssp();
79 }
80 
test_rstorssp(void * __p)81 void test_rstorssp(void * __p) {
82   // CHECK-LABEL: @test_rstorssp
83   // CHECK:       call void @llvm.x86.rstorssp(ptr %{{[a-z0-9.]+}})
84   _rstorssp(__p);
85 }
86 
test_wrssd(unsigned int __a,void * __p)87 void test_wrssd(unsigned int __a, void * __p) {
88   // CHECK-LABEL: @test_wrssd
89   // CHECK:       call void @llvm.x86.wrssd(i32 %{{[a-z0-9.]+}}, ptr %{{[a-z0-9.]+}})
90   _wrssd(__a, __p);
91 }
92 
93 #ifdef __x86_64__
test_wrssq(unsigned long long __a,void * __p)94 void test_wrssq(unsigned long long __a, void * __p) {
95   // X86_64-LABEL: @test_wrssq
96   // X86_64:       call void @llvm.x86.wrssq(i64 %{{[a-z0-9.]+}}, ptr %{{[a-z0-9.]+}})
97   _wrssq(__a, __p);
98 }
99 #endif
100 
test_wrussd(unsigned int __a,void * __p)101 void test_wrussd(unsigned int __a, void * __p) {
102   // CHECK-LABEL: @test_wrussd
103   // CHECK:       call void @llvm.x86.wrussd(i32 %{{[a-z0-9.]+}}, ptr %{{[a-z0-9.]+}})
104   _wrussd(__a, __p);
105 }
106 
107 #ifdef __x86_64__
test_wrussq(unsigned long long __a,void * __p)108 void test_wrussq(unsigned long long __a, void * __p) {
109   // X86_64-LABEL: @test_wrussq
110   // X86_64:       call void @llvm.x86.wrussq(i64 %{{[a-z0-9.]+}}, ptr %{{[a-z0-9.]+}})
111   _wrussq(__a, __p);
112 }
113 #endif
114 
test_setssbsy(void)115 void test_setssbsy(void) {
116   // CHECK-LABEL: @test_setssbsy
117   // CHECK:       call void @llvm.x86.setssbsy()
118   _setssbsy();
119 }
120 
test_clrssbsy(void * __p)121 void test_clrssbsy(void * __p) {
122   // CHECK-LABEL: @test_clrssbsy
123   // CHECK:       call void @llvm.x86.clrssbsy(ptr %{{[a-z0-9.]+}})
124   _clrssbsy(__p);
125 }
126