[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / attr-target-mv-member-funcs.cpp
blobcf3ba290714e0bd0d84cec41500c27801561be0a
1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefix=WINDOWS
4 struct S {
5 int __attribute__((target("sse4.2"))) foo(int) { return 0; }
6 int __attribute__((target("arch=sandybridge"))) foo(int);
7 int __attribute__((target("arch=ivybridge"))) foo(int) { return 1; }
8 int __attribute__((target("default"))) foo(int) { return 2; }
10 S &__attribute__((target("arch=ivybridge"))) operator=(const S &) {
11 return *this;
13 S &__attribute__((target("default"))) operator=(const S &) {
14 return *this;
18 struct ConvertTo {
19 __attribute__((target("arch=ivybridge"))) operator S() const {
20 return S{};
22 __attribute__((target("default"))) operator S() const {
23 return S{};
27 int bar() {
28 S s;
29 S s2;
30 s2 = s;
32 ConvertTo C;
33 s2 = static_cast<S>(C);
35 return s.foo(0);
38 struct S2 {
39 int __attribute__((target("sse4.2"))) foo(int);
40 int __attribute__((target("arch=sandybridge"))) foo(int);
41 int __attribute__((target("arch=ivybridge"))) foo(int);
42 int __attribute__((target("default"))) foo(int);
45 int bar2() {
46 S2 s;
47 return s.foo(0);
50 int __attribute__((target("sse4.2"))) S2::foo(int) { return 0; }
51 int __attribute__((target("arch=ivybridge"))) S2::foo(int) { return 1; }
52 int __attribute__((target("default"))) S2::foo(int) { return 2; }
54 template<typename T>
55 struct templ {
56 int __attribute__((target("sse4.2"))) foo(int) { return 0; }
57 int __attribute__((target("arch=sandybridge"))) foo(int);
58 int __attribute__((target("arch=ivybridge"))) foo(int) { return 1; }
59 int __attribute__((target("default"))) foo(int) { return 2; }
62 int templ_use() {
63 templ<int> a;
64 templ<double> b;
65 return a.foo(1) + b.foo(2);
68 // LINUX: @_ZN1SaSERKS_.ifunc = weak_odr ifunc ptr (ptr, ptr), ptr @_ZN1SaSERKS_.resolver
69 // LINUX: @_ZNK9ConvertTocv1SEv.ifunc = weak_odr ifunc void (ptr), ptr @_ZNK9ConvertTocv1SEv.resolver
70 // LINUX: @_ZN1S3fooEi.ifunc = weak_odr ifunc i32 (ptr, i32), ptr @_ZN1S3fooEi.resolver
71 // LINUX: @_ZN2S23fooEi.ifunc = weak_odr ifunc i32 (ptr, i32), ptr @_ZN2S23fooEi.resolver
72 // Templates:
73 // LINUX: @_ZN5templIiE3fooEi.ifunc = weak_odr ifunc i32 (ptr, i32), ptr @_ZN5templIiE3fooEi.resolver
74 // LINUX: @_ZN5templIdE3fooEi.ifunc = weak_odr ifunc i32 (ptr, i32), ptr @_ZN5templIdE3fooEi.resolver
76 // LINUX: define{{.*}} i32 @_Z3barv()
77 // LINUX: %s = alloca %struct.S, align 1
78 // LINUX: %s2 = alloca %struct.S, align 1
79 // LINUX: %C = alloca %struct.ConvertTo, align 1
80 // LINUX: call noundef nonnull align 1 dereferenceable(1) ptr @_ZN1SaSERKS_.ifunc(ptr {{[^,]*}} %s2
81 // LINUX: call void @_ZNK9ConvertTocv1SEv.ifunc(ptr {{[^,]*}} %C)
82 // LINUX: call noundef nonnull align 1 dereferenceable(1) ptr @_ZN1SaSERKS_.ifunc(ptr {{[^,]*}} %s2
83 // LINUX: call noundef i32 @_ZN1S3fooEi.ifunc(ptr {{[^,]*}} %s, i32 noundef 0)
85 // WINDOWS: define dso_local noundef i32 @"?bar@@YAHXZ"()
86 // WINDOWS: %s = alloca %struct.S, align 1
87 // WINDOWS: %s2 = alloca %struct.S, align 1
88 // WINDOWS: %C = alloca %struct.ConvertTo, align 1
89 // WINDOWS: call noundef nonnull align 1 dereferenceable(1) ptr @"??4S@@QEAAAEAU0@AEBU0@@Z.resolver"(ptr {{[^,]*}} %s2
90 // WINDOWS: call void @"??BConvertTo@@QEBA?AUS@@XZ.resolver"(ptr {{[^,]*}} %C
91 // WINDOWS: call noundef nonnull align 1 dereferenceable(1) ptr @"??4S@@QEAAAEAU0@AEBU0@@Z.resolver"(ptr {{[^,]*}} %s2
92 // WINDOWS: call noundef i32 @"?foo@S@@QEAAHH@Z.resolver"(ptr {{[^,]*}} %s, i32 noundef 0)
94 // LINUX: define weak_odr ptr @_ZN1SaSERKS_.resolver() comdat
95 // LINUX: ret ptr @_ZN1SaSERKS_.arch_ivybridge
96 // LINUX: ret ptr @_ZN1SaSERKS_
98 // WINDOWS: define weak_odr dso_local ptr @"??4S@@QEAAAEAU0@AEBU0@@Z.resolver"(ptr %0, ptr %1)
99 // WINDOWS: call ptr @"??4S@@QEAAAEAU0@AEBU0@@Z.arch_ivybridge"
100 // WINDOWS: call ptr @"??4S@@QEAAAEAU0@AEBU0@@Z"
102 // LINUX: define weak_odr ptr @_ZNK9ConvertTocv1SEv.resolver() comdat
103 // LINUX: ret ptr @_ZNK9ConvertTocv1SEv.arch_ivybridge
104 // LINUX: ret ptr @_ZNK9ConvertTocv1SEv
106 // WINDOWS: define weak_odr dso_local void @"??BConvertTo@@QEBA?AUS@@XZ.resolver"(ptr %0, ptr %1)
107 // WINDOWS: call void @"??BConvertTo@@QEBA?AUS@@XZ.arch_ivybridge"
108 // WINDOWS: call void @"??BConvertTo@@QEBA?AUS@@XZ"
110 // LINUX: define weak_odr ptr @_ZN1S3fooEi.resolver() comdat
111 // LINUX: ret ptr @_ZN1S3fooEi.arch_sandybridge
112 // LINUX: ret ptr @_ZN1S3fooEi.arch_ivybridge
113 // LINUX: ret ptr @_ZN1S3fooEi.sse4.2
114 // LINUX: ret ptr @_ZN1S3fooEi
116 // WINDOWS: define weak_odr dso_local i32 @"?foo@S@@QEAAHH@Z.resolver"(ptr %0, i32 %1)
117 // WINDOWS: call i32 @"?foo@S@@QEAAHH@Z.arch_sandybridge"
118 // WINDOWS: call i32 @"?foo@S@@QEAAHH@Z.arch_ivybridge"
119 // WINDOWS: call i32 @"?foo@S@@QEAAHH@Z.sse4.2"
120 // WINDOWS: call i32 @"?foo@S@@QEAAHH@Z"
122 // LINUX: define{{.*}} i32 @_Z4bar2v()
123 // LINUX: call noundef i32 @_ZN2S23fooEi.ifunc
125 // WINDOWS: define dso_local noundef i32 @"?bar2@@YAHXZ"()
126 // WINDOWS: call noundef i32 @"?foo@S2@@QEAAHH@Z.resolver"
128 // LINUX: define weak_odr ptr @_ZN2S23fooEi.resolver() comdat
129 // LINUX: ret ptr @_ZN2S23fooEi.arch_sandybridge
130 // LINUX: ret ptr @_ZN2S23fooEi.arch_ivybridge
131 // LINUX: ret ptr @_ZN2S23fooEi.sse4.2
132 // LINUX: ret ptr @_ZN2S23fooEi
134 // WINDOWS: define weak_odr dso_local i32 @"?foo@S2@@QEAAHH@Z.resolver"(ptr %0, i32 %1)
135 // WINDOWS: call i32 @"?foo@S2@@QEAAHH@Z.arch_sandybridge"
136 // WINDOWS: call i32 @"?foo@S2@@QEAAHH@Z.arch_ivybridge"
137 // WINDOWS: call i32 @"?foo@S2@@QEAAHH@Z.sse4.2"
138 // WINDOWS: call i32 @"?foo@S2@@QEAAHH@Z"
140 // LINUX: define{{.*}} i32 @_ZN2S23fooEi.sse4.2(ptr {{[^,]*}} %this, i32 noundef %0)
141 // LINUX: define{{.*}} i32 @_ZN2S23fooEi.arch_ivybridge(ptr {{[^,]*}} %this, i32 noundef %0)
142 // LINUX: define{{.*}} i32 @_ZN2S23fooEi(ptr {{[^,]*}} %this, i32 noundef %0)
144 // WINDOWS: define dso_local noundef i32 @"?foo@S2@@QEAAHH@Z.sse4.2"(ptr {{[^,]*}} %this, i32 noundef %0)
145 // WINDOWS: define dso_local noundef i32 @"?foo@S2@@QEAAHH@Z.arch_ivybridge"(ptr {{[^,]*}} %this, i32 noundef %0)
146 // WINDOWS: define dso_local noundef i32 @"?foo@S2@@QEAAHH@Z"(ptr {{[^,]*}} %this, i32 noundef %0)
148 // LINUX: define{{.*}} i32 @_Z9templ_usev()
149 // LINUX: call noundef i32 @_ZN5templIiE3fooEi.ifunc
150 // LINUX: call noundef i32 @_ZN5templIdE3fooEi.ifunc
152 // WINDOWS: define dso_local noundef i32 @"?templ_use@@YAHXZ"()
153 // WINDOWS: call noundef i32 @"?foo@?$templ@H@@QEAAHH@Z.resolver"
154 // WINDOWS: call noundef i32 @"?foo@?$templ@N@@QEAAHH@Z.resolver"
156 // LINUX: define weak_odr ptr @_ZN5templIiE3fooEi.resolver() comdat
157 // LINUX: ret ptr @_ZN5templIiE3fooEi.arch_sandybridge
158 // LINUX: ret ptr @_ZN5templIiE3fooEi.arch_ivybridge
159 // LINUX: ret ptr @_ZN5templIiE3fooEi.sse4.2
160 // LINUX: ret ptr @_ZN5templIiE3fooEi
162 // WINDOWS: define weak_odr dso_local i32 @"?foo@?$templ@H@@QEAAHH@Z.resolver"(ptr %0, i32 %1)
163 // WINDOWS: call i32 @"?foo@?$templ@H@@QEAAHH@Z.arch_sandybridge"
164 // WINDOWS: call i32 @"?foo@?$templ@H@@QEAAHH@Z.arch_ivybridge"
165 // WINDOWS: call i32 @"?foo@?$templ@H@@QEAAHH@Z.sse4.2"
166 // WINDOWS: call i32 @"?foo@?$templ@H@@QEAAHH@Z"
168 // LINUX: define weak_odr ptr @_ZN5templIdE3fooEi.resolver() comdat
169 // LINUX: ret ptr @_ZN5templIdE3fooEi.arch_sandybridge
170 // LINUX: ret ptr @_ZN5templIdE3fooEi.arch_ivybridge
171 // LINUX: ret ptr @_ZN5templIdE3fooEi.sse4.2
172 // LINUX: ret ptr @_ZN5templIdE3fooEi
174 // WINDOWS: define weak_odr dso_local i32 @"?foo@?$templ@N@@QEAAHH@Z.resolver"(ptr %0, i32 %1) comdat
175 // WINDOWS: call i32 @"?foo@?$templ@N@@QEAAHH@Z.arch_sandybridge"
176 // WINDOWS: call i32 @"?foo@?$templ@N@@QEAAHH@Z.arch_ivybridge"
177 // WINDOWS: call i32 @"?foo@?$templ@N@@QEAAHH@Z.sse4.2"
178 // WINDOWS: call i32 @"?foo@?$templ@N@@QEAAHH@Z"
180 // LINUX: define linkonce_odr noundef i32 @_ZN1S3fooEi.sse4.2(ptr {{[^,]*}} %this, i32 noundef %0)
181 // LINUX: ret i32 0
183 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@S@@QEAAHH@Z.sse4.2"(ptr {{[^,]*}} %this, i32 noundef %0)
184 // WINDOWS: ret i32 0
186 // LINUX: declare noundef i32 @_ZN1S3fooEi.arch_sandybridge(ptr {{[^,]*}}, i32 noundef)
188 // WINDOWS: declare dso_local noundef i32 @"?foo@S@@QEAAHH@Z.arch_sandybridge"(ptr {{[^,]*}}, i32 noundef)
190 // LINUX: define linkonce_odr noundef i32 @_ZN1S3fooEi.arch_ivybridge(ptr {{[^,]*}} %this, i32 noundef %0)
191 // LINUX: ret i32 1
193 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@S@@QEAAHH@Z.arch_ivybridge"(ptr {{[^,]*}} %this, i32 noundef %0)
194 // WINDOWS: ret i32 1
196 // LINUX: define linkonce_odr noundef i32 @_ZN1S3fooEi(ptr {{[^,]*}} %this, i32 noundef %0)
197 // LINUX: ret i32 2
199 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@S@@QEAAHH@Z"(ptr {{[^,]*}} %this, i32 noundef %0)
200 // WINDOWS: ret i32 2
202 // LINUX: define linkonce_odr noundef i32 @_ZN5templIiE3fooEi.sse4.2
203 // LINUX: declare noundef i32 @_ZN5templIiE3fooEi.arch_sandybridge
204 // LINUX: define linkonce_odr noundef i32 @_ZN5templIiE3fooEi.arch_ivybridge
205 // LINUX: define linkonce_odr noundef i32 @_ZN5templIiE3fooEi
207 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@H@@QEAAHH@Z.sse4.2"
208 // WINDOWS: declare dso_local noundef i32 @"?foo@?$templ@H@@QEAAHH@Z.arch_sandybridge"
209 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@H@@QEAAHH@Z.arch_ivybridge"
210 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@H@@QEAAHH@Z"
212 // LINUX: define linkonce_odr noundef i32 @_ZN5templIdE3fooEi.sse4.2
213 // LINUX: declare noundef i32 @_ZN5templIdE3fooEi.arch_sandybridge
214 // LINUX: define linkonce_odr noundef i32 @_ZN5templIdE3fooEi.arch_ivybridge
215 // LINUX: define linkonce_odr noundef i32 @_ZN5templIdE3fooEi
217 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@N@@QEAAHH@Z.sse4.2"
218 // WINDOWS: declare dso_local noundef i32 @"?foo@?$templ@N@@QEAAHH@Z.arch_sandybridge"
219 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@N@@QEAAHH@Z.arch_ivybridge"
220 // WINDOWS: define linkonce_odr dso_local noundef i32 @"?foo@?$templ@N@@QEAAHH@Z"