TargetRegistry.cpp 1.6 KB

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