2
0

TargetRegistry.cpp 1.3 KB

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