1 //=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Analysis/CallGraph.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/Module.h"
13 #include "gtest/gtest.h"
19 template <typename Ty
> void canSpecializeGraphTraitsIterators(Ty
*G
) {
20 typedef typename GraphTraits
<Ty
*>::NodeRef NodeRef
;
22 auto I
= GraphTraits
<Ty
*>::nodes_begin(G
);
23 auto E
= GraphTraits
<Ty
*>::nodes_end(G
);
26 // Should be able to iterate over all nodes of the graph.
27 static_assert(std::is_same
<decltype(*I
), NodeRef
>::value
,
28 "Node type does not match");
29 static_assert(std::is_same
<decltype(*X
), NodeRef
>::value
,
30 "Node type does not match");
31 static_assert(std::is_same
<decltype(*E
), NodeRef
>::value
,
32 "Node type does not match");
34 NodeRef N
= GraphTraits
<Ty
*>::getEntryNode(G
);
36 auto S
= GraphTraits
<NodeRef
>::child_begin(N
);
37 auto F
= GraphTraits
<NodeRef
>::child_end(N
);
39 // Should be able to iterate over immediate successors of a node.
40 static_assert(std::is_same
<decltype(*S
), NodeRef
>::value
,
41 "Node type does not match");
42 static_assert(std::is_same
<decltype(*F
), NodeRef
>::value
,
43 "Node type does not match");
46 TEST(CallGraphTest
, GraphTraitsSpecialization
) {
48 Module
M("", Context
);
51 canSpecializeGraphTraitsIterators(&CG
);
54 TEST(CallGraphTest
, GraphTraitsConstSpecialization
) {
56 Module
M("", Context
);
59 canSpecializeGraphTraitsIterators(const_cast<const CallGraph
*>(&CG
));