Index: unittests/MC/CMakeLists.txt =================================================================== --- unittests/MC/CMakeLists.txt +++ unittests/MC/CMakeLists.txt @@ -3,10 +3,12 @@ MC MCDisassembler Support + AllTargetsInfos ) add_llvm_unittest(MCTests Disassembler.cpp StringTableBuilderTest.cpp + TargetRegistry.cpp YAMLTest.cpp ) Index: unittests/MC/TargetRegistry.cpp =================================================================== --- /dev/null +++ unittests/MC/TargetRegistry.cpp @@ -0,0 +1,37 @@ +//===- unittests/MC/TargetRegistry.cpp - ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(TargetRegistry, PrintAll) { + llvm::InitializeAllTargetInfos(); + int i = 0; + for (auto it = llvm::TargetRegistry::begin() ; it != llvm::TargetRegistry::end() ; + ++it) { + StringRef s = it->getName(); + // There is really no way (at present) to ask a Target whether it targets + // a specific architecture, because the logic for that is buried in a predicate. + // We can't ask the predicate "Are you a function that always returns false?" + // So given that the cpp backend truly has no target arch, we have to skip it. + if (s != "cpp") { + Triple::ArchType arch = Triple::getArchTypeForLLVMName(s); + ASSERT_NE(arch, Triple::UnknownArch); + ++i; + } + } + ASSERT_NE(i, 0); +} + +} // end namespace