1 //=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/CallGraph.h"
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/Module.h"
12 #include "gtest/gtest.h"
18 template <typename Ty
> void canSpecializeGraphTraitsIterators(Ty
*G
) {
19 typedef typename GraphTraits
<Ty
*>::NodeRef NodeRef
;
21 auto I
= GraphTraits
<Ty
*>::nodes_begin(G
);
22 auto E
= GraphTraits
<Ty
*>::nodes_end(G
);
25 // Should be able to iterate over all nodes of the graph.
26 static_assert(std::is_same
<decltype(*I
), NodeRef
>::value
,
27 "Node type does not match");
28 static_assert(std::is_same
<decltype(*X
), NodeRef
>::value
,
29 "Node type does not match");
30 static_assert(std::is_same
<decltype(*E
), NodeRef
>::value
,
31 "Node type does not match");
33 NodeRef N
= GraphTraits
<Ty
*>::getEntryNode(G
);
35 auto S
= GraphTraits
<NodeRef
>::child_begin(N
);
36 auto F
= GraphTraits
<NodeRef
>::child_end(N
);
38 // Should be able to iterate over immediate successors of a node.
39 static_assert(std::is_same
<decltype(*S
), NodeRef
>::value
,
40 "Node type does not match");
41 static_assert(std::is_same
<decltype(*F
), NodeRef
>::value
,
42 "Node type does not match");
45 TEST(CallGraphTest
, GraphTraitsSpecialization
) {
47 Module
M("", Context
);
50 canSpecializeGraphTraitsIterators(&CG
);
53 TEST(CallGraphTest
, GraphTraitsConstSpecialization
) {
55 Module
M("", Context
);
58 canSpecializeGraphTraitsIterators(const_cast<const CallGraph
*>(&CG
));