1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X64,ALL
2 // RUN: %clang_cc1 -no-opaque-pointers -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X86,ALL
3
4 struct Foo {
5 int * __ptr32 p32;
6 int * __ptr64 p64;
7 };
8 void use_foo(struct Foo *f);
test_sign_ext(struct Foo * f,int * __ptr32 __sptr i)9 void test_sign_ext(struct Foo *f, int * __ptr32 __sptr i) {
10 // X64-LABEL: define dso_local void @test_sign_ext({{.*}}i32 addrspace(270)* noundef %i)
11 // X86-LABEL: define dso_local void @test_sign_ext(%struct.Foo* noundef %f, i32* noundef %i)
12 // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
13 // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
14 f->p64 = i;
15 use_foo(f);
16 }
test_zero_ext(struct Foo * f,int * __ptr32 __uptr i)17 void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
18 // X64-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* noundef %i)
19 // X86-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* noundef %i)
20 // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
21 // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
22 f->p64 = i;
23 use_foo(f);
24 }
test_trunc(struct Foo * f,int * __ptr64 i)25 void test_trunc(struct Foo *f, int * __ptr64 i) {
26 // X64-LABEL: define dso_local void @test_trunc(%struct.Foo* noundef %f, i32* noundef %i)
27 // X86-LABEL: define dso_local void @test_trunc({{.*}}i32 addrspace(272)* noundef %i)
28 // X64: %{{.+}} = addrspacecast i32* %i to i32 addrspace(270)*
29 // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %i to i32*
30 f->p32 = i;
31 use_foo(f);
32 }
test_noop(struct Foo * f,int * __ptr32 i)33 void test_noop(struct Foo *f, int * __ptr32 i) {
34 // X64-LABEL: define dso_local void @test_noop({{.*}}i32 addrspace(270)* noundef %i)
35 // X86-LABEL: define dso_local void @test_noop({{.*}}i32* noundef %i)
36 // X64-NOT: addrspacecast
37 // X86-NOT: addrspacecast
38 f->p32 = i;
39 use_foo(f);
40 }
41
test_other(struct Foo * f,int * i)42 void test_other(struct Foo *f, __attribute__((address_space(10))) int *i) {
43 // X64-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* noundef %i)
44 // X86-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* noundef %i)
45 // X64: %{{.+}} = addrspacecast i32 addrspace(10)* %i to i32 addrspace(270)*
46 // X86: %{{.+}} = addrspacecast i32 addrspace(10)* %i to i32*
47 f->p32 = (int * __ptr32)i;
48 use_foo(f);
49 }
50
test_compare1(int * __ptr32 __uptr i,int * __ptr64 j)51 int test_compare1(int *__ptr32 __uptr i, int *__ptr64 j) {
52 // ALL-LABEL: define dso_local i32 @test_compare1
53 // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(271)*
54 // X64: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
55 // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32 addrspace(271)*
56 // X86: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
57 return (i == j);
58 }
59
test_compare2(int * __ptr32 __sptr i,int * __ptr64 j)60 int test_compare2(int *__ptr32 __sptr i, int *__ptr64 j) {
61 // ALL-LABEL: define dso_local i32 @test_compare2
62 // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(270)*
63 // X64: %cmp = icmp eq i32 addrspace(270)* %{{.+}}, %i
64 // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32*
65 // X86: %cmp = icmp eq i32* %{{.+}}, %i
66 return (i == j);
67 }
68
test_compare3(int * __ptr32 __uptr i,int * __ptr64 j)69 int test_compare3(int *__ptr32 __uptr i, int *__ptr64 j) {
70 // ALL-LABEL: define dso_local i32 @test_compare3
71 // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
72 // X64: %cmp = icmp eq i32* %{{.+}}, %j
73 // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
74 // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
75 return (j == i);
76 }
77
test_compare4(int * __ptr32 __sptr i,int * __ptr64 j)78 int test_compare4(int *__ptr32 __sptr i, int *__ptr64 j) {
79 // ALL-LABEL: define dso_local i32 @test_compare4
80 // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
81 // X64: %cmp = icmp eq i32* %{{.+}}, %j
82 // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
83 // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
84 return (j == i);
85 }
86