CallGraphTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
  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/Analysis/CallGraph.h"
  10. #include "llvm/IR/LLVMContext.h"
  11. #include "llvm/IR/Module.h"
  12. #include "gtest/gtest.h"
  13. using namespace llvm;
  14. namespace {
  15. template <typename Ty> void canSpecializeGraphTraitsIterators(Ty *G) {
  16. typedef typename GraphTraits<Ty *>::NodeType NodeTy;
  17. auto I = GraphTraits<Ty *>::nodes_begin(G);
  18. auto E = GraphTraits<Ty *>::nodes_end(G);
  19. auto X = ++I;
  20. // Should be able to iterate over all nodes of the graph.
  21. static_assert(std::is_same<decltype(*I), NodeTy &>::value,
  22. "Node type does not match");
  23. static_assert(std::is_same<decltype(*X), NodeTy &>::value,
  24. "Node type does not match");
  25. static_assert(std::is_same<decltype(*E), NodeTy &>::value,
  26. "Node type does not match");
  27. NodeTy *N = GraphTraits<Ty *>::getEntryNode(G);
  28. auto S = GraphTraits<NodeTy *>::child_begin(N);
  29. auto F = GraphTraits<NodeTy *>::child_end(N);
  30. // Should be able to iterate over immediate successors of a node.
  31. static_assert(std::is_same<decltype(*S), NodeTy *>::value,
  32. "Node type does not match");
  33. static_assert(std::is_same<decltype(*F), NodeTy *>::value,
  34. "Node type does not match");
  35. }
  36. TEST(CallGraphTest, GraphTraitsSpecialization) {
  37. Module M("", getGlobalContext());
  38. CallGraph CG(M);
  39. canSpecializeGraphTraitsIterators(&CG);
  40. }
  41. TEST(CallGraphTest, GraphTraitsConstSpecialization) {
  42. Module M("", getGlobalContext());
  43. CallGraph CG(M);
  44. canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
  45. }
  46. }