[clang][NFC] simplify the unset check in `ParseLabeledStatement` (#117430)
[llvm-project.git] / clang / test / Analysis / debug-CallGraph.cpp
blob120bb38d3bb339d7253a84a3b14a8baa68ff2fa8
1 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCallGraph %s -fblocks -std=c++14 2>&1 | FileCheck %s
3 int get5() {
4 return 5;
7 int add(int val1, int val2) {
8 return val1 + val2;
11 int test_add() {
12 return add(10, get5());
15 static void mmm(int y) {
16 if (y != 0)
17 y++;
18 y = y/y;
21 static int foo(int x, int y) {
22 mmm(y);
23 if (x != 0)
24 x++;
25 return 5/x;
28 void aaa() {
29 foo(1,2);
32 void bbb(int y) {
33 int x = (y > 2);
34 ^ {
35 foo(x, y);
36 }();
38 void ccc();
39 void ddd() { ccc(); }
40 void ccc() {}
42 void eee();
43 void eee() {}
44 void fff() { eee(); }
46 // This test case tests that forward declaration for the top-level function
47 // does not affect call graph construction.
48 void do_nothing() {}
49 void test_single_call();
50 void test_single_call() {
51 do_nothing();
54 namespace SomeNS {
55 template<typename T>
56 void templ(T t) {
57 ccc();
60 template<>
61 void templ<double>(double t) {
62 eee();
65 void templUser() {
66 templ(5);
67 templ(5.5);
71 namespace Lambdas {
72 void Callee(){}
74 void f1() {
75 [](int i) {
76 Callee();
77 }(1);
78 [](auto i) {
79 Callee();
80 }(1);
84 namespace CallDecl {
85 void SomeDecl();
86 void SomeOtherDecl();
87 void SomeDef() {}
89 void Caller() {
90 SomeDecl();
91 SomeOtherDecl();
94 void SomeOtherDecl() {
95 SomeDef();
99 // CHECK:--- Call graph Dump ---
100 // CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call SomeNS::templ SomeNS::templ SomeNS::templUser Lambdas::Callee Lambdas::f1 Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) CallDecl::SomeDef CallDecl::Caller CallDecl::SomeDecl CallDecl::SomeOtherDecl $}}
101 // CHECK-NEXT: {{Function: CallDecl::Caller calls: CallDecl::SomeDecl CallDecl::SomeOtherDecl $}}
102 // CHECK-NEXT: {{Function: CallDecl::SomeOtherDecl calls: CallDecl::SomeDef $}}
103 // CHECK-NEXT: {{Function: CallDecl::SomeDecl calls: $}}
104 // CHECK-NEXT: {{Function: CallDecl::SomeDef calls: $}}
105 // CHECK-NEXT: {{Function: Lambdas::f1 calls: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) Lambdas::f1\(\)::\(anonymous class\)::operator\(\) $}}
106 // CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}}
107 // CHECK-NEXT: {{Function: Lambdas::f1\(\)::\(anonymous class\)::operator\(\) calls: Lambdas::Callee $}}
108 // CHECK-NEXT: {{Function: Lambdas::Callee calls: $}}
109 // CHECK-NEXT: {{Function: SomeNS::templUser calls: SomeNS::templ SomeNS::templ $}}
110 // CHECK-NEXT: {{Function: SomeNS::templ calls: eee $}}
111 // CHECK-NEXT: {{Function: SomeNS::templ calls: ccc $}}
112 // CHECK-NEXT: {{Function: test_single_call calls: do_nothing $}}
113 // CHECK-NEXT: {{Function: do_nothing calls: $}}
114 // CHECK-NEXT: {{Function: fff calls: eee $}}
115 // CHECK-NEXT: {{Function: eee calls: $}}
116 // CHECK-NEXT: {{Function: ddd calls: ccc $}}
117 // CHECK-NEXT: {{Function: ccc calls: $}}
118 // CHECK-NEXT: {{Function: bbb calls: < > $}}
119 // CHECK-NEXT: {{Function: < > calls: foo $}}
120 // CHECK-NEXT: {{Function: aaa calls: foo $}}
121 // CHECK-NEXT: {{Function: foo calls: mmm $}}
122 // CHECK-NEXT: {{Function: mmm calls: $}}
123 // CHECK-NEXT: {{Function: test_add calls: add get5 $}}
124 // CHECK-NEXT: {{Function: add calls: $}}
125 // CHECK-NEXT: {{Function: get5 calls: $}}