46 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// The target registry code lives in Support, but it relies on linking in all10// LLVM targets. We keep this test with the MC tests, which already do that, to11// keep the SupportTests target small.12 13#include "llvm/MC/TargetRegistry.h"14#include "llvm/Support/TargetSelect.h"15#include "gtest/gtest.h"16 17using namespace llvm;18 19namespace {20 21TEST(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 targets31 // a specific architecture, because the logic for that is buried in a32 // predicate.33 // We can't ask the predicate "Are you a function that always returns34 // 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(Name);38 EXPECT_NE(Arch, Triple::UnknownArch);39 ++Count;40 }41 }42 ASSERT_NE(Count, 0);43}44 45} // end namespace46