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