1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X86-64
2 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
3 // RUN: %clang_cc1 -triple armv7-linux-gnu -target-abi apcs-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
5 // CHECK-NOT: @sp = common global
7 #if defined(__x86_64__)
8 register unsigned long current_stack_pointer
asm("rsp");
10 register unsigned long current_stack_pointer
asm("sp");
18 // Testing pointer types as well
19 #if defined(__x86_64__)
20 register struct p4_Thread
*p4TH
asm("rsp");
22 register struct p4_Thread
*p4TH
asm("sp");
25 // CHECK: define{{.*}} i[[bits:[0-9]+]] @get_stack_pointer_addr()
26 // CHECK: [[ret:%[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
27 // CHECK: ret i[[bits]] [[ret]]
28 unsigned long get_stack_pointer_addr(void) {
29 return current_stack_pointer
;
31 // CHECK: declare{{.*}} i[[bits]] @llvm.read_register.i[[bits]](metadata)
33 // CHECK: define{{.*}} void @set_stack_pointer_addr(i[[bits]] noundef %addr) #0 {
34 // CHECK: [[sto:%[0-9]+]] = load i[[bits]], ptr %
35 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] [[sto]])
37 void set_stack_pointer_addr(unsigned long addr
) {
38 current_stack_pointer
= addr
;
40 // CHECK: declare{{.*}} void @llvm.write_register.i[[bits]](metadata, i[[bits]])
42 // CHECK: define {{.*}}@fn1
44 return (*p4TH
).word
.len
;
46 // CHECK: %[[regr:[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
47 // CHECK: inttoptr i[[bits]] %[[regr]] to ptr
49 // CHECK: define {{.*}}@fn2
50 void fn2(struct p4_Thread
*val
) {
53 // CHECK: %[[regw:[0-9]+]] = ptrtoint ptr %{{.*}} to i[[bits]]
54 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] %[[regw]])
56 // CHECK-X86-64: !llvm.named.register.rsp = !{!0}
57 // CHECK-X86-64: !0 = !{!"rsp"}
58 // CHECK-ARM: !llvm.named.register.sp = !{!0}
59 // CHECK-ARM: !0 = !{!"sp"}