1 //===----------- Triple.cpp - Triple unit tests ---------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/ADT/Triple.h"
10 #include "llvm/Support/VersionTuple.h"
11 #include "gtest/gtest.h"
12
13 using namespace llvm;
14
15 namespace {
16
TEST(TripleTest,BasicParsing)17 TEST(TripleTest, BasicParsing) {
18 Triple T;
19
20 T = Triple("");
21 EXPECT_EQ("", T.getArchName().str());
22 EXPECT_EQ("", T.getVendorName().str());
23 EXPECT_EQ("", T.getOSName().str());
24 EXPECT_EQ("", T.getEnvironmentName().str());
25
26 T = Triple("-");
27 EXPECT_EQ("", T.getArchName().str());
28 EXPECT_EQ("", T.getVendorName().str());
29 EXPECT_EQ("", T.getOSName().str());
30 EXPECT_EQ("", T.getEnvironmentName().str());
31
32 T = Triple("--");
33 EXPECT_EQ("", T.getArchName().str());
34 EXPECT_EQ("", T.getVendorName().str());
35 EXPECT_EQ("", T.getOSName().str());
36 EXPECT_EQ("", T.getEnvironmentName().str());
37
38 T = Triple("---");
39 EXPECT_EQ("", T.getArchName().str());
40 EXPECT_EQ("", T.getVendorName().str());
41 EXPECT_EQ("", T.getOSName().str());
42 EXPECT_EQ("", T.getEnvironmentName().str());
43
44 T = Triple("----");
45 EXPECT_EQ("", T.getArchName().str());
46 EXPECT_EQ("", T.getVendorName().str());
47 EXPECT_EQ("", T.getOSName().str());
48 EXPECT_EQ("-", T.getEnvironmentName().str());
49
50 T = Triple("a");
51 EXPECT_EQ("a", T.getArchName().str());
52 EXPECT_EQ("", T.getVendorName().str());
53 EXPECT_EQ("", T.getOSName().str());
54 EXPECT_EQ("", T.getEnvironmentName().str());
55
56 T = Triple("a-b");
57 EXPECT_EQ("a", T.getArchName().str());
58 EXPECT_EQ("b", T.getVendorName().str());
59 EXPECT_EQ("", T.getOSName().str());
60 EXPECT_EQ("", T.getEnvironmentName().str());
61
62 T = Triple("a-b-c");
63 EXPECT_EQ("a", T.getArchName().str());
64 EXPECT_EQ("b", T.getVendorName().str());
65 EXPECT_EQ("c", T.getOSName().str());
66 EXPECT_EQ("", T.getEnvironmentName().str());
67
68 T = Triple("a-b-c-d");
69 EXPECT_EQ("a", T.getArchName().str());
70 EXPECT_EQ("b", T.getVendorName().str());
71 EXPECT_EQ("c", T.getOSName().str());
72 EXPECT_EQ("d", T.getEnvironmentName().str());
73 }
74
TEST(TripleTest,ParsedIDs)75 TEST(TripleTest, ParsedIDs) {
76 Triple T;
77
78 T = Triple("i386-apple-darwin");
79 EXPECT_EQ(Triple::x86, T.getArch());
80 EXPECT_EQ(Triple::Apple, T.getVendor());
81 EXPECT_EQ(Triple::Darwin, T.getOS());
82 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
83
84 T = Triple("i386-pc-elfiamcu");
85 EXPECT_EQ(Triple::x86, T.getArch());
86 EXPECT_EQ(Triple::PC, T.getVendor());
87 EXPECT_EQ(Triple::ELFIAMCU, T.getOS());
88 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
89
90 T = Triple("i386-pc-contiki-unknown");
91 EXPECT_EQ(Triple::x86, T.getArch());
92 EXPECT_EQ(Triple::PC, T.getVendor());
93 EXPECT_EQ(Triple::Contiki, T.getOS());
94 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
95
96 T = Triple("i386-pc-hurd-gnu");
97 EXPECT_EQ(Triple::x86, T.getArch());
98 EXPECT_EQ(Triple::PC, T.getVendor());
99 EXPECT_EQ(Triple::Hurd, T.getOS());
100 EXPECT_EQ(Triple::GNU, T.getEnvironment());
101
102 T = Triple("x86_64-pc-linux-gnu");
103 EXPECT_EQ(Triple::x86_64, T.getArch());
104 EXPECT_EQ(Triple::PC, T.getVendor());
105 EXPECT_EQ(Triple::Linux, T.getOS());
106 EXPECT_EQ(Triple::GNU, T.getEnvironment());
107
108 T = Triple("x86_64-pc-linux-musl");
109 EXPECT_EQ(Triple::x86_64, T.getArch());
110 EXPECT_EQ(Triple::PC, T.getVendor());
111 EXPECT_EQ(Triple::Linux, T.getOS());
112 EXPECT_EQ(Triple::Musl, T.getEnvironment());
113
114 T = Triple("powerpc-ibm-aix");
115 EXPECT_EQ(Triple::ppc, T.getArch());
116 EXPECT_EQ(Triple::IBM, T.getVendor());
117 EXPECT_EQ(Triple::AIX, T.getOS());
118 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
119
120 T = Triple("powerpc64-ibm-aix");
121 EXPECT_EQ(Triple::ppc64, T.getArch());
122 EXPECT_EQ(Triple::IBM, T.getVendor());
123 EXPECT_EQ(Triple::AIX, T.getOS());
124 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
125
126 T = Triple("powerpc-dunno-notsure");
127 EXPECT_EQ(Triple::ppc, T.getArch());
128 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
129 EXPECT_EQ(Triple::UnknownOS, T.getOS());
130 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
131
132 T = Triple("powerpcspe-unknown-freebsd");
133 EXPECT_EQ(Triple::ppc, T.getArch());
134 EXPECT_EQ(Triple::PPCSubArch_spe, T.getSubArch());
135 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
136 EXPECT_EQ(Triple::FreeBSD, T.getOS());
137 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
138
139 T = Triple("s390x-ibm-zos");
140 EXPECT_EQ(Triple::systemz, T.getArch());
141 EXPECT_EQ(Triple::IBM, T.getVendor());
142 EXPECT_EQ(Triple::ZOS, T.getOS());
143 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
144
145 T = Triple("systemz-ibm-zos");
146 EXPECT_EQ(Triple::systemz, T.getArch());
147 EXPECT_EQ(Triple::IBM, T.getVendor());
148 EXPECT_EQ(Triple::ZOS, T.getOS());
149 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
150
151 T = Triple("arm-none-none-eabi");
152 EXPECT_EQ(Triple::arm, T.getArch());
153 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
154 EXPECT_EQ(Triple::UnknownOS, T.getOS());
155 EXPECT_EQ(Triple::EABI, T.getEnvironment());
156
157 T = Triple("arm-none-linux-musleabi");
158 EXPECT_EQ(Triple::arm, T.getArch());
159 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
160 EXPECT_EQ(Triple::Linux, T.getOS());
161 EXPECT_EQ(Triple::MuslEABI, T.getEnvironment());
162
163 T = Triple("armv6hl-none-linux-gnueabi");
164 EXPECT_EQ(Triple::arm, T.getArch());
165 EXPECT_EQ(Triple::Linux, T.getOS());
166 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
167 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
168
169 T = Triple("armv7hl-none-linux-gnueabi");
170 EXPECT_EQ(Triple::arm, T.getArch());
171 EXPECT_EQ(Triple::Linux, T.getOS());
172 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
173 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
174
175 T = Triple("amdil-unknown-unknown");
176 EXPECT_EQ(Triple::amdil, T.getArch());
177 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
178 EXPECT_EQ(Triple::UnknownOS, T.getOS());
179
180 T = Triple("amdil64-unknown-unknown");
181 EXPECT_EQ(Triple::amdil64, T.getArch());
182 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
183 EXPECT_EQ(Triple::UnknownOS, T.getOS());
184
185 T = Triple("hsail-unknown-unknown");
186 EXPECT_EQ(Triple::hsail, T.getArch());
187 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
188 EXPECT_EQ(Triple::UnknownOS, T.getOS());
189
190 T = Triple("hsail64-unknown-unknown");
191 EXPECT_EQ(Triple::hsail64, T.getArch());
192 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
193 EXPECT_EQ(Triple::UnknownOS, T.getOS());
194
195 T = Triple("sparcel-unknown-unknown");
196 EXPECT_EQ(Triple::sparcel, T.getArch());
197 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
198 EXPECT_EQ(Triple::UnknownOS, T.getOS());
199
200 T = Triple("spir-unknown-unknown");
201 EXPECT_EQ(Triple::spir, T.getArch());
202 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
203 EXPECT_EQ(Triple::UnknownOS, T.getOS());
204
205 T = Triple("spir64-unknown-unknown");
206 EXPECT_EQ(Triple::spir64, T.getArch());
207 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
208 EXPECT_EQ(Triple::UnknownOS, T.getOS());
209
210 T = Triple("x86_64-unknown-ananas");
211 EXPECT_EQ(Triple::x86_64, T.getArch());
212 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
213 EXPECT_EQ(Triple::Ananas, T.getOS());
214 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
215
216 T = Triple("x86_64-unknown-cloudabi");
217 EXPECT_EQ(Triple::x86_64, T.getArch());
218 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
219 EXPECT_EQ(Triple::CloudABI, T.getOS());
220 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
221
222 T = Triple("x86_64-unknown-fuchsia");
223 EXPECT_EQ(Triple::x86_64, T.getArch());
224 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
225 EXPECT_EQ(Triple::Fuchsia, T.getOS());
226 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
227
228 T = Triple("x86_64-unknown-hermit");
229 EXPECT_EQ(Triple::x86_64, T.getArch());
230 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
231 EXPECT_EQ(Triple::HermitCore, T.getOS());
232 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
233
234 T = Triple("wasm32-unknown-unknown");
235 EXPECT_EQ(Triple::wasm32, T.getArch());
236 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
237 EXPECT_EQ(Triple::UnknownOS, T.getOS());
238 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
239
240 T = Triple("wasm32-unknown-wasi");
241 EXPECT_EQ(Triple::wasm32, T.getArch());
242 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
243 EXPECT_EQ(Triple::WASI, T.getOS());
244 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
245
246 T = Triple("wasm64-unknown-unknown");
247 EXPECT_EQ(Triple::wasm64, T.getArch());
248 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
249 EXPECT_EQ(Triple::UnknownOS, T.getOS());
250 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
251
252 T = Triple("wasm64-unknown-wasi");
253 EXPECT_EQ(Triple::wasm64, T.getArch());
254 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
255 EXPECT_EQ(Triple::WASI, T.getOS());
256 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
257
258 T = Triple("avr-unknown-unknown");
259 EXPECT_EQ(Triple::avr, T.getArch());
260 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
261 EXPECT_EQ(Triple::UnknownOS, T.getOS());
262 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
263
264 T = Triple("avr");
265 EXPECT_EQ(Triple::avr, T.getArch());
266 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
267 EXPECT_EQ(Triple::UnknownOS, T.getOS());
268 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
269
270 T = Triple("lanai-unknown-unknown");
271 EXPECT_EQ(Triple::lanai, T.getArch());
272 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
273 EXPECT_EQ(Triple::UnknownOS, T.getOS());
274 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
275
276 T = Triple("lanai");
277 EXPECT_EQ(Triple::lanai, T.getArch());
278 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
279 EXPECT_EQ(Triple::UnknownOS, T.getOS());
280 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
281
282 T = Triple("amdgcn-mesa-mesa3d");
283 EXPECT_EQ(Triple::amdgcn, T.getArch());
284 EXPECT_EQ(Triple::Mesa, T.getVendor());
285 EXPECT_EQ(Triple::Mesa3D, T.getOS());
286 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
287
288 T = Triple("amdgcn-amd-amdhsa");
289 EXPECT_EQ(Triple::amdgcn, T.getArch());
290 EXPECT_EQ(Triple::AMD, T.getVendor());
291 EXPECT_EQ(Triple::AMDHSA, T.getOS());
292 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
293
294 T = Triple("amdgcn-amd-amdpal");
295 EXPECT_EQ(Triple::amdgcn, T.getArch());
296 EXPECT_EQ(Triple::AMD, T.getVendor());
297 EXPECT_EQ(Triple::AMDPAL, T.getOS());
298 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
299
300 T = Triple("ve-unknown-linux");
301 EXPECT_EQ(Triple::ve, T.getArch());
302 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
303 EXPECT_EQ(Triple::Linux, T.getOS());
304 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
305
306 T = Triple("csky-unknown-unknown");
307 EXPECT_EQ(Triple::csky, T.getArch());
308 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
309 EXPECT_EQ(Triple::UnknownOS, T.getOS());
310 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
311
312 T = Triple("csky-unknown-linux");
313 EXPECT_EQ(Triple::csky, T.getArch());
314 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
315 EXPECT_EQ(Triple::Linux, T.getOS());
316 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
317
318 T = Triple("riscv32-unknown-unknown");
319 EXPECT_EQ(Triple::riscv32, T.getArch());
320 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
321 EXPECT_EQ(Triple::UnknownOS, T.getOS());
322 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
323
324 T = Triple("riscv64-unknown-linux");
325 EXPECT_EQ(Triple::riscv64, T.getArch());
326 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
327 EXPECT_EQ(Triple::Linux, T.getOS());
328 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
329
330 T = Triple("riscv64-unknown-freebsd");
331 EXPECT_EQ(Triple::riscv64, T.getArch());
332 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
333 EXPECT_EQ(Triple::FreeBSD, T.getOS());
334 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
335
336 T = Triple("riscv64-suse-linux");
337 EXPECT_EQ(Triple::riscv64, T.getArch());
338 EXPECT_EQ(Triple::SUSE, T.getVendor());
339 EXPECT_EQ(Triple::Linux, T.getOS());
340 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
341
342 T = Triple("armv7hl-suse-linux-gnueabi");
343 EXPECT_EQ(Triple::arm, T.getArch());
344 EXPECT_EQ(Triple::SUSE, T.getVendor());
345 EXPECT_EQ(Triple::Linux, T.getOS());
346 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
347
348 T = Triple("i586-pc-haiku");
349 EXPECT_EQ(Triple::x86, T.getArch());
350 EXPECT_EQ(Triple::PC, T.getVendor());
351 EXPECT_EQ(Triple::Haiku, T.getOS());
352 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
353
354 T = Triple("x86_64-unknown-haiku");
355 EXPECT_EQ(Triple::x86_64, T.getArch());
356 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
357 EXPECT_EQ(Triple::Haiku, T.getOS());
358 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
359
360 T = Triple("mips-mti-linux-gnu");
361 EXPECT_EQ(Triple::mips, T.getArch());
362 EXPECT_EQ(Triple::MipsTechnologies, T.getVendor());
363 EXPECT_EQ(Triple::Linux, T.getOS());
364 EXPECT_EQ(Triple::GNU, T.getEnvironment());
365
366 T = Triple("mipsel-img-linux-gnu");
367 EXPECT_EQ(Triple::mipsel, T.getArch());
368 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
369 EXPECT_EQ(Triple::Linux, T.getOS());
370 EXPECT_EQ(Triple::GNU, T.getEnvironment());
371
372 T = Triple("mips64-mti-linux-gnu");
373 EXPECT_EQ(Triple::mips64, T.getArch());
374 EXPECT_EQ(Triple::MipsTechnologies, T.getVendor());
375 EXPECT_EQ(Triple::Linux, T.getOS());
376 EXPECT_EQ(Triple::GNU, T.getEnvironment());
377
378 T = Triple("mips64el-img-linux-gnu");
379 EXPECT_EQ(Triple::mips64el, T.getArch());
380 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
381 EXPECT_EQ(Triple::Linux, T.getOS());
382 EXPECT_EQ(Triple::GNU, T.getEnvironment());
383
384 T = Triple("mips64el-img-linux-gnuabin32");
385 EXPECT_EQ(Triple::mips64el, T.getArch());
386 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
387 EXPECT_EQ(Triple::Linux, T.getOS());
388 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
389
390 T = Triple("mips64el-unknown-linux-gnuabi64");
391 EXPECT_EQ(Triple::mips64el, T.getArch());
392 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
393 EXPECT_EQ(Triple::Linux, T.getOS());
394 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
395 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
396 T = Triple("mips64el");
397 EXPECT_EQ(Triple::mips64el, T.getArch());
398 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
399 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
400 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
401
402 T = Triple("mips64-unknown-linux-gnuabi64");
403 EXPECT_EQ(Triple::mips64, T.getArch());
404 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
405 EXPECT_EQ(Triple::Linux, T.getOS());
406 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
407 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
408 T = Triple("mips64");
409 EXPECT_EQ(Triple::mips64, T.getArch());
410 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
411 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
412 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
413
414 T = Triple("mipsisa64r6el-unknown-linux-gnuabi64");
415 EXPECT_EQ(Triple::mips64el, T.getArch());
416 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
417 EXPECT_EQ(Triple::Linux, T.getOS());
418 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
419 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
420 T = Triple("mips64r6el");
421 EXPECT_EQ(Triple::mips64el, T.getArch());
422 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
423 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
424 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
425 T = Triple("mipsisa64r6el");
426 EXPECT_EQ(Triple::mips64el, T.getArch());
427 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
428 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
429 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
430
431 T = Triple("mipsisa64r6-unknown-linux-gnuabi64");
432 EXPECT_EQ(Triple::mips64, T.getArch());
433 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
434 EXPECT_EQ(Triple::Linux, T.getOS());
435 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
436 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
437 T = Triple("mips64r6");
438 EXPECT_EQ(Triple::mips64, T.getArch());
439 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
440 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
441 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
442 T = Triple("mipsisa64r6");
443 EXPECT_EQ(Triple::mips64, T.getArch());
444 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
445 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
446 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
447
448 T = Triple("mips64el-unknown-linux-gnuabin32");
449 EXPECT_EQ(Triple::mips64el, T.getArch());
450 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
451 EXPECT_EQ(Triple::Linux, T.getOS());
452 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
453 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
454 T = Triple("mipsn32el");
455 EXPECT_EQ(Triple::mips64el, T.getArch());
456 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
457 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
458 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
459
460 T = Triple("mips64-unknown-linux-gnuabin32");
461 EXPECT_EQ(Triple::mips64, T.getArch());
462 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
463 EXPECT_EQ(Triple::Linux, T.getOS());
464 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
465 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
466 T = Triple("mipsn32");
467 EXPECT_EQ(Triple::mips64, T.getArch());
468 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
469 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
470 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
471
472 T = Triple("mipsisa64r6el-unknown-linux-gnuabin32");
473 EXPECT_EQ(Triple::mips64el, T.getArch());
474 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
475 EXPECT_EQ(Triple::Linux, T.getOS());
476 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
477 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
478 T = Triple("mipsn32r6el");
479 EXPECT_EQ(Triple::mips64el, T.getArch());
480 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
481 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
482 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
483
484 T = Triple("mipsisa64r6-unknown-linux-gnuabin32");
485 EXPECT_EQ(Triple::mips64, T.getArch());
486 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
487 EXPECT_EQ(Triple::Linux, T.getOS());
488 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
489 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
490 T = Triple("mipsn32r6");
491 EXPECT_EQ(Triple::mips64, T.getArch());
492 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
493 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
494 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
495
496 T = Triple("mipsel-unknown-linux-gnu");
497 EXPECT_EQ(Triple::mipsel, T.getArch());
498 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
499 EXPECT_EQ(Triple::Linux, T.getOS());
500 EXPECT_EQ(Triple::GNU, T.getEnvironment());
501 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
502 T = Triple("mipsel");
503 EXPECT_EQ(Triple::mipsel, T.getArch());
504 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
505 EXPECT_EQ(Triple::GNU, T.getEnvironment());
506 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
507
508 T = Triple("mips-unknown-linux-gnu");
509 EXPECT_EQ(Triple::mips, T.getArch());
510 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
511 EXPECT_EQ(Triple::Linux, T.getOS());
512 EXPECT_EQ(Triple::GNU, T.getEnvironment());
513 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
514 T = Triple("mips");
515 EXPECT_EQ(Triple::mips, T.getArch());
516 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
517 EXPECT_EQ(Triple::GNU, T.getEnvironment());
518 EXPECT_EQ(Triple::NoSubArch, T.getSubArch());
519
520 T = Triple("mipsisa32r6el-unknown-linux-gnu");
521 EXPECT_EQ(Triple::mipsel, T.getArch());
522 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
523 EXPECT_EQ(Triple::Linux, T.getOS());
524 EXPECT_EQ(Triple::GNU, T.getEnvironment());
525 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
526 T = Triple("mipsr6el");
527 EXPECT_EQ(Triple::mipsel, T.getArch());
528 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
529 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
530 T = Triple("mipsisa32r6el");
531 EXPECT_EQ(Triple::mipsel, T.getArch());
532 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
533 EXPECT_EQ(Triple::GNU, T.getEnvironment());
534 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
535
536 T = Triple("mipsisa32r6-unknown-linux-gnu");
537 EXPECT_EQ(Triple::mips, T.getArch());
538 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
539 EXPECT_EQ(Triple::Linux, T.getOS());
540 EXPECT_EQ(Triple::GNU, T.getEnvironment());
541 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
542 T = Triple("mipsr6");
543 EXPECT_EQ(Triple::mips, T.getArch());
544 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
545 EXPECT_EQ(Triple::GNU, T.getEnvironment());
546 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
547 T = Triple("mipsisa32r6");
548 EXPECT_EQ(Triple::mips, T.getArch());
549 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
550 EXPECT_EQ(Triple::GNU, T.getEnvironment());
551 EXPECT_EQ(Triple::MipsSubArch_r6, T.getSubArch());
552
553 T = Triple("arm-oe-linux-gnueabi");
554 EXPECT_EQ(Triple::arm, T.getArch());
555 EXPECT_EQ(Triple::OpenEmbedded, T.getVendor());
556 EXPECT_EQ(Triple::Linux, T.getOS());
557 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
558
559 T = Triple("aarch64-oe-linux");
560 EXPECT_EQ(Triple::aarch64, T.getArch());
561 EXPECT_EQ(Triple::OpenEmbedded, T.getVendor());
562 EXPECT_EQ(Triple::Linux, T.getOS());
563 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
564 EXPECT_TRUE(T.isArch64Bit());
565
566 T = Triple("arm64_32-apple-ios");
567 EXPECT_EQ(Triple::aarch64_32, T.getArch());
568 EXPECT_EQ(Triple::IOS, T.getOS());
569 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
570 EXPECT_TRUE(T.isArch32Bit());
571
572 T = Triple("huh");
573 EXPECT_EQ(Triple::UnknownArch, T.getArch());
574 }
575
Join(StringRef A,StringRef B,StringRef C)576 static std::string Join(StringRef A, StringRef B, StringRef C) {
577 std::string Str = std::string(A);
578 Str += '-';
579 Str += B;
580 Str += '-';
581 Str += C;
582 return Str;
583 }
584
Join(StringRef A,StringRef B,StringRef C,StringRef D)585 static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) {
586 std::string Str = std::string(A);
587 Str += '-';
588 Str += B;
589 Str += '-';
590 Str += C;
591 Str += '-';
592 Str += D;
593 return Str;
594 }
595
TEST(TripleTest,Normalization)596 TEST(TripleTest, Normalization) {
597
598 EXPECT_EQ("unknown", Triple::normalize(""));
599 EXPECT_EQ("unknown-unknown", Triple::normalize("-"));
600 EXPECT_EQ("unknown-unknown-unknown", Triple::normalize("--"));
601 EXPECT_EQ("unknown-unknown-unknown-unknown", Triple::normalize("---"));
602 EXPECT_EQ("unknown-unknown-unknown-unknown-unknown",
603 Triple::normalize("----"));
604
605 EXPECT_EQ("a", Triple::normalize("a"));
606 EXPECT_EQ("a-b", Triple::normalize("a-b"));
607 EXPECT_EQ("a-b-c", Triple::normalize("a-b-c"));
608 EXPECT_EQ("a-b-c-d", Triple::normalize("a-b-c-d"));
609
610 EXPECT_EQ("i386-b-c", Triple::normalize("i386-b-c"));
611 EXPECT_EQ("i386-a-c", Triple::normalize("a-i386-c"));
612 EXPECT_EQ("i386-a-b", Triple::normalize("a-b-i386"));
613 EXPECT_EQ("i386-a-b-c", Triple::normalize("a-b-c-i386"));
614
615 EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c"));
616 EXPECT_EQ("unknown-pc-b-c", Triple::normalize("pc-b-c"));
617 EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc"));
618 EXPECT_EQ("a-pc-b-c", Triple::normalize("a-b-c-pc"));
619
620 EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux"));
621 EXPECT_EQ("unknown-unknown-linux-b-c", Triple::normalize("linux-b-c"));
622 EXPECT_EQ("a-unknown-linux-c", Triple::normalize("a-linux-c"));
623
624 EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386"));
625 EXPECT_EQ("i386-pc-unknown", Triple::normalize("-pc-i386"));
626 EXPECT_EQ("unknown-pc-linux-c", Triple::normalize("linux-pc-c"));
627 EXPECT_EQ("unknown-pc-linux", Triple::normalize("linux-pc-"));
628
629 EXPECT_EQ("i386", Triple::normalize("i386"));
630 EXPECT_EQ("unknown-pc", Triple::normalize("pc"));
631 EXPECT_EQ("unknown-unknown-linux", Triple::normalize("linux"));
632
633 EXPECT_EQ("x86_64-unknown-linux-gnu", Triple::normalize("x86_64-gnu-linux"));
634
635 // Check that normalizing a permutated set of valid components returns a
636 // triple with the unpermuted components.
637 //
638 // We don't check every possible combination. For the set of architectures A,
639 // vendors V, operating systems O, and environments E, that would require |A|
640 // * |V| * |O| * |E| * 4! tests. Instead we check every option for any given
641 // slot and make sure it gets normalized to the correct position from every
642 // permutation. This should cover the core logic while being a tractable
643 // number of tests at (|A| + |V| + |O| + |E|) * 4!.
644 auto FirstArchType = Triple::ArchType(Triple::UnknownArch + 1);
645 auto FirstVendorType = Triple::VendorType(Triple::UnknownVendor + 1);
646 auto FirstOSType = Triple::OSType(Triple::UnknownOS + 1);
647 auto FirstEnvType = Triple::EnvironmentType(Triple::UnknownEnvironment + 1);
648 StringRef InitialC[] = {Triple::getArchTypeName(FirstArchType),
649 Triple::getVendorTypeName(FirstVendorType),
650 Triple::getOSTypeName(FirstOSType),
651 Triple::getEnvironmentTypeName(FirstEnvType)};
652 for (int Arch = FirstArchType; Arch <= Triple::LastArchType; ++Arch) {
653 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
654 C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
655 std::string E = Join(C[0], C[1], C[2]);
656 int I[] = {0, 1, 2};
657 do {
658 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
659 } while (std::next_permutation(std::begin(I), std::end(I)));
660 std::string F = Join(C[0], C[1], C[2], C[3]);
661 int J[] = {0, 1, 2, 3};
662 do {
663 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
664 } while (std::next_permutation(std::begin(J), std::end(J)));
665 }
666 for (int Vendor = FirstVendorType; Vendor <= Triple::LastVendorType;
667 ++Vendor) {
668 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
669 C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
670 std::string E = Join(C[0], C[1], C[2]);
671 int I[] = {0, 1, 2};
672 do {
673 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
674 } while (std::next_permutation(std::begin(I), std::end(I)));
675 std::string F = Join(C[0], C[1], C[2], C[3]);
676 int J[] = {0, 1, 2, 3};
677 do {
678 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
679 } while (std::next_permutation(std::begin(J), std::end(J)));
680 }
681 for (int OS = FirstOSType; OS <= Triple::LastOSType; ++OS) {
682 if (OS == Triple::Win32)
683 continue;
684 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
685 C[2] = Triple::getOSTypeName(Triple::OSType(OS));
686 std::string E = Join(C[0], C[1], C[2]);
687 int I[] = {0, 1, 2};
688 do {
689 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
690 } while (std::next_permutation(std::begin(I), std::end(I)));
691 std::string F = Join(C[0], C[1], C[2], C[3]);
692 int J[] = {0, 1, 2, 3};
693 do {
694 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
695 } while (std::next_permutation(std::begin(J), std::end(J)));
696 }
697 for (int Env = FirstEnvType; Env <= Triple::LastEnvironmentType; ++Env) {
698 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
699 C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
700 std::string F = Join(C[0], C[1], C[2], C[3]);
701 int J[] = {0, 1, 2, 3};
702 do {
703 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
704 } while (std::next_permutation(std::begin(J), std::end(J)));
705 }
706
707 // Various real-world funky triples. The value returned by GCC's config.sub
708 // is given in the comment.
709 EXPECT_EQ("i386-unknown-windows-gnu",
710 Triple::normalize("i386-mingw32")); // i386-pc-mingw32
711 EXPECT_EQ("x86_64-unknown-linux-gnu",
712 Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
713 EXPECT_EQ("i486-unknown-linux-gnu",
714 Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
715 EXPECT_EQ("i386-redhat-linux",
716 Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
717 EXPECT_EQ("i686-unknown-linux",
718 Triple::normalize("i686-linux")); // i686-pc-linux-gnu
719 EXPECT_EQ("arm-none-unknown-eabi",
720 Triple::normalize("arm-none-eabi")); // arm-none-eabi
721 EXPECT_EQ("ve-unknown-linux",
722 Triple::normalize("ve-linux")); // ve-linux
723 EXPECT_EQ("wasm32-unknown-wasi",
724 Triple::normalize("wasm32-wasi")); // wasm32-unknown-wasi
725 EXPECT_EQ("wasm64-unknown-wasi",
726 Triple::normalize("wasm64-wasi")); // wasm64-unknown-wasi
727 }
728
TEST(TripleTest,MutateName)729 TEST(TripleTest, MutateName) {
730 Triple T;
731 EXPECT_EQ(Triple::UnknownArch, T.getArch());
732 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
733 EXPECT_EQ(Triple::UnknownOS, T.getOS());
734 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
735
736 T.setArchName("i386");
737 EXPECT_EQ(Triple::x86, T.getArch());
738 EXPECT_EQ("i386--", T.getTriple());
739
740 T.setVendorName("pc");
741 EXPECT_EQ(Triple::x86, T.getArch());
742 EXPECT_EQ(Triple::PC, T.getVendor());
743 EXPECT_EQ("i386-pc-", T.getTriple());
744
745 T.setOSName("linux");
746 EXPECT_EQ(Triple::x86, T.getArch());
747 EXPECT_EQ(Triple::PC, T.getVendor());
748 EXPECT_EQ(Triple::Linux, T.getOS());
749 EXPECT_EQ("i386-pc-linux", T.getTriple());
750
751 T.setEnvironmentName("gnu");
752 EXPECT_EQ(Triple::x86, T.getArch());
753 EXPECT_EQ(Triple::PC, T.getVendor());
754 EXPECT_EQ(Triple::Linux, T.getOS());
755 EXPECT_EQ("i386-pc-linux-gnu", T.getTriple());
756
757 T.setOSName("freebsd");
758 EXPECT_EQ(Triple::x86, T.getArch());
759 EXPECT_EQ(Triple::PC, T.getVendor());
760 EXPECT_EQ(Triple::FreeBSD, T.getOS());
761 EXPECT_EQ("i386-pc-freebsd-gnu", T.getTriple());
762
763 T.setOSAndEnvironmentName("darwin");
764 EXPECT_EQ(Triple::x86, T.getArch());
765 EXPECT_EQ(Triple::PC, T.getVendor());
766 EXPECT_EQ(Triple::Darwin, T.getOS());
767 EXPECT_EQ("i386-pc-darwin", T.getTriple());
768 }
769
TEST(TripleTest,BitWidthPredicates)770 TEST(TripleTest, BitWidthPredicates) {
771 Triple T;
772 EXPECT_FALSE(T.isArch16Bit());
773 EXPECT_FALSE(T.isArch32Bit());
774 EXPECT_FALSE(T.isArch64Bit());
775
776 T.setArch(Triple::arm);
777 EXPECT_FALSE(T.isArch16Bit());
778 EXPECT_TRUE(T.isArch32Bit());
779 EXPECT_FALSE(T.isArch64Bit());
780
781 T.setArch(Triple::hexagon);
782 EXPECT_FALSE(T.isArch16Bit());
783 EXPECT_TRUE(T.isArch32Bit());
784 EXPECT_FALSE(T.isArch64Bit());
785
786 T.setArch(Triple::mips);
787 EXPECT_FALSE(T.isArch16Bit());
788 EXPECT_TRUE(T.isArch32Bit());
789 EXPECT_FALSE(T.isArch64Bit());
790
791 T.setArch(Triple::mips64);
792 EXPECT_FALSE(T.isArch16Bit());
793 EXPECT_FALSE(T.isArch32Bit());
794 EXPECT_TRUE(T.isArch64Bit());
795
796 T.setArch(Triple::msp430);
797 EXPECT_TRUE(T.isArch16Bit());
798 EXPECT_FALSE(T.isArch32Bit());
799 EXPECT_FALSE(T.isArch64Bit());
800
801 T.setArch(Triple::ppc);
802 EXPECT_FALSE(T.isArch16Bit());
803 EXPECT_TRUE(T.isArch32Bit());
804 EXPECT_FALSE(T.isArch64Bit());
805
806 T.setArch(Triple::ppc64);
807 EXPECT_FALSE(T.isArch16Bit());
808 EXPECT_FALSE(T.isArch32Bit());
809 EXPECT_TRUE(T.isArch64Bit());
810
811 T.setArch(Triple::x86);
812 EXPECT_FALSE(T.isArch16Bit());
813 EXPECT_TRUE(T.isArch32Bit());
814 EXPECT_FALSE(T.isArch64Bit());
815
816 T.setArch(Triple::x86_64);
817 EXPECT_FALSE(T.isArch16Bit());
818 EXPECT_FALSE(T.isArch32Bit());
819 EXPECT_TRUE(T.isArch64Bit());
820
821 T.setArch(Triple::amdil);
822 EXPECT_FALSE(T.isArch16Bit());
823 EXPECT_TRUE(T.isArch32Bit());
824 EXPECT_FALSE(T.isArch64Bit());
825
826 T.setArch(Triple::amdil64);
827 EXPECT_FALSE(T.isArch16Bit());
828 EXPECT_FALSE(T.isArch32Bit());
829 EXPECT_TRUE(T.isArch64Bit());
830
831 T.setArch(Triple::hsail);
832 EXPECT_FALSE(T.isArch16Bit());
833 EXPECT_TRUE(T.isArch32Bit());
834 EXPECT_FALSE(T.isArch64Bit());
835
836 T.setArch(Triple::hsail64);
837 EXPECT_FALSE(T.isArch16Bit());
838 EXPECT_FALSE(T.isArch32Bit());
839 EXPECT_TRUE(T.isArch64Bit());
840
841 T.setArch(Triple::spir);
842 EXPECT_FALSE(T.isArch16Bit());
843 EXPECT_TRUE(T.isArch32Bit());
844 EXPECT_FALSE(T.isArch64Bit());
845
846 T.setArch(Triple::spir64);
847 EXPECT_FALSE(T.isArch16Bit());
848 EXPECT_FALSE(T.isArch32Bit());
849 EXPECT_TRUE(T.isArch64Bit());
850
851 T.setArch(Triple::sparc);
852 EXPECT_FALSE(T.isArch16Bit());
853 EXPECT_TRUE(T.isArch32Bit());
854 EXPECT_FALSE(T.isArch64Bit());
855
856 T.setArch(Triple::sparcel);
857 EXPECT_FALSE(T.isArch16Bit());
858 EXPECT_TRUE(T.isArch32Bit());
859 EXPECT_FALSE(T.isArch64Bit());
860
861 T.setArch(Triple::sparcv9);
862 EXPECT_FALSE(T.isArch16Bit());
863 EXPECT_FALSE(T.isArch32Bit());
864 EXPECT_TRUE(T.isArch64Bit());
865
866 T.setArch(Triple::wasm32);
867 EXPECT_FALSE(T.isArch16Bit());
868 EXPECT_TRUE(T.isArch32Bit());
869 EXPECT_FALSE(T.isArch64Bit());
870
871 T.setArch(Triple::wasm64);
872 EXPECT_FALSE(T.isArch16Bit());
873 EXPECT_FALSE(T.isArch32Bit());
874 EXPECT_TRUE(T.isArch64Bit());
875
876 T.setArch(Triple::avr);
877 EXPECT_TRUE(T.isArch16Bit());
878 EXPECT_FALSE(T.isArch32Bit());
879 EXPECT_FALSE(T.isArch64Bit());
880
881 T.setArch(Triple::lanai);
882 EXPECT_FALSE(T.isArch16Bit());
883 EXPECT_TRUE(T.isArch32Bit());
884 EXPECT_FALSE(T.isArch64Bit());
885
886 T.setArch(Triple::riscv32);
887 EXPECT_FALSE(T.isArch16Bit());
888 EXPECT_TRUE(T.isArch32Bit());
889 EXPECT_FALSE(T.isArch64Bit());
890 EXPECT_TRUE(T.isRISCV());
891
892 T.setArch(Triple::riscv64);
893 EXPECT_FALSE(T.isArch16Bit());
894 EXPECT_FALSE(T.isArch32Bit());
895 EXPECT_TRUE(T.isArch64Bit());
896 EXPECT_TRUE(T.isRISCV());
897
898 T.setArch(Triple::csky);
899 EXPECT_FALSE(T.isArch16Bit());
900 EXPECT_TRUE(T.isArch32Bit());
901 EXPECT_FALSE(T.isArch64Bit());
902 EXPECT_TRUE(T.isCSKY());
903 }
904
TEST(TripleTest,BitWidthArchVariants)905 TEST(TripleTest, BitWidthArchVariants) {
906 Triple T;
907 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
908 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
909
910 T.setArch(Triple::UnknownArch);
911 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
912 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
913
914 T.setArch(Triple::mips);
915 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
916 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
917
918 T.setArch(Triple::mipsel);
919 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
920 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
921
922 T.setArch(Triple::ppc);
923 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
924 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
925
926 T.setArch(Triple::nvptx);
927 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
928 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
929
930 T.setArch(Triple::sparc);
931 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
932 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
933
934 T.setArch(Triple::x86);
935 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
936 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
937
938 T.setArch(Triple::mips64);
939 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
940 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
941
942 T.setArch(Triple::mips64el);
943 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
944 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
945
946 T.setArch(Triple::ppc64);
947 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
948 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
949
950 T.setArch(Triple::nvptx64);
951 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
952 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
953
954 T.setArch(Triple::sparcv9);
955 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
956 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
957
958 T.setArch(Triple::x86_64);
959 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
960 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
961
962 T.setArch(Triple::amdil);
963 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
964 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
965
966 T.setArch(Triple::amdil64);
967 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
968 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
969
970 T.setArch(Triple::hsail);
971 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
972 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
973
974 T.setArch(Triple::hsail64);
975 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
976 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
977
978 T.setArch(Triple::spir);
979 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
980 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
981
982 T.setArch(Triple::spir64);
983 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
984 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
985
986 T.setArch(Triple::wasm32);
987 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
988 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
989
990 T.setArch(Triple::wasm64);
991 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
992 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
993
994 T.setArch(Triple::riscv32);
995 EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch());
996 EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch());
997
998 T.setArch(Triple::riscv64);
999 EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch());
1000 EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch());
1001
1002 T.setArch(Triple::csky);
1003 EXPECT_EQ(Triple::csky, T.get32BitArchVariant().getArch());
1004 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
1005
1006 T.setArch(Triple::thumbeb);
1007 EXPECT_EQ(Triple::thumbeb, T.get32BitArchVariant().getArch());
1008 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
1009
1010 T.setArch(Triple::thumb);
1011 EXPECT_EQ(Triple::thumb, T.get32BitArchVariant().getArch());
1012 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
1013
1014 T.setArch(Triple::aarch64);
1015 EXPECT_EQ(Triple::arm, T.get32BitArchVariant().getArch());
1016 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
1017
1018 T.setArch(Triple::aarch64_be);
1019 EXPECT_EQ(Triple::armeb, T.get32BitArchVariant().getArch());
1020 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
1021
1022 T.setArch(Triple::renderscript32);
1023 EXPECT_EQ(Triple::renderscript32, T.get32BitArchVariant().getArch());
1024 EXPECT_EQ(Triple::renderscript64, T.get64BitArchVariant().getArch());
1025
1026 T.setArch(Triple::renderscript64);
1027 EXPECT_EQ(Triple::renderscript32, T.get32BitArchVariant().getArch());
1028 EXPECT_EQ(Triple::renderscript64, T.get64BitArchVariant().getArch());
1029
1030 T.setArch(Triple::le32);
1031 EXPECT_EQ(Triple::le32, T.get32BitArchVariant().getArch());
1032 EXPECT_EQ(Triple::le64, T.get64BitArchVariant().getArch());
1033
1034 T.setArch(Triple::le64);
1035 EXPECT_EQ(Triple::le32, T.get32BitArchVariant().getArch());
1036 EXPECT_EQ(Triple::le64, T.get64BitArchVariant().getArch());
1037
1038 T.setArch(Triple::armeb);
1039 EXPECT_EQ(Triple::armeb, T.get32BitArchVariant().getArch());
1040 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
1041
1042 T.setArch(Triple::arm);
1043 EXPECT_EQ(Triple::arm, T.get32BitArchVariant().getArch());
1044 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
1045
1046 T.setArch(Triple::systemz);
1047 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
1048 EXPECT_EQ(Triple::systemz, T.get64BitArchVariant().getArch());
1049
1050 T.setArch(Triple::xcore);
1051 EXPECT_EQ(Triple::xcore, T.get32BitArchVariant().getArch());
1052 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
1053 }
1054
TEST(TripleTest,EndianArchVariants)1055 TEST(TripleTest, EndianArchVariants) {
1056 Triple T;
1057 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1058 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1059
1060 T.setArch(Triple::UnknownArch);
1061 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1062 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1063
1064 T.setArch(Triple::aarch64_be);
1065 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
1066 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
1067
1068 T.setArch(Triple::aarch64);
1069 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
1070 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
1071
1072 T.setArch(Triple::armeb);
1073 EXPECT_EQ(Triple::armeb, T.getBigEndianArchVariant().getArch());
1074 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1075
1076 T.setArch(Triple::arm);
1077 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1078 EXPECT_EQ(Triple::arm, T.getLittleEndianArchVariant().getArch());
1079 T = Triple("arm");
1080 EXPECT_TRUE(T.isLittleEndian());
1081 T = Triple("thumb");
1082 EXPECT_TRUE(T.isLittleEndian());
1083 T = Triple("armeb");
1084 EXPECT_FALSE(T.isLittleEndian());
1085 T = Triple("thumbeb");
1086 EXPECT_FALSE(T.isLittleEndian());
1087
1088 T.setArch(Triple::bpfeb);
1089 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
1090 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
1091
1092 T.setArch(Triple::bpfel);
1093 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
1094 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
1095
1096 T.setArch(Triple::mips64);
1097 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
1098 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
1099
1100 T.setArch(Triple::mips64el);
1101 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
1102 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
1103
1104 T.setArch(Triple::mips);
1105 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
1106 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
1107
1108 T.setArch(Triple::mipsel);
1109 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
1110 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
1111
1112 T.setArch(Triple::ppc);
1113 EXPECT_EQ(Triple::ppc, T.getBigEndianArchVariant().getArch());
1114 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1115
1116 T.setArch(Triple::ppc64);
1117 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
1118 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
1119
1120 T.setArch(Triple::ppc64le);
1121 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
1122 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
1123
1124 T.setArch(Triple::sparc);
1125 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
1126 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
1127
1128 T.setArch(Triple::sparcel);
1129 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
1130 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
1131
1132 T.setArch(Triple::thumb);
1133 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1134 EXPECT_EQ(Triple::thumb, T.getLittleEndianArchVariant().getArch());
1135
1136 T.setArch(Triple::thumbeb);
1137 EXPECT_EQ(Triple::thumbeb, T.getBigEndianArchVariant().getArch());
1138 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1139
1140 T.setArch(Triple::lanai);
1141 EXPECT_EQ(Triple::lanai, T.getBigEndianArchVariant().getArch());
1142 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
1143
1144 T.setArch(Triple::tcele);
1145 EXPECT_EQ(Triple::tce, T.getBigEndianArchVariant().getArch());
1146 EXPECT_EQ(Triple::tcele, T.getLittleEndianArchVariant().getArch());
1147
1148 T.setArch(Triple::tce);
1149 EXPECT_EQ(Triple::tce, T.getBigEndianArchVariant().getArch());
1150 EXPECT_EQ(Triple::tcele, T.getLittleEndianArchVariant().getArch());
1151
1152 T.setArch(Triple::le32);
1153 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1154 EXPECT_EQ(Triple::le32, T.getLittleEndianArchVariant().getArch());
1155
1156 T.setArch(Triple::le64);
1157 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1158 EXPECT_EQ(Triple::le64, T.getLittleEndianArchVariant().getArch());
1159
1160 T.setArch(Triple::csky);
1161 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
1162 EXPECT_EQ(Triple::csky, T.getLittleEndianArchVariant().getArch());
1163 }
1164
TEST(TripleTest,getOSVersion)1165 TEST(TripleTest, getOSVersion) {
1166 Triple T;
1167 unsigned Major, Minor, Micro;
1168
1169 T = Triple("i386-apple-darwin9");
1170 EXPECT_TRUE(T.isMacOSX());
1171 EXPECT_FALSE(T.isiOS());
1172 EXPECT_FALSE(T.isArch16Bit());
1173 EXPECT_TRUE(T.isArch32Bit());
1174 EXPECT_FALSE(T.isArch64Bit());
1175 T.getMacOSXVersion(Major, Minor, Micro);
1176 EXPECT_EQ((unsigned)10, Major);
1177 EXPECT_EQ((unsigned)5, Minor);
1178 EXPECT_EQ((unsigned)0, Micro);
1179 T.getiOSVersion(Major, Minor, Micro);
1180 EXPECT_EQ((unsigned)5, Major);
1181 EXPECT_EQ((unsigned)0, Minor);
1182 EXPECT_EQ((unsigned)0, Micro);
1183
1184 T = Triple("x86_64-apple-darwin9");
1185 EXPECT_TRUE(T.isMacOSX());
1186 EXPECT_FALSE(T.isiOS());
1187 EXPECT_FALSE(T.isArch16Bit());
1188 EXPECT_FALSE(T.isArch32Bit());
1189 EXPECT_TRUE(T.isArch64Bit());
1190 T.getMacOSXVersion(Major, Minor, Micro);
1191 EXPECT_EQ((unsigned)10, Major);
1192 EXPECT_EQ((unsigned)5, Minor);
1193 EXPECT_EQ((unsigned)0, Micro);
1194 T.getiOSVersion(Major, Minor, Micro);
1195 EXPECT_EQ((unsigned)5, Major);
1196 EXPECT_EQ((unsigned)0, Minor);
1197 EXPECT_EQ((unsigned)0, Micro);
1198
1199 T = Triple("x86_64-apple-macosx");
1200 EXPECT_TRUE(T.isMacOSX());
1201 EXPECT_FALSE(T.isiOS());
1202 EXPECT_FALSE(T.isArch16Bit());
1203 EXPECT_FALSE(T.isArch32Bit());
1204 EXPECT_TRUE(T.isArch64Bit());
1205 T.getMacOSXVersion(Major, Minor, Micro);
1206 EXPECT_EQ((unsigned)10, Major);
1207 EXPECT_EQ((unsigned)4, Minor);
1208 EXPECT_EQ((unsigned)0, Micro);
1209 T.getiOSVersion(Major, Minor, Micro);
1210 EXPECT_EQ((unsigned)5, Major);
1211 EXPECT_EQ((unsigned)0, Minor);
1212 EXPECT_EQ((unsigned)0, Micro);
1213
1214 T = Triple("x86_64-apple-macosx10.7");
1215 EXPECT_TRUE(T.isMacOSX());
1216 EXPECT_FALSE(T.isiOS());
1217 EXPECT_FALSE(T.isArch16Bit());
1218 EXPECT_FALSE(T.isArch32Bit());
1219 EXPECT_TRUE(T.isArch64Bit());
1220 T.getMacOSXVersion(Major, Minor, Micro);
1221 EXPECT_EQ((unsigned)10, Major);
1222 EXPECT_EQ((unsigned)7, Minor);
1223 EXPECT_EQ((unsigned)0, Micro);
1224 T.getiOSVersion(Major, Minor, Micro);
1225 EXPECT_EQ((unsigned)5, Major);
1226 EXPECT_EQ((unsigned)0, Minor);
1227 EXPECT_EQ((unsigned)0, Micro);
1228
1229 T = Triple("x86_64-apple-macos11.0");
1230 EXPECT_TRUE(T.isMacOSX());
1231 EXPECT_FALSE(T.isiOS());
1232 EXPECT_FALSE(T.isArch16Bit());
1233 EXPECT_FALSE(T.isArch32Bit());
1234 EXPECT_TRUE(T.isArch64Bit());
1235 T.getMacOSXVersion(Major, Minor, Micro);
1236 EXPECT_EQ((unsigned)11, Major);
1237 EXPECT_EQ((unsigned)0, Minor);
1238 EXPECT_EQ((unsigned)0, Micro);
1239
1240 T = Triple("arm64-apple-macosx11.5.8");
1241 EXPECT_TRUE(T.isMacOSX());
1242 EXPECT_FALSE(T.isiOS());
1243 EXPECT_FALSE(T.isArch16Bit());
1244 EXPECT_FALSE(T.isArch32Bit());
1245 EXPECT_TRUE(T.isArch64Bit());
1246 T.getMacOSXVersion(Major, Minor, Micro);
1247 EXPECT_EQ((unsigned)11, Major);
1248 EXPECT_EQ((unsigned)5, Minor);
1249 EXPECT_EQ((unsigned)8, Micro);
1250
1251 // 10.16 forms a valid triple, even though it's not
1252 // a version of a macOS.
1253 T = Triple("x86_64-apple-macos10.16");
1254 EXPECT_TRUE(T.isMacOSX());
1255 T.getMacOSXVersion(Major, Minor, Micro);
1256 EXPECT_EQ((unsigned)10, Major);
1257 EXPECT_EQ((unsigned)16, Minor);
1258 EXPECT_EQ((unsigned)0, Micro);
1259
1260 T = Triple("x86_64-apple-darwin20");
1261 EXPECT_TRUE(T.isMacOSX());
1262 T.getMacOSXVersion(Major, Minor, Micro);
1263 EXPECT_EQ((unsigned)11, Major);
1264 EXPECT_EQ((unsigned)0, Minor);
1265 EXPECT_EQ((unsigned)0, Micro);
1266
1267 T = Triple("armv7-apple-ios");
1268 EXPECT_FALSE(T.isMacOSX());
1269 EXPECT_TRUE(T.isiOS());
1270 EXPECT_FALSE(T.isArch16Bit());
1271 EXPECT_TRUE(T.isArch32Bit());
1272 EXPECT_FALSE(T.isArch64Bit());
1273 T.getMacOSXVersion(Major, Minor, Micro);
1274 EXPECT_EQ((unsigned)10, Major);
1275 EXPECT_EQ((unsigned)4, Minor);
1276 EXPECT_EQ((unsigned)0, Micro);
1277 T.getiOSVersion(Major, Minor, Micro);
1278 EXPECT_EQ((unsigned)5, Major);
1279 EXPECT_EQ((unsigned)0, Minor);
1280 EXPECT_EQ((unsigned)0, Micro);
1281
1282 T = Triple("armv7-apple-ios7.0");
1283 EXPECT_FALSE(T.isMacOSX());
1284 EXPECT_TRUE(T.isiOS());
1285 EXPECT_FALSE(T.isArch16Bit());
1286 EXPECT_TRUE(T.isArch32Bit());
1287 EXPECT_FALSE(T.isArch64Bit());
1288 T.getMacOSXVersion(Major, Minor, Micro);
1289 EXPECT_EQ((unsigned)10, Major);
1290 EXPECT_EQ((unsigned)4, Minor);
1291 EXPECT_EQ((unsigned)0, Micro);
1292 T.getiOSVersion(Major, Minor, Micro);
1293 EXPECT_EQ((unsigned)7, Major);
1294 EXPECT_EQ((unsigned)0, Minor);
1295 EXPECT_EQ((unsigned)0, Micro);
1296 EXPECT_FALSE(T.isSimulatorEnvironment());
1297
1298 T = Triple("x86_64-apple-ios10.3-simulator");
1299 EXPECT_TRUE(T.isiOS());
1300 T.getiOSVersion(Major, Minor, Micro);
1301 EXPECT_EQ((unsigned)10, Major);
1302 EXPECT_EQ((unsigned)3, Minor);
1303 EXPECT_EQ((unsigned)0, Micro);
1304 EXPECT_TRUE(T.isSimulatorEnvironment());
1305 EXPECT_FALSE(T.isMacCatalystEnvironment());
1306
1307 T = Triple("x86_64-apple-ios13.0-macabi");
1308 EXPECT_TRUE(T.isiOS());
1309 T.getiOSVersion(Major, Minor, Micro);
1310 EXPECT_EQ((unsigned)13, Major);
1311 EXPECT_EQ((unsigned)0, Minor);
1312 EXPECT_EQ((unsigned)0, Micro);
1313 EXPECT_TRUE(T.getEnvironment() == Triple::MacABI);
1314 EXPECT_TRUE(T.isMacCatalystEnvironment());
1315 EXPECT_FALSE(T.isSimulatorEnvironment());
1316 }
1317
TEST(TripleTest,isMacOSVersionLT)1318 TEST(TripleTest, isMacOSVersionLT) {
1319 Triple T = Triple("x86_64-apple-macos11");
1320 EXPECT_TRUE(T.isMacOSXVersionLT(11, 1, 0));
1321 EXPECT_FALSE(T.isMacOSXVersionLT(10, 15, 0));
1322
1323 T = Triple("x86_64-apple-darwin20");
1324 EXPECT_TRUE(T.isMacOSXVersionLT(11, 1, 0));
1325 EXPECT_FALSE(T.isMacOSXVersionLT(11, 0, 0));
1326 EXPECT_FALSE(T.isMacOSXVersionLT(10, 15, 0));
1327 }
1328
TEST(TripleTest,CanonicalizeOSVersion)1329 TEST(TripleTest, CanonicalizeOSVersion) {
1330 EXPECT_EQ(VersionTuple(10, 15, 4),
1331 Triple::getCanonicalVersionForOS(Triple::MacOSX,
1332 VersionTuple(10, 15, 4)));
1333 EXPECT_EQ(VersionTuple(11, 0), Triple::getCanonicalVersionForOS(
1334 Triple::MacOSX, VersionTuple(10, 16)));
1335 EXPECT_EQ(VersionTuple(20),
1336 Triple::getCanonicalVersionForOS(Triple::Darwin, VersionTuple(20)));
1337 }
1338
TEST(TripleTest,FileFormat)1339 TEST(TripleTest, FileFormat) {
1340 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-linux-gnu").getObjectFormat());
1341 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-freebsd").getObjectFormat());
1342 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-netbsd").getObjectFormat());
1343 EXPECT_EQ(Triple::ELF, Triple("i686--win32-elf").getObjectFormat());
1344 EXPECT_EQ(Triple::ELF, Triple("i686---elf").getObjectFormat());
1345
1346 EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
1347 EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
1348 EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
1349
1350 EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
1351
1352 EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
1353 EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat());
1354
1355 EXPECT_EQ(Triple::ELF, Triple("systemz-ibm-linux").getObjectFormat());
1356 EXPECT_EQ(Triple::ELF, Triple("systemz-ibm-unknown").getObjectFormat());
1357
1358 EXPECT_EQ(Triple::GOFF, Triple("s390x-ibm-zos").getObjectFormat());
1359 EXPECT_EQ(Triple::GOFF, Triple("systemz-ibm-zos").getObjectFormat());
1360 EXPECT_EQ(Triple::GOFF, Triple("s390x-ibm-zos-goff").getObjectFormat());
1361 EXPECT_EQ(Triple::GOFF, Triple("s390x-unknown-zos-goff").getObjectFormat());
1362 EXPECT_EQ(Triple::GOFF, Triple("s390x---goff").getObjectFormat());
1363
1364 EXPECT_EQ(Triple::Wasm, Triple("wasm32-unknown-unknown").getObjectFormat());
1365 EXPECT_EQ(Triple::Wasm, Triple("wasm64-unknown-unknown").getObjectFormat());
1366 EXPECT_EQ(Triple::Wasm, Triple("wasm32-wasi").getObjectFormat());
1367 EXPECT_EQ(Triple::Wasm, Triple("wasm64-wasi").getObjectFormat());
1368 EXPECT_EQ(Triple::Wasm, Triple("wasm32-unknown-wasi").getObjectFormat());
1369 EXPECT_EQ(Triple::Wasm, Triple("wasm64-unknown-wasi").getObjectFormat());
1370
1371 EXPECT_EQ(Triple::Wasm,
1372 Triple("wasm32-unknown-unknown-wasm").getObjectFormat());
1373 EXPECT_EQ(Triple::Wasm,
1374 Triple("wasm64-unknown-unknown-wasm").getObjectFormat());
1375 EXPECT_EQ(Triple::Wasm,
1376 Triple("wasm32-wasi-wasm").getObjectFormat());
1377 EXPECT_EQ(Triple::Wasm,
1378 Triple("wasm64-wasi-wasm").getObjectFormat());
1379 EXPECT_EQ(Triple::Wasm,
1380 Triple("wasm32-unknown-wasi-wasm").getObjectFormat());
1381 EXPECT_EQ(Triple::Wasm,
1382 Triple("wasm64-unknown-wasi-wasm").getObjectFormat());
1383
1384 EXPECT_EQ(Triple::XCOFF, Triple("powerpc-ibm-aix").getObjectFormat());
1385 EXPECT_EQ(Triple::XCOFF, Triple("powerpc64-ibm-aix").getObjectFormat());
1386 EXPECT_EQ(Triple::XCOFF, Triple("powerpc---xcoff").getObjectFormat());
1387 EXPECT_EQ(Triple::XCOFF, Triple("powerpc64---xcoff").getObjectFormat());
1388
1389 EXPECT_EQ(Triple::ELF, Triple("csky-unknown-unknown").getObjectFormat());
1390 EXPECT_EQ(Triple::ELF, Triple("csky-unknown-linux").getObjectFormat());
1391
1392 Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
1393 EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
1394
1395 Triple GNUWindowsNormalized(Triple::normalize("i686-pc-windows-gnu-elf"));
1396 EXPECT_EQ(Triple::ELF, GNUWindowsNormalized.getObjectFormat());
1397
1398 Triple CygnusNormalised(Triple::normalize("i686-pc-windows-cygnus-elf"));
1399 EXPECT_EQ(Triple::ELF, CygnusNormalised.getObjectFormat());
1400
1401 Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf"));
1402 EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat());
1403
1404 Triple T = Triple("");
1405 T.setObjectFormat(Triple::ELF);
1406 EXPECT_EQ(Triple::ELF, T.getObjectFormat());
1407
1408 T.setObjectFormat(Triple::MachO);
1409 EXPECT_EQ(Triple::MachO, T.getObjectFormat());
1410
1411 T.setObjectFormat(Triple::XCOFF);
1412 EXPECT_EQ(Triple::XCOFF, T.getObjectFormat());
1413
1414 T.setObjectFormat(Triple::GOFF);
1415 EXPECT_EQ(Triple::GOFF, T.getObjectFormat());
1416 }
1417
TEST(TripleTest,NormalizeWindows)1418 TEST(TripleTest, NormalizeWindows) {
1419 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-win32"));
1420 EXPECT_EQ("i686-unknown-windows-msvc", Triple::normalize("i686-win32"));
1421 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32"));
1422 EXPECT_EQ("i686-unknown-windows-gnu", Triple::normalize("i686-mingw32"));
1423 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32-w64"));
1424 EXPECT_EQ("i686-unknown-windows-gnu", Triple::normalize("i686-mingw32-w64"));
1425 EXPECT_EQ("i686-pc-windows-cygnus", Triple::normalize("i686-pc-cygwin"));
1426 EXPECT_EQ("i686-unknown-windows-cygnus", Triple::normalize("i686-cygwin"));
1427
1428 EXPECT_EQ("x86_64-pc-windows-msvc", Triple::normalize("x86_64-pc-win32"));
1429 EXPECT_EQ("x86_64-unknown-windows-msvc", Triple::normalize("x86_64-win32"));
1430 EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32"));
1431 EXPECT_EQ("x86_64-unknown-windows-gnu", Triple::normalize("x86_64-mingw32"));
1432 EXPECT_EQ("x86_64-pc-windows-gnu",
1433 Triple::normalize("x86_64-pc-mingw32-w64"));
1434 EXPECT_EQ("x86_64-unknown-windows-gnu",
1435 Triple::normalize("x86_64-mingw32-w64"));
1436
1437 EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-win32-elf"));
1438 EXPECT_EQ("i686-unknown-windows-elf", Triple::normalize("i686-win32-elf"));
1439 EXPECT_EQ("i686-pc-windows-macho", Triple::normalize("i686-pc-win32-macho"));
1440 EXPECT_EQ("i686-unknown-windows-macho",
1441 Triple::normalize("i686-win32-macho"));
1442
1443 EXPECT_EQ("x86_64-pc-windows-elf", Triple::normalize("x86_64-pc-win32-elf"));
1444 EXPECT_EQ("x86_64-unknown-windows-elf",
1445 Triple::normalize("x86_64-win32-elf"));
1446 EXPECT_EQ("x86_64-pc-windows-macho",
1447 Triple::normalize("x86_64-pc-win32-macho"));
1448 EXPECT_EQ("x86_64-unknown-windows-macho",
1449 Triple::normalize("x86_64-win32-macho"));
1450
1451 EXPECT_EQ("i686-pc-windows-cygnus",
1452 Triple::normalize("i686-pc-windows-cygnus"));
1453 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
1454 EXPECT_EQ("i686-pc-windows-itanium",
1455 Triple::normalize("i686-pc-windows-itanium"));
1456 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
1457
1458 EXPECT_EQ("i686-pc-windows-elf",
1459 Triple::normalize("i686-pc-windows-elf-elf"));
1460
1461 EXPECT_TRUE(Triple("x86_64-pc-win32").isWindowsMSVCEnvironment());
1462 }
1463
TEST(TripleTest,getARMCPUForArch)1464 TEST(TripleTest, getARMCPUForArch) {
1465 // Platform specific defaults.
1466 {
1467 llvm::Triple Triple("arm--nacl");
1468 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
1469 }
1470 {
1471 llvm::Triple Triple("arm--openbsd");
1472 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
1473 }
1474 {
1475 llvm::Triple Triple("armv6-unknown-freebsd");
1476 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1477 }
1478 {
1479 llvm::Triple Triple("thumbv6-unknown-freebsd");
1480 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1481 }
1482 {
1483 llvm::Triple Triple("armebv6-unknown-freebsd");
1484 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1485 }
1486 {
1487 llvm::Triple Triple("arm--win32");
1488 EXPECT_EQ("cortex-a9", Triple.getARMCPUForArch());
1489 }
1490 // Some alternative architectures
1491 {
1492 llvm::Triple Triple("armv7k-apple-ios9");
1493 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1494 }
1495 {
1496 llvm::Triple Triple("armv7k-apple-watchos3");
1497 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1498 }
1499 {
1500 llvm::Triple Triple("armv7k-apple-tvos9");
1501 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1502 }
1503 // armeb is permitted, but armebeb is not
1504 {
1505 llvm::Triple Triple("armeb-none-eabi");
1506 EXPECT_EQ("arm7tdmi", Triple.getARMCPUForArch());
1507 }
1508 {
1509 llvm::Triple Triple("armebeb-none-eabi");
1510 EXPECT_EQ("", Triple.getARMCPUForArch());
1511 }
1512 {
1513 llvm::Triple Triple("armebv6eb-none-eabi");
1514 EXPECT_EQ("", Triple.getARMCPUForArch());
1515 }
1516 // xscaleeb is permitted, but armebxscale is not
1517 {
1518 llvm::Triple Triple("xscaleeb-none-eabi");
1519 EXPECT_EQ("xscale", Triple.getARMCPUForArch());
1520 }
1521 {
1522 llvm::Triple Triple("armebxscale-none-eabi");
1523 EXPECT_EQ("", Triple.getARMCPUForArch());
1524 }
1525 }
1526
TEST(TripleTest,NormalizeARM)1527 TEST(TripleTest, NormalizeARM) {
1528 EXPECT_EQ("armv6-unknown-netbsd-eabi",
1529 Triple::normalize("armv6-netbsd-eabi"));
1530 EXPECT_EQ("armv7-unknown-netbsd-eabi",
1531 Triple::normalize("armv7-netbsd-eabi"));
1532 EXPECT_EQ("armv6eb-unknown-netbsd-eabi",
1533 Triple::normalize("armv6eb-netbsd-eabi"));
1534 EXPECT_EQ("armv7eb-unknown-netbsd-eabi",
1535 Triple::normalize("armv7eb-netbsd-eabi"));
1536 EXPECT_EQ("armv6-unknown-netbsd-eabihf",
1537 Triple::normalize("armv6-netbsd-eabihf"));
1538 EXPECT_EQ("armv7-unknown-netbsd-eabihf",
1539 Triple::normalize("armv7-netbsd-eabihf"));
1540 EXPECT_EQ("armv6eb-unknown-netbsd-eabihf",
1541 Triple::normalize("armv6eb-netbsd-eabihf"));
1542 EXPECT_EQ("armv7eb-unknown-netbsd-eabihf",
1543 Triple::normalize("armv7eb-netbsd-eabihf"));
1544
1545 EXPECT_EQ("armv7-suse-linux-gnueabihf",
1546 Triple::normalize("armv7-suse-linux-gnueabi"));
1547
1548 Triple T;
1549 T = Triple("armv6--netbsd-eabi");
1550 EXPECT_EQ(Triple::arm, T.getArch());
1551 T = Triple("armv6eb--netbsd-eabi");
1552 EXPECT_EQ(Triple::armeb, T.getArch());
1553 T = Triple("armv7-suse-linux-gnueabihf");
1554 EXPECT_EQ(Triple::GNUEABIHF, T.getEnvironment());
1555 }
1556
TEST(TripleTest,ParseARMArch)1557 TEST(TripleTest, ParseARMArch) {
1558 // ARM
1559 {
1560 Triple T = Triple("arm");
1561 EXPECT_EQ(Triple::arm, T.getArch());
1562 }
1563 {
1564 Triple T = Triple("armeb");
1565 EXPECT_EQ(Triple::armeb, T.getArch());
1566 }
1567 // THUMB
1568 {
1569 Triple T = Triple("thumb");
1570 EXPECT_EQ(Triple::thumb, T.getArch());
1571 }
1572 {
1573 Triple T = Triple("thumbeb");
1574 EXPECT_EQ(Triple::thumbeb, T.getArch());
1575 }
1576 // AARCH64
1577 {
1578 Triple T = Triple("arm64");
1579 EXPECT_EQ(Triple::aarch64, T.getArch());
1580 }
1581 {
1582 Triple T = Triple("arm64_32");
1583 EXPECT_EQ(Triple::aarch64_32, T.getArch());
1584 }
1585 {
1586 Triple T = Triple("aarch64");
1587 EXPECT_EQ(Triple::aarch64, T.getArch());
1588 }
1589 {
1590 Triple T = Triple("aarch64_be");
1591 EXPECT_EQ(Triple::aarch64_be, T.getArch());
1592 }
1593 {
1594 Triple T = Triple("arm64e");
1595 EXPECT_EQ(Triple::aarch64, T.getArch());
1596 EXPECT_EQ(Triple::AArch64SubArch_arm64e, T.getSubArch());
1597 }
1598 }
1599 } // end anonymous namespace
1600