1 //===----------- Triple.cpp - Triple unit tests ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/Triple.h"
11 #include "gtest/gtest.h"
17 TEST(TripleTest, BasicParsing) {
21 EXPECT_EQ("", T.getArchName().str());
22 EXPECT_EQ("", T.getVendorName().str());
23 EXPECT_EQ("", T.getOSName().str());
24 EXPECT_EQ("", T.getEnvironmentName().str());
27 EXPECT_EQ("", T.getArchName().str());
28 EXPECT_EQ("", T.getVendorName().str());
29 EXPECT_EQ("", T.getOSName().str());
30 EXPECT_EQ("", T.getEnvironmentName().str());
33 EXPECT_EQ("", T.getArchName().str());
34 EXPECT_EQ("", T.getVendorName().str());
35 EXPECT_EQ("", T.getOSName().str());
36 EXPECT_EQ("", T.getEnvironmentName().str());
39 EXPECT_EQ("", T.getArchName().str());
40 EXPECT_EQ("", T.getVendorName().str());
41 EXPECT_EQ("", T.getOSName().str());
42 EXPECT_EQ("", T.getEnvironmentName().str());
45 EXPECT_EQ("", T.getArchName().str());
46 EXPECT_EQ("", T.getVendorName().str());
47 EXPECT_EQ("", T.getOSName().str());
48 EXPECT_EQ("-", T.getEnvironmentName().str());
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());
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());
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());
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());
75 TEST(TripleTest, ParsedIDs) {
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());
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());
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());
96 T = Triple("x86_64-pc-linux-gnu");
97 EXPECT_EQ(Triple::x86_64, T.getArch());
98 EXPECT_EQ(Triple::PC, T.getVendor());
99 EXPECT_EQ(Triple::Linux, T.getOS());
100 EXPECT_EQ(Triple::GNU, T.getEnvironment());
102 T = Triple("x86_64-pc-linux-musl");
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::Musl, T.getEnvironment());
108 T = Triple("powerpc-bgp-linux");
109 EXPECT_EQ(Triple::ppc, T.getArch());
110 EXPECT_EQ(Triple::BGP, T.getVendor());
111 EXPECT_EQ(Triple::Linux, T.getOS());
112 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
114 T = Triple("powerpc-bgp-cnk");
115 EXPECT_EQ(Triple::ppc, T.getArch());
116 EXPECT_EQ(Triple::BGP, T.getVendor());
117 EXPECT_EQ(Triple::CNK, T.getOS());
118 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
120 T = Triple("ppc-bgp-linux");
121 EXPECT_EQ(Triple::ppc, T.getArch());
122 EXPECT_EQ(Triple::BGP, T.getVendor());
123 EXPECT_EQ(Triple::Linux, T.getOS());
124 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
126 T = Triple("ppc32-bgp-linux");
127 EXPECT_EQ(Triple::ppc, T.getArch());
128 EXPECT_EQ(Triple::BGP, T.getVendor());
129 EXPECT_EQ(Triple::Linux, T.getOS());
130 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
132 T = Triple("powerpc64-bgq-linux");
133 EXPECT_EQ(Triple::ppc64, T.getArch());
134 EXPECT_EQ(Triple::BGQ, T.getVendor());
135 EXPECT_EQ(Triple::Linux, T.getOS());
136 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
138 T = Triple("ppc64-bgq-linux");
139 EXPECT_EQ(Triple::ppc64, T.getArch());
140 EXPECT_EQ(Triple::BGQ, T.getVendor());
141 EXPECT_EQ(Triple::Linux, T.getOS());
143 T = Triple("powerpc-ibm-aix");
144 EXPECT_EQ(Triple::ppc, T.getArch());
145 EXPECT_EQ(Triple::IBM, T.getVendor());
146 EXPECT_EQ(Triple::AIX, T.getOS());
147 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
149 T = Triple("powerpc64-ibm-aix");
150 EXPECT_EQ(Triple::ppc64, T.getArch());
151 EXPECT_EQ(Triple::IBM, T.getVendor());
152 EXPECT_EQ(Triple::AIX, T.getOS());
153 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
155 T = Triple("powerpc-dunno-notsure");
156 EXPECT_EQ(Triple::ppc, T.getArch());
157 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
158 EXPECT_EQ(Triple::UnknownOS, T.getOS());
159 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
161 T = Triple("arm-none-none-eabi");
162 EXPECT_EQ(Triple::arm, T.getArch());
163 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
164 EXPECT_EQ(Triple::UnknownOS, T.getOS());
165 EXPECT_EQ(Triple::EABI, T.getEnvironment());
167 T = Triple("arm-none-linux-musleabi");
168 EXPECT_EQ(Triple::arm, T.getArch());
169 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
170 EXPECT_EQ(Triple::Linux, T.getOS());
171 EXPECT_EQ(Triple::MuslEABI, T.getEnvironment());
173 T = Triple("armv6hl-none-linux-gnueabi");
174 EXPECT_EQ(Triple::arm, T.getArch());
175 EXPECT_EQ(Triple::Linux, T.getOS());
176 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
177 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
179 T = Triple("armv7hl-none-linux-gnueabi");
180 EXPECT_EQ(Triple::arm, T.getArch());
181 EXPECT_EQ(Triple::Linux, T.getOS());
182 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
183 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
185 T = Triple("amdil-unknown-unknown");
186 EXPECT_EQ(Triple::amdil, T.getArch());
187 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
188 EXPECT_EQ(Triple::UnknownOS, T.getOS());
190 T = Triple("amdil64-unknown-unknown");
191 EXPECT_EQ(Triple::amdil64, T.getArch());
192 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
193 EXPECT_EQ(Triple::UnknownOS, T.getOS());
195 T = Triple("hsail-unknown-unknown");
196 EXPECT_EQ(Triple::hsail, T.getArch());
197 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
198 EXPECT_EQ(Triple::UnknownOS, T.getOS());
200 T = Triple("hsail64-unknown-unknown");
201 EXPECT_EQ(Triple::hsail64, T.getArch());
202 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
203 EXPECT_EQ(Triple::UnknownOS, T.getOS());
205 T = Triple("sparcel-unknown-unknown");
206 EXPECT_EQ(Triple::sparcel, T.getArch());
207 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
208 EXPECT_EQ(Triple::UnknownOS, T.getOS());
210 T = Triple("spir-unknown-unknown");
211 EXPECT_EQ(Triple::spir, T.getArch());
212 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
213 EXPECT_EQ(Triple::UnknownOS, T.getOS());
215 T = Triple("spir64-unknown-unknown");
216 EXPECT_EQ(Triple::spir64, T.getArch());
217 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
218 EXPECT_EQ(Triple::UnknownOS, T.getOS());
220 T = Triple("x86_64-unknown-ananas");
221 EXPECT_EQ(Triple::x86_64, T.getArch());
222 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
223 EXPECT_EQ(Triple::Ananas, T.getOS());
224 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
226 T = Triple("x86_64-unknown-cloudabi");
227 EXPECT_EQ(Triple::x86_64, T.getArch());
228 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
229 EXPECT_EQ(Triple::CloudABI, T.getOS());
230 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
232 T = Triple("x86_64-unknown-fuchsia");
233 EXPECT_EQ(Triple::x86_64, T.getArch());
234 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
235 EXPECT_EQ(Triple::Fuchsia, T.getOS());
236 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
238 T = Triple("wasm32-unknown-unknown");
239 EXPECT_EQ(Triple::wasm32, T.getArch());
240 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
241 EXPECT_EQ(Triple::UnknownOS, T.getOS());
242 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
244 T = Triple("wasm64-unknown-unknown");
245 EXPECT_EQ(Triple::wasm64, T.getArch());
246 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
247 EXPECT_EQ(Triple::UnknownOS, T.getOS());
248 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
250 T = Triple("avr-unknown-unknown");
251 EXPECT_EQ(Triple::avr, T.getArch());
252 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
253 EXPECT_EQ(Triple::UnknownOS, T.getOS());
254 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
257 EXPECT_EQ(Triple::avr, T.getArch());
258 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
259 EXPECT_EQ(Triple::UnknownOS, T.getOS());
260 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
262 T = Triple("lanai-unknown-unknown");
263 EXPECT_EQ(Triple::lanai, T.getArch());
264 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
265 EXPECT_EQ(Triple::UnknownOS, T.getOS());
266 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
269 EXPECT_EQ(Triple::lanai, T.getArch());
270 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
271 EXPECT_EQ(Triple::UnknownOS, T.getOS());
272 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
274 T = Triple("amdgcn-mesa-mesa3d");
275 EXPECT_EQ(Triple::amdgcn, T.getArch());
276 EXPECT_EQ(Triple::Mesa, T.getVendor());
277 EXPECT_EQ(Triple::Mesa3D, T.getOS());
278 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
280 T = Triple("amdgcn-amd-amdhsa");
281 EXPECT_EQ(Triple::amdgcn, T.getArch());
282 EXPECT_EQ(Triple::AMD, T.getVendor());
283 EXPECT_EQ(Triple::AMDHSA, T.getOS());
284 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
286 T = Triple("amdgcn-amd-amdhsa-opencl");
287 EXPECT_EQ(Triple::amdgcn, T.getArch());
288 EXPECT_EQ(Triple::AMD, T.getVendor());
289 EXPECT_EQ(Triple::AMDHSA, T.getOS());
290 EXPECT_EQ(Triple::OpenCL, T.getEnvironment());
292 T = Triple("amdgcn-amd-amdpal");
293 EXPECT_EQ(Triple::amdgcn, T.getArch());
294 EXPECT_EQ(Triple::AMD, T.getVendor());
295 EXPECT_EQ(Triple::AMDPAL, T.getOS());
296 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
298 T = Triple("riscv32-unknown-unknown");
299 EXPECT_EQ(Triple::riscv32, T.getArch());
300 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
301 EXPECT_EQ(Triple::UnknownOS, T.getOS());
302 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
304 T = Triple("riscv64-unknown-linux");
305 EXPECT_EQ(Triple::riscv64, T.getArch());
306 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
307 EXPECT_EQ(Triple::Linux, T.getOS());
308 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
310 T = Triple("riscv64-unknown-freebsd");
311 EXPECT_EQ(Triple::riscv64, T.getArch());
312 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
313 EXPECT_EQ(Triple::FreeBSD, T.getOS());
314 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
316 T = Triple("armv7hl-suse-linux-gnueabi");
317 EXPECT_EQ(Triple::arm, T.getArch());
318 EXPECT_EQ(Triple::SUSE, T.getVendor());
319 EXPECT_EQ(Triple::Linux, T.getOS());
320 EXPECT_EQ(Triple::GNUEABI, T.getEnvironment());
322 T = Triple("i586-pc-haiku");
323 EXPECT_EQ(Triple::x86, T.getArch());
324 EXPECT_EQ(Triple::PC, T.getVendor());
325 EXPECT_EQ(Triple::Haiku, T.getOS());
326 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
328 T = Triple("x86_64-unknown-haiku");
329 EXPECT_EQ(Triple::x86_64, T.getArch());
330 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
331 EXPECT_EQ(Triple::Haiku, T.getOS());
332 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
334 T = Triple("mips-mti-linux-gnu");
335 EXPECT_EQ(Triple::mips, T.getArch());
336 EXPECT_EQ(Triple::MipsTechnologies, T.getVendor());
337 EXPECT_EQ(Triple::Linux, T.getOS());
338 EXPECT_EQ(Triple::GNU, T.getEnvironment());
340 T = Triple("mipsel-img-linux-gnu");
341 EXPECT_EQ(Triple::mipsel, T.getArch());
342 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
343 EXPECT_EQ(Triple::Linux, T.getOS());
344 EXPECT_EQ(Triple::GNU, T.getEnvironment());
346 T = Triple("mips64-mti-linux-gnu");
347 EXPECT_EQ(Triple::mips64, T.getArch());
348 EXPECT_EQ(Triple::MipsTechnologies, T.getVendor());
349 EXPECT_EQ(Triple::Linux, T.getOS());
350 EXPECT_EQ(Triple::GNU, T.getEnvironment());
352 T = Triple("mips64el-img-linux-gnu");
353 EXPECT_EQ(Triple::mips64el, T.getArch());
354 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
355 EXPECT_EQ(Triple::Linux, T.getOS());
356 EXPECT_EQ(Triple::GNU, T.getEnvironment());
358 T = Triple("mips64el-img-linux-gnuabin32");
359 EXPECT_EQ(Triple::mips64el, T.getArch());
360 EXPECT_EQ(Triple::ImaginationTechnologies, T.getVendor());
361 EXPECT_EQ(Triple::Linux, T.getOS());
362 EXPECT_EQ(Triple::GNUABIN32, T.getEnvironment());
364 T = Triple("mips64el-unknown-linux-gnuabi64");
365 EXPECT_EQ(Triple::mips64el, T.getArch());
366 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
367 EXPECT_EQ(Triple::Linux, T.getOS());
368 EXPECT_EQ(Triple::GNUABI64, T.getEnvironment());
371 EXPECT_EQ(Triple::UnknownArch, T.getArch());
374 static std::string Join(StringRef A, StringRef B, StringRef C) {
375 std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C;
379 static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) {
380 std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; Str += '-';
381 Str += D; return Str;
384 TEST(TripleTest, Normalization) {
386 EXPECT_EQ("", Triple::normalize(""));
387 EXPECT_EQ("-", Triple::normalize("-"));
388 EXPECT_EQ("--", Triple::normalize("--"));
389 EXPECT_EQ("---", Triple::normalize("---"));
390 EXPECT_EQ("----", Triple::normalize("----"));
392 EXPECT_EQ("a", Triple::normalize("a"));
393 EXPECT_EQ("a-b", Triple::normalize("a-b"));
394 EXPECT_EQ("a-b-c", Triple::normalize("a-b-c"));
395 EXPECT_EQ("a-b-c-d", Triple::normalize("a-b-c-d"));
397 EXPECT_EQ("i386-b-c", Triple::normalize("i386-b-c"));
398 EXPECT_EQ("i386-a-c", Triple::normalize("a-i386-c"));
399 EXPECT_EQ("i386-a-b", Triple::normalize("a-b-i386"));
400 EXPECT_EQ("i386-a-b-c", Triple::normalize("a-b-c-i386"));
402 EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c"));
403 EXPECT_EQ("-pc-b-c", Triple::normalize("pc-b-c"));
404 EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc"));
405 EXPECT_EQ("a-pc-b-c", Triple::normalize("a-b-c-pc"));
407 EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux"));
408 EXPECT_EQ("--linux-b-c", Triple::normalize("linux-b-c"));
409 EXPECT_EQ("a--linux-c", Triple::normalize("a-linux-c"));
411 EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386"));
412 EXPECT_EQ("i386-pc-", Triple::normalize("-pc-i386"));
413 EXPECT_EQ("-pc-linux-c", Triple::normalize("linux-pc-c"));
414 EXPECT_EQ("-pc-linux", Triple::normalize("linux-pc-"));
416 EXPECT_EQ("i386", Triple::normalize("i386"));
417 EXPECT_EQ("-pc", Triple::normalize("pc"));
418 EXPECT_EQ("--linux", Triple::normalize("linux"));
420 EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-gnu-linux"));
422 // Check that normalizing a permutated set of valid components returns a
423 // triple with the unpermuted components.
425 // We don't check every possible combination. For the set of architectures A,
426 // vendors V, operating systems O, and environments E, that would require |A|
427 // * |V| * |O| * |E| * 4! tests. Instead we check every option for any given
428 // slot and make sure it gets normalized to the correct position from every
429 // permutation. This should cover the core logic while being a tractable
430 // number of tests at (|A| + |V| + |O| + |E|) * 4!.
431 auto FirstArchType = Triple::ArchType(Triple::UnknownArch + 1);
432 auto FirstVendorType = Triple::VendorType(Triple::UnknownVendor + 1);
433 auto FirstOSType = Triple::OSType(Triple::UnknownOS + 1);
434 auto FirstEnvType = Triple::EnvironmentType(Triple::UnknownEnvironment + 1);
435 StringRef InitialC[] = {Triple::getArchTypeName(FirstArchType),
436 Triple::getVendorTypeName(FirstVendorType),
437 Triple::getOSTypeName(FirstOSType),
438 Triple::getEnvironmentTypeName(FirstEnvType)};
439 for (int Arch = FirstArchType; Arch <= Triple::LastArchType; ++Arch) {
440 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
441 C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
442 std::string E = Join(C[0], C[1], C[2]);
445 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
446 } while (std::next_permutation(std::begin(I), std::end(I)));
447 std::string F = Join(C[0], C[1], C[2], C[3]);
448 int J[] = {0, 1, 2, 3};
450 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
451 } while (std::next_permutation(std::begin(J), std::end(J)));
453 for (int Vendor = FirstVendorType; Vendor <= Triple::LastVendorType;
455 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
456 C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
457 std::string E = Join(C[0], C[1], C[2]);
460 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
461 } while (std::next_permutation(std::begin(I), std::end(I)));
462 std::string F = Join(C[0], C[1], C[2], C[3]);
463 int J[] = {0, 1, 2, 3};
465 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
466 } while (std::next_permutation(std::begin(J), std::end(J)));
468 for (int OS = FirstOSType; OS <= Triple::LastOSType; ++OS) {
469 if (OS == Triple::Win32)
471 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
472 C[2] = Triple::getOSTypeName(Triple::OSType(OS));
473 std::string E = Join(C[0], C[1], C[2]);
476 EXPECT_EQ(E, Triple::normalize(Join(C[I[0]], C[I[1]], C[I[2]])));
477 } while (std::next_permutation(std::begin(I), std::end(I)));
478 std::string F = Join(C[0], C[1], C[2], C[3]);
479 int J[] = {0, 1, 2, 3};
481 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
482 } while (std::next_permutation(std::begin(J), std::end(J)));
484 for (int Env = FirstEnvType; Env <= Triple::LastEnvironmentType; ++Env) {
485 StringRef C[] = {InitialC[0], InitialC[1], InitialC[2], InitialC[3]};
486 C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
487 std::string F = Join(C[0], C[1], C[2], C[3]);
488 int J[] = {0, 1, 2, 3};
490 EXPECT_EQ(F, Triple::normalize(Join(C[J[0]], C[J[1]], C[J[2]], C[J[3]])));
491 } while (std::next_permutation(std::begin(J), std::end(J)));
494 // Various real-world funky triples. The value returned by GCC's config.sub
495 // is given in the comment.
496 EXPECT_EQ("i386--windows-gnu", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
497 EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
498 EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
499 EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
500 EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
501 EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
504 TEST(TripleTest, MutateName) {
506 EXPECT_EQ(Triple::UnknownArch, T.getArch());
507 EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
508 EXPECT_EQ(Triple::UnknownOS, T.getOS());
509 EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
511 T.setArchName("i386");
512 EXPECT_EQ(Triple::x86, T.getArch());
513 EXPECT_EQ("i386--", T.getTriple());
515 T.setVendorName("pc");
516 EXPECT_EQ(Triple::x86, T.getArch());
517 EXPECT_EQ(Triple::PC, T.getVendor());
518 EXPECT_EQ("i386-pc-", T.getTriple());
520 T.setOSName("linux");
521 EXPECT_EQ(Triple::x86, T.getArch());
522 EXPECT_EQ(Triple::PC, T.getVendor());
523 EXPECT_EQ(Triple::Linux, T.getOS());
524 EXPECT_EQ("i386-pc-linux", T.getTriple());
526 T.setEnvironmentName("gnu");
527 EXPECT_EQ(Triple::x86, T.getArch());
528 EXPECT_EQ(Triple::PC, T.getVendor());
529 EXPECT_EQ(Triple::Linux, T.getOS());
530 EXPECT_EQ("i386-pc-linux-gnu", T.getTriple());
532 T.setOSName("freebsd");
533 EXPECT_EQ(Triple::x86, T.getArch());
534 EXPECT_EQ(Triple::PC, T.getVendor());
535 EXPECT_EQ(Triple::FreeBSD, T.getOS());
536 EXPECT_EQ("i386-pc-freebsd-gnu", T.getTriple());
538 T.setOSAndEnvironmentName("darwin");
539 EXPECT_EQ(Triple::x86, T.getArch());
540 EXPECT_EQ(Triple::PC, T.getVendor());
541 EXPECT_EQ(Triple::Darwin, T.getOS());
542 EXPECT_EQ("i386-pc-darwin", T.getTriple());
545 TEST(TripleTest, BitWidthPredicates) {
547 EXPECT_FALSE(T.isArch16Bit());
548 EXPECT_FALSE(T.isArch32Bit());
549 EXPECT_FALSE(T.isArch64Bit());
551 T.setArch(Triple::arm);
552 EXPECT_FALSE(T.isArch16Bit());
553 EXPECT_TRUE(T.isArch32Bit());
554 EXPECT_FALSE(T.isArch64Bit());
556 T.setArch(Triple::hexagon);
557 EXPECT_FALSE(T.isArch16Bit());
558 EXPECT_TRUE(T.isArch32Bit());
559 EXPECT_FALSE(T.isArch64Bit());
561 T.setArch(Triple::mips);
562 EXPECT_FALSE(T.isArch16Bit());
563 EXPECT_TRUE(T.isArch32Bit());
564 EXPECT_FALSE(T.isArch64Bit());
566 T.setArch(Triple::mips64);
567 EXPECT_FALSE(T.isArch16Bit());
568 EXPECT_FALSE(T.isArch32Bit());
569 EXPECT_TRUE(T.isArch64Bit());
571 T.setArch(Triple::msp430);
572 EXPECT_TRUE(T.isArch16Bit());
573 EXPECT_FALSE(T.isArch32Bit());
574 EXPECT_FALSE(T.isArch64Bit());
576 T.setArch(Triple::ppc);
577 EXPECT_FALSE(T.isArch16Bit());
578 EXPECT_TRUE(T.isArch32Bit());
579 EXPECT_FALSE(T.isArch64Bit());
581 T.setArch(Triple::ppc64);
582 EXPECT_FALSE(T.isArch16Bit());
583 EXPECT_FALSE(T.isArch32Bit());
584 EXPECT_TRUE(T.isArch64Bit());
586 T.setArch(Triple::x86);
587 EXPECT_FALSE(T.isArch16Bit());
588 EXPECT_TRUE(T.isArch32Bit());
589 EXPECT_FALSE(T.isArch64Bit());
591 T.setArch(Triple::x86_64);
592 EXPECT_FALSE(T.isArch16Bit());
593 EXPECT_FALSE(T.isArch32Bit());
594 EXPECT_TRUE(T.isArch64Bit());
596 T.setArch(Triple::amdil);
597 EXPECT_FALSE(T.isArch16Bit());
598 EXPECT_TRUE(T.isArch32Bit());
599 EXPECT_FALSE(T.isArch64Bit());
601 T.setArch(Triple::amdil64);
602 EXPECT_FALSE(T.isArch16Bit());
603 EXPECT_FALSE(T.isArch32Bit());
604 EXPECT_TRUE(T.isArch64Bit());
606 T.setArch(Triple::hsail);
607 EXPECT_FALSE(T.isArch16Bit());
608 EXPECT_TRUE(T.isArch32Bit());
609 EXPECT_FALSE(T.isArch64Bit());
611 T.setArch(Triple::hsail64);
612 EXPECT_FALSE(T.isArch16Bit());
613 EXPECT_FALSE(T.isArch32Bit());
614 EXPECT_TRUE(T.isArch64Bit());
616 T.setArch(Triple::spir);
617 EXPECT_FALSE(T.isArch16Bit());
618 EXPECT_TRUE(T.isArch32Bit());
619 EXPECT_FALSE(T.isArch64Bit());
621 T.setArch(Triple::spir64);
622 EXPECT_FALSE(T.isArch16Bit());
623 EXPECT_FALSE(T.isArch32Bit());
624 EXPECT_TRUE(T.isArch64Bit());
626 T.setArch(Triple::sparc);
627 EXPECT_FALSE(T.isArch16Bit());
628 EXPECT_TRUE(T.isArch32Bit());
629 EXPECT_FALSE(T.isArch64Bit());
631 T.setArch(Triple::sparcel);
632 EXPECT_FALSE(T.isArch16Bit());
633 EXPECT_TRUE(T.isArch32Bit());
634 EXPECT_FALSE(T.isArch64Bit());
636 T.setArch(Triple::sparcv9);
637 EXPECT_FALSE(T.isArch16Bit());
638 EXPECT_FALSE(T.isArch32Bit());
639 EXPECT_TRUE(T.isArch64Bit());
641 T.setArch(Triple::wasm32);
642 EXPECT_FALSE(T.isArch16Bit());
643 EXPECT_TRUE(T.isArch32Bit());
644 EXPECT_FALSE(T.isArch64Bit());
646 T.setArch(Triple::wasm64);
647 EXPECT_FALSE(T.isArch16Bit());
648 EXPECT_FALSE(T.isArch32Bit());
649 EXPECT_TRUE(T.isArch64Bit());
651 T.setArch(Triple::avr);
652 EXPECT_TRUE(T.isArch16Bit());
653 EXPECT_FALSE(T.isArch32Bit());
654 EXPECT_FALSE(T.isArch64Bit());
656 T.setArch(Triple::lanai);
657 EXPECT_FALSE(T.isArch16Bit());
658 EXPECT_TRUE(T.isArch32Bit());
659 EXPECT_FALSE(T.isArch64Bit());
661 T.setArch(Triple::riscv32);
662 EXPECT_FALSE(T.isArch16Bit());
663 EXPECT_TRUE(T.isArch32Bit());
664 EXPECT_FALSE(T.isArch64Bit());
666 T.setArch(Triple::riscv64);
667 EXPECT_FALSE(T.isArch16Bit());
668 EXPECT_FALSE(T.isArch32Bit());
669 EXPECT_TRUE(T.isArch64Bit());
672 TEST(TripleTest, BitWidthArchVariants) {
674 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
675 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
677 T.setArch(Triple::UnknownArch);
678 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
679 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
681 T.setArch(Triple::mips);
682 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
683 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
685 T.setArch(Triple::mipsel);
686 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
687 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
689 T.setArch(Triple::ppc);
690 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
691 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
693 T.setArch(Triple::nvptx);
694 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
695 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
697 T.setArch(Triple::sparc);
698 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
699 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
701 T.setArch(Triple::x86);
702 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
703 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
705 T.setArch(Triple::mips64);
706 EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
707 EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
709 T.setArch(Triple::mips64el);
710 EXPECT_EQ(Triple::mipsel, T.get32BitArchVariant().getArch());
711 EXPECT_EQ(Triple::mips64el, T.get64BitArchVariant().getArch());
713 T.setArch(Triple::ppc64);
714 EXPECT_EQ(Triple::ppc, T.get32BitArchVariant().getArch());
715 EXPECT_EQ(Triple::ppc64, T.get64BitArchVariant().getArch());
717 T.setArch(Triple::nvptx64);
718 EXPECT_EQ(Triple::nvptx, T.get32BitArchVariant().getArch());
719 EXPECT_EQ(Triple::nvptx64, T.get64BitArchVariant().getArch());
721 T.setArch(Triple::sparcv9);
722 EXPECT_EQ(Triple::sparc, T.get32BitArchVariant().getArch());
723 EXPECT_EQ(Triple::sparcv9, T.get64BitArchVariant().getArch());
725 T.setArch(Triple::x86_64);
726 EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
727 EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
729 T.setArch(Triple::amdil);
730 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
731 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
733 T.setArch(Triple::amdil64);
734 EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
735 EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
737 T.setArch(Triple::hsail);
738 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
739 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
741 T.setArch(Triple::hsail64);
742 EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
743 EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
745 T.setArch(Triple::spir);
746 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
747 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
749 T.setArch(Triple::spir64);
750 EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
751 EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
753 T.setArch(Triple::wasm32);
754 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
755 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
757 T.setArch(Triple::wasm64);
758 EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch());
759 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
761 T.setArch(Triple::riscv32);
762 EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch());
763 EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch());
765 T.setArch(Triple::riscv64);
766 EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch());
767 EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch());
769 T.setArch(Triple::thumbeb);
770 EXPECT_EQ(Triple::thumbeb, T.get32BitArchVariant().getArch());
771 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
773 T.setArch(Triple::thumb);
774 EXPECT_EQ(Triple::thumb, T.get32BitArchVariant().getArch());
775 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
777 T.setArch(Triple::aarch64);
778 EXPECT_EQ(Triple::arm, T.get32BitArchVariant().getArch());
779 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
781 T.setArch(Triple::aarch64_be);
782 EXPECT_EQ(Triple::armeb, T.get32BitArchVariant().getArch());
783 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
785 T.setArch(Triple::renderscript32);
786 EXPECT_EQ(Triple::renderscript32, T.get32BitArchVariant().getArch());
787 EXPECT_EQ(Triple::renderscript64, T.get64BitArchVariant().getArch());
789 T.setArch(Triple::renderscript64);
790 EXPECT_EQ(Triple::renderscript32, T.get32BitArchVariant().getArch());
791 EXPECT_EQ(Triple::renderscript64, T.get64BitArchVariant().getArch());
793 T.setArch(Triple::le32);
794 EXPECT_EQ(Triple::le32, T.get32BitArchVariant().getArch());
795 EXPECT_EQ(Triple::le64, T.get64BitArchVariant().getArch());
797 T.setArch(Triple::le64);
798 EXPECT_EQ(Triple::le32, T.get32BitArchVariant().getArch());
799 EXPECT_EQ(Triple::le64, T.get64BitArchVariant().getArch());
801 T.setArch(Triple::armeb);
802 EXPECT_EQ(Triple::armeb, T.get32BitArchVariant().getArch());
803 EXPECT_EQ(Triple::aarch64_be, T.get64BitArchVariant().getArch());
805 T.setArch(Triple::arm);
806 EXPECT_EQ(Triple::arm, T.get32BitArchVariant().getArch());
807 EXPECT_EQ(Triple::aarch64, T.get64BitArchVariant().getArch());
809 T.setArch(Triple::systemz);
810 EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
811 EXPECT_EQ(Triple::systemz, T.get64BitArchVariant().getArch());
813 T.setArch(Triple::xcore);
814 EXPECT_EQ(Triple::xcore, T.get32BitArchVariant().getArch());
815 EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
818 TEST(TripleTest, EndianArchVariants) {
820 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
821 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
823 T.setArch(Triple::UnknownArch);
824 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
825 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
827 T.setArch(Triple::aarch64_be);
828 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
829 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
831 T.setArch(Triple::aarch64);
832 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
833 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
835 T.setArch(Triple::armeb);
836 EXPECT_EQ(Triple::armeb, T.getBigEndianArchVariant().getArch());
837 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
839 T.setArch(Triple::arm);
840 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
841 EXPECT_EQ(Triple::arm, T.getLittleEndianArchVariant().getArch());
843 EXPECT_TRUE(T.isLittleEndian());
845 EXPECT_TRUE(T.isLittleEndian());
847 EXPECT_FALSE(T.isLittleEndian());
848 T = Triple("thumbeb");
849 EXPECT_FALSE(T.isLittleEndian());
851 T.setArch(Triple::bpfeb);
852 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
853 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
855 T.setArch(Triple::bpfel);
856 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
857 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
859 T.setArch(Triple::mips64);
860 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
861 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
863 T.setArch(Triple::mips64el);
864 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
865 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
867 T.setArch(Triple::mips);
868 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
869 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
871 T.setArch(Triple::mipsel);
872 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
873 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
875 T.setArch(Triple::ppc);
876 EXPECT_EQ(Triple::ppc, T.getBigEndianArchVariant().getArch());
877 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
879 T.setArch(Triple::ppc64);
880 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
881 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
883 T.setArch(Triple::ppc64le);
884 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
885 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
887 T.setArch(Triple::sparc);
888 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
889 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
891 T.setArch(Triple::sparcel);
892 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
893 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
895 T.setArch(Triple::thumb);
896 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
897 EXPECT_EQ(Triple::thumb, T.getLittleEndianArchVariant().getArch());
899 T.setArch(Triple::thumbeb);
900 EXPECT_EQ(Triple::thumbeb, T.getBigEndianArchVariant().getArch());
901 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
903 T.setArch(Triple::lanai);
904 EXPECT_EQ(Triple::lanai, T.getBigEndianArchVariant().getArch());
905 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
907 T.setArch(Triple::tcele);
908 EXPECT_EQ(Triple::tce, T.getBigEndianArchVariant().getArch());
909 EXPECT_EQ(Triple::tcele, T.getLittleEndianArchVariant().getArch());
911 T.setArch(Triple::tce);
912 EXPECT_EQ(Triple::tce, T.getBigEndianArchVariant().getArch());
913 EXPECT_EQ(Triple::tcele, T.getLittleEndianArchVariant().getArch());
915 T.setArch(Triple::le32);
916 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
917 EXPECT_EQ(Triple::le32, T.getLittleEndianArchVariant().getArch());
919 T.setArch(Triple::le64);
920 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
921 EXPECT_EQ(Triple::le64, T.getLittleEndianArchVariant().getArch());
924 TEST(TripleTest, getOSVersion) {
926 unsigned Major, Minor, Micro;
928 T = Triple("i386-apple-darwin9");
929 EXPECT_TRUE(T.isMacOSX());
930 EXPECT_FALSE(T.isiOS());
931 EXPECT_FALSE(T.isArch16Bit());
932 EXPECT_TRUE(T.isArch32Bit());
933 EXPECT_FALSE(T.isArch64Bit());
934 T.getMacOSXVersion(Major, Minor, Micro);
935 EXPECT_EQ((unsigned)10, Major);
936 EXPECT_EQ((unsigned)5, Minor);
937 EXPECT_EQ((unsigned)0, Micro);
938 T.getiOSVersion(Major, Minor, Micro);
939 EXPECT_EQ((unsigned)5, Major);
940 EXPECT_EQ((unsigned)0, Minor);
941 EXPECT_EQ((unsigned)0, Micro);
943 T = Triple("x86_64-apple-darwin9");
944 EXPECT_TRUE(T.isMacOSX());
945 EXPECT_FALSE(T.isiOS());
946 EXPECT_FALSE(T.isArch16Bit());
947 EXPECT_FALSE(T.isArch32Bit());
948 EXPECT_TRUE(T.isArch64Bit());
949 T.getMacOSXVersion(Major, Minor, Micro);
950 EXPECT_EQ((unsigned)10, Major);
951 EXPECT_EQ((unsigned)5, Minor);
952 EXPECT_EQ((unsigned)0, Micro);
953 T.getiOSVersion(Major, Minor, Micro);
954 EXPECT_EQ((unsigned)5, Major);
955 EXPECT_EQ((unsigned)0, Minor);
956 EXPECT_EQ((unsigned)0, Micro);
958 T = Triple("x86_64-apple-macosx");
959 EXPECT_TRUE(T.isMacOSX());
960 EXPECT_FALSE(T.isiOS());
961 EXPECT_FALSE(T.isArch16Bit());
962 EXPECT_FALSE(T.isArch32Bit());
963 EXPECT_TRUE(T.isArch64Bit());
964 T.getMacOSXVersion(Major, Minor, Micro);
965 EXPECT_EQ((unsigned)10, Major);
966 EXPECT_EQ((unsigned)4, Minor);
967 EXPECT_EQ((unsigned)0, Micro);
968 T.getiOSVersion(Major, Minor, Micro);
969 EXPECT_EQ((unsigned)5, Major);
970 EXPECT_EQ((unsigned)0, Minor);
971 EXPECT_EQ((unsigned)0, Micro);
973 T = Triple("x86_64-apple-macosx10.7");
974 EXPECT_TRUE(T.isMacOSX());
975 EXPECT_FALSE(T.isiOS());
976 EXPECT_FALSE(T.isArch16Bit());
977 EXPECT_FALSE(T.isArch32Bit());
978 EXPECT_TRUE(T.isArch64Bit());
979 T.getMacOSXVersion(Major, Minor, Micro);
980 EXPECT_EQ((unsigned)10, Major);
981 EXPECT_EQ((unsigned)7, Minor);
982 EXPECT_EQ((unsigned)0, Micro);
983 T.getiOSVersion(Major, Minor, Micro);
984 EXPECT_EQ((unsigned)5, Major);
985 EXPECT_EQ((unsigned)0, Minor);
986 EXPECT_EQ((unsigned)0, Micro);
988 T = Triple("armv7-apple-ios");
989 EXPECT_FALSE(T.isMacOSX());
990 EXPECT_TRUE(T.isiOS());
991 EXPECT_FALSE(T.isArch16Bit());
992 EXPECT_TRUE(T.isArch32Bit());
993 EXPECT_FALSE(T.isArch64Bit());
994 T.getMacOSXVersion(Major, Minor, Micro);
995 EXPECT_EQ((unsigned)10, Major);
996 EXPECT_EQ((unsigned)4, Minor);
997 EXPECT_EQ((unsigned)0, Micro);
998 T.getiOSVersion(Major, Minor, Micro);
999 EXPECT_EQ((unsigned)5, Major);
1000 EXPECT_EQ((unsigned)0, Minor);
1001 EXPECT_EQ((unsigned)0, Micro);
1003 T = Triple("armv7-apple-ios7.0");
1004 EXPECT_FALSE(T.isMacOSX());
1005 EXPECT_TRUE(T.isiOS());
1006 EXPECT_FALSE(T.isArch16Bit());
1007 EXPECT_TRUE(T.isArch32Bit());
1008 EXPECT_FALSE(T.isArch64Bit());
1009 T.getMacOSXVersion(Major, Minor, Micro);
1010 EXPECT_EQ((unsigned)10, Major);
1011 EXPECT_EQ((unsigned)4, Minor);
1012 EXPECT_EQ((unsigned)0, Micro);
1013 T.getiOSVersion(Major, Minor, Micro);
1014 EXPECT_EQ((unsigned)7, Major);
1015 EXPECT_EQ((unsigned)0, Minor);
1016 EXPECT_EQ((unsigned)0, Micro);
1017 EXPECT_FALSE(T.isSimulatorEnvironment());
1019 T = Triple("x86_64-apple-ios10.3-simulator");
1020 EXPECT_TRUE(T.isiOS());
1021 T.getiOSVersion(Major, Minor, Micro);
1022 EXPECT_EQ((unsigned)10, Major);
1023 EXPECT_EQ((unsigned)3, Minor);
1024 EXPECT_EQ((unsigned)0, Micro);
1025 EXPECT_TRUE(T.isSimulatorEnvironment());
1028 TEST(TripleTest, FileFormat) {
1029 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-linux-gnu").getObjectFormat());
1030 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-freebsd").getObjectFormat());
1031 EXPECT_EQ(Triple::ELF, Triple("i686-unknown-netbsd").getObjectFormat());
1032 EXPECT_EQ(Triple::ELF, Triple("i686--win32-elf").getObjectFormat());
1033 EXPECT_EQ(Triple::ELF, Triple("i686---elf").getObjectFormat());
1035 EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
1036 EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
1037 EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
1039 EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
1041 EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
1042 EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat());
1044 EXPECT_EQ(Triple::Wasm, Triple("wasm32-unknown-unknown").getObjectFormat());
1045 EXPECT_EQ(Triple::Wasm, Triple("wasm64-unknown-unknown").getObjectFormat());
1047 EXPECT_EQ(Triple::Wasm,
1048 Triple("wasm32-unknown-unknown-wasm").getObjectFormat());
1049 EXPECT_EQ(Triple::Wasm,
1050 Triple("wasm64-unknown-unknown-wasm").getObjectFormat());
1052 EXPECT_EQ(Triple::ELF,
1053 Triple("wasm32-unknown-unknown-elf").getObjectFormat());
1054 EXPECT_EQ(Triple::ELF,
1055 Triple("wasm64-unknown-unknown-elf").getObjectFormat());
1057 Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
1058 EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
1060 Triple GNUWindowsNormalized(Triple::normalize("i686-pc-windows-gnu-elf"));
1061 EXPECT_EQ(Triple::ELF, GNUWindowsNormalized.getObjectFormat());
1063 Triple CygnusNormalised(Triple::normalize("i686-pc-windows-cygnus-elf"));
1064 EXPECT_EQ(Triple::ELF, CygnusNormalised.getObjectFormat());
1066 Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf"));
1067 EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat());
1069 Triple T = Triple("");
1070 T.setObjectFormat(Triple::ELF);
1071 EXPECT_EQ(Triple::ELF, T.getObjectFormat());
1073 T.setObjectFormat(Triple::MachO);
1074 EXPECT_EQ(Triple::MachO, T.getObjectFormat());
1077 TEST(TripleTest, NormalizeWindows) {
1078 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-win32"));
1079 EXPECT_EQ("i686--windows-msvc", Triple::normalize("i686-win32"));
1080 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32"));
1081 EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32"));
1082 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32-w64"));
1083 EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32-w64"));
1084 EXPECT_EQ("i686-pc-windows-cygnus", Triple::normalize("i686-pc-cygwin"));
1085 EXPECT_EQ("i686--windows-cygnus", Triple::normalize("i686-cygwin"));
1087 EXPECT_EQ("x86_64-pc-windows-msvc", Triple::normalize("x86_64-pc-win32"));
1088 EXPECT_EQ("x86_64--windows-msvc", Triple::normalize("x86_64-win32"));
1089 EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32"));
1090 EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32"));
1091 EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32-w64"));
1092 EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32-w64"));
1094 EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-win32-elf"));
1095 EXPECT_EQ("i686--windows-elf", Triple::normalize("i686-win32-elf"));
1096 EXPECT_EQ("i686-pc-windows-macho", Triple::normalize("i686-pc-win32-macho"));
1097 EXPECT_EQ("i686--windows-macho", Triple::normalize("i686-win32-macho"));
1099 EXPECT_EQ("x86_64-pc-windows-elf", Triple::normalize("x86_64-pc-win32-elf"));
1100 EXPECT_EQ("x86_64--windows-elf", Triple::normalize("x86_64-win32-elf"));
1101 EXPECT_EQ("x86_64-pc-windows-macho", Triple::normalize("x86_64-pc-win32-macho"));
1102 EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
1104 EXPECT_EQ("i686-pc-windows-cygnus",
1105 Triple::normalize("i686-pc-windows-cygnus"));
1106 EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
1107 EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
1108 EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
1110 EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
1113 TEST(TripleTest, getARMCPUForArch) {
1114 // Platform specific defaults.
1116 llvm::Triple Triple("arm--nacl");
1117 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
1120 llvm::Triple Triple("arm--openbsd");
1121 EXPECT_EQ("cortex-a8", Triple.getARMCPUForArch());
1124 llvm::Triple Triple("armv6-unknown-freebsd");
1125 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1128 llvm::Triple Triple("thumbv6-unknown-freebsd");
1129 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1132 llvm::Triple Triple("armebv6-unknown-freebsd");
1133 EXPECT_EQ("arm1176jzf-s", Triple.getARMCPUForArch());
1136 llvm::Triple Triple("arm--win32");
1137 EXPECT_EQ("cortex-a9", Triple.getARMCPUForArch());
1139 // Some alternative architectures
1141 llvm::Triple Triple("armv7k-apple-ios9");
1142 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1145 llvm::Triple Triple("armv7k-apple-watchos3");
1146 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1149 llvm::Triple Triple("armv7k-apple-tvos9");
1150 EXPECT_EQ("cortex-a7", Triple.getARMCPUForArch());
1152 // armeb is permitted, but armebeb is not
1154 llvm::Triple Triple("armeb-none-eabi");
1155 EXPECT_EQ("arm7tdmi", Triple.getARMCPUForArch());
1158 llvm::Triple Triple("armebeb-none-eabi");
1159 EXPECT_EQ("", Triple.getARMCPUForArch());
1162 llvm::Triple Triple("armebv6eb-none-eabi");
1163 EXPECT_EQ("", Triple.getARMCPUForArch());
1165 // xscaleeb is permitted, but armebxscale is not
1167 llvm::Triple Triple("xscaleeb-none-eabi");
1168 EXPECT_EQ("xscale", Triple.getARMCPUForArch());
1171 llvm::Triple Triple("armebxscale-none-eabi");
1172 EXPECT_EQ("", Triple.getARMCPUForArch());
1176 TEST(TripleTest, NormalizeARM) {
1177 EXPECT_EQ("armv6--netbsd-eabi", Triple::normalize("armv6-netbsd-eabi"));
1178 EXPECT_EQ("armv7--netbsd-eabi", Triple::normalize("armv7-netbsd-eabi"));
1179 EXPECT_EQ("armv6eb--netbsd-eabi", Triple::normalize("armv6eb-netbsd-eabi"));
1180 EXPECT_EQ("armv7eb--netbsd-eabi", Triple::normalize("armv7eb-netbsd-eabi"));
1181 EXPECT_EQ("armv6--netbsd-eabihf", Triple::normalize("armv6-netbsd-eabihf"));
1182 EXPECT_EQ("armv7--netbsd-eabihf", Triple::normalize("armv7-netbsd-eabihf"));
1183 EXPECT_EQ("armv6eb--netbsd-eabihf", Triple::normalize("armv6eb-netbsd-eabihf"));
1184 EXPECT_EQ("armv7eb--netbsd-eabihf", Triple::normalize("armv7eb-netbsd-eabihf"));
1186 EXPECT_EQ("armv7-suse-linux-gnueabihf",
1187 Triple::normalize("armv7-suse-linux-gnueabi"));
1190 T = Triple("armv6--netbsd-eabi");
1191 EXPECT_EQ(Triple::arm, T.getArch());
1192 T = Triple("armv6eb--netbsd-eabi");
1193 EXPECT_EQ(Triple::armeb, T.getArch());
1194 T = Triple("armv7-suse-linux-gnueabihf");
1195 EXPECT_EQ(Triple::GNUEABIHF, T.getEnvironment());
1198 TEST(TripleTest, ParseARMArch) {
1201 Triple T = Triple("arm");
1202 EXPECT_EQ(Triple::arm, T.getArch());
1205 Triple T = Triple("armeb");
1206 EXPECT_EQ(Triple::armeb, T.getArch());
1210 Triple T = Triple("thumb");
1211 EXPECT_EQ(Triple::thumb, T.getArch());
1214 Triple T = Triple("thumbeb");
1215 EXPECT_EQ(Triple::thumbeb, T.getArch());
1219 Triple T = Triple("arm64");
1220 EXPECT_EQ(Triple::aarch64, T.getArch());
1223 Triple T = Triple("aarch64");
1224 EXPECT_EQ(Triple::aarch64, T.getArch());
1227 Triple T = Triple("aarch64_be");
1228 EXPECT_EQ(Triple::aarch64_be, T.getArch());
1231 } // end anonymous namespace