1 | //===- unittests/MC/TargetRegistry.cpp ------------------------------------===// |
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 | // The target registry code lives in Support, but it relies on linking in all |
10 | // LLVM targets. We keep this test with the MC tests, which already do that, to |
11 | // keep the SupportTests target small. |
12 | |
13 | #include "llvm/MC/TargetRegistry.h" |
14 | #include "llvm/Support/TargetSelect.h" |
15 | #include "gtest/gtest.h" |
16 | |
17 | using namespace llvm; |
18 | |
19 | namespace { |
20 | |
21 | TEST(TargetRegistry, TargetHasArchType) { |
22 | // Presence of at least one target will be asserted when done with the loop, |
23 | // else this would pass by accident if InitializeAllTargetInfos were omitted. |
24 | int Count = 0; |
25 | |
26 | llvm::InitializeAllTargetInfos(); |
27 | |
28 | for (const Target &T : TargetRegistry::targets()) { |
29 | StringRef Name = T.getName(); |
30 | // There is really no way (at present) to ask a Target whether it targets |
31 | // a specific architecture, because the logic for that is buried in a |
32 | // predicate. |
33 | // We can't ask the predicate "Are you a function that always returns |
34 | // false?" |
35 | // So given that the cpp backend truly has no target arch, it is skipped. |
36 | if (Name != "cpp" ) { |
37 | Triple::ArchType Arch = Triple::getArchTypeForLLVMName(Str: Name); |
38 | EXPECT_NE(Arch, Triple::UnknownArch); |
39 | ++Count; |
40 | } |
41 | } |
42 | ASSERT_NE(Count, 0); |
43 | } |
44 | |
45 | } // end namespace |
46 | |