blob: ae89c8b6493038bfd67c63a885771a5d031bbfc7 [file] [log] [blame]
Douglas Katzmanec1fc972015-05-08 15:34:12 +00001//===- unittests/Support/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#include "llvm/Support/TargetRegistry.h"
11#include "llvm/Support/TargetSelect.h"
12#include "gtest/gtest.h"
13
14using namespace llvm;
15
16namespace {
17
18TEST(TargetRegistry, TargetHasArchType) {
19 // Presence of at least one target will be asserted when done with the loop,
20 // else this would pass by accident if InitializeAllTargetInfos were omitted.
21 int Count = 0;
22
23 llvm::InitializeAllTargetInfos();
24
David Blaikie46c561c2015-05-11 22:20:48 +000025 for (const Target &T : TargetRegistry::targets()) {
26 StringRef Name = T.getName();
Douglas Katzmanec1fc972015-05-08 15:34:12 +000027 // There is really no way (at present) to ask a Target whether it targets
28 // a specific architecture, because the logic for that is buried in a
29 // predicate.
30 // We can't ask the predicate "Are you a function that always returns
31 // false?"
32 // So given that the cpp backend truly has no target arch, it is skipped.
33 if (Name != "cpp") {
34 Triple::ArchType Arch = Triple::getArchTypeForLLVMName(Name);
35 EXPECT_NE(Arch, Triple::UnknownArch);
36 ++Count;
37 }
38 }
39 ASSERT_NE(Count, 0);
40}
41
42} // end namespace