[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / Analysis / CallGraphTest.cpp
blob0060d2c4b23969c62eeabdc19d3ff17b91b05e93
1 //=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/CallGraph.h"
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/Module.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace {
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);
23 auto X = ++I;
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) {
46 LLVMContext Context;
47 Module M("", Context);
48 CallGraph CG(M);
50 canSpecializeGraphTraitsIterators(&CG);
53 TEST(CallGraphTest, GraphTraitsConstSpecialization) {
54 LLVMContext Context;
55 Module M("", Context);
56 CallGraph CG(M);
58 canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));