Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Analysis/ProgramPoint.cpp
Line
Count
Source (jump to first uncovered line)
1
//==- ProgramPoint.cpp - Program Points for Path-Sensitive Analysis -*- C++ -*-/
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
//===----------------------------------------------------------------------===//
8
//
9
//  This file defines the interface ProgramPoint, which identifies a
10
//  distinct location in a function.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Analysis/ProgramPoint.h"
15
#include "clang/Basic/JsonSupport.h"
16
17
using namespace clang;
18
19
17.3k
ProgramPointTag::~ProgramPointTag() {}
20
21
ProgramPoint ProgramPoint::getProgramPoint(const Stmt *S, ProgramPoint::Kind K,
22
                                           const LocationContext *LC,
23
3.62M
                                           const ProgramPointTag *tag){
24
3.62M
  switch (K) {
25
3.62M
    default:
26
0
      llvm_unreachable("Unhandled ProgramPoint kind");
27
3.62M
    case ProgramPoint::PreStmtKind:
28
464k
      return PreStmt(S, LC, tag);
29
3.62M
    case ProgramPoint::PostStmtKind:
30
1.00M
      return PostStmt(S, LC, tag);
31
3.62M
    case ProgramPoint::PreLoadKind:
32
367k
      return PreLoad(S, LC, tag);
33
3.62M
    case ProgramPoint::PostLoadKind:
34
149k
      return PostLoad(S, LC, tag);
35
3.62M
    case ProgramPoint::PreStoreKind:
36
74.5k
      return PreStore(S, LC, tag);
37
3.62M
    case ProgramPoint::PostLValueKind:
38
256k
      return PostLValue(S, LC, tag);
39
3.62M
    case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
40
224k
      return PostStmtPurgeDeadSymbols(S, LC, tag);
41
3.62M
    case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
42
1.08M
      return PreStmtPurgeDeadSymbols(S, LC, tag);
43
3.62M
  }
44
3.62M
}
45
46
0
LLVM_DUMP_METHOD void ProgramPoint::dump() const {
47
0
  return printJson(llvm::errs());
48
0
}
49
50
0
void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {
51
0
  const ASTContext &Context =
52
0
      getLocationContext()->getAnalysisDeclContext()->getASTContext();
53
0
  const SourceManager &SM = Context.getSourceManager();
54
0
  const PrintingPolicy &PP = Context.getPrintingPolicy();
55
0
  const bool AddQuotes = true;
56
0
57
0
  Out << "\"kind\": \"";
58
0
  switch (getKind()) {
59
0
  case ProgramPoint::BlockEntranceKind:
60
0
    Out << "BlockEntrance\""
61
0
        << ", \"block_id\": "
62
0
        << castAs<BlockEntrance>().getBlock()->getBlockID();
63
0
    break;
64
0
65
0
  case ProgramPoint::FunctionExitKind: {
66
0
    auto FEP = getAs<FunctionExitPoint>();
67
0
    Out << "FunctionExit\""
68
0
        << ", \"block_id\": " << FEP->getBlock()->getBlockID()
69
0
        << ", \"stmt_id\": ";
70
0
71
0
    if (const ReturnStmt *RS = FEP->getStmt()) {
72
0
      Out << RS->getID(Context) << ", \"stmt\": ";
73
0
      RS->printJson(Out, nullptr, PP, AddQuotes);
74
0
    } else {
75
0
      Out << "null, \"stmt\": null";
76
0
    }
77
0
    break;
78
0
  }
79
0
  case ProgramPoint::BlockExitKind:
80
0
    llvm_unreachable("BlockExitKind");
81
0
    break;
82
0
  case ProgramPoint::CallEnterKind:
83
0
    Out << "CallEnter\"";
84
0
    break;
85
0
  case ProgramPoint::CallExitBeginKind:
86
0
    Out << "CallExitBegin\"";
87
0
    break;
88
0
  case ProgramPoint::CallExitEndKind:
89
0
    Out << "CallExitEnd\"";
90
0
    break;
91
0
  case ProgramPoint::EpsilonKind:
92
0
    Out << "EpsilonPoint\"";
93
0
    break;
94
0
95
0
  case ProgramPoint::LoopExitKind:
96
0
    Out << "LoopExit\", \"stmt\": \""
97
0
        << castAs<LoopExit>().getLoopStmt()->getStmtClassName() << '\"';
98
0
    break;
99
0
100
0
  case ProgramPoint::PreImplicitCallKind: {
101
0
    ImplicitCallPoint PC = castAs<ImplicitCallPoint>();
102
0
    Out << "PreCall\", \"decl\": \""
103
0
        << PC.getDecl()->getAsFunction()->getQualifiedNameAsString()
104
0
        << "\", \"location\": ";
105
0
    printSourceLocationAsJson(Out, PC.getLocation(), SM);
106
0
    break;
107
0
  }
108
0
109
0
  case ProgramPoint::PostImplicitCallKind: {
110
0
    ImplicitCallPoint PC = castAs<ImplicitCallPoint>();
111
0
    Out << "PostCall\", \"decl\": \""
112
0
        << PC.getDecl()->getAsFunction()->getQualifiedNameAsString()
113
0
        << "\", \"location\": ";
114
0
    printSourceLocationAsJson(Out, PC.getLocation(), SM);
115
0
    break;
116
0
  }
117
0
118
0
  case ProgramPoint::PostInitializerKind: {
119
0
    Out << "PostInitializer\", ";
120
0
    const CXXCtorInitializer *Init = castAs<PostInitializer>().getInitializer();
121
0
    if (const FieldDecl *FD = Init->getAnyMember()) {
122
0
      Out << "\"field_decl\": \"" << *FD << '\"';
123
0
    } else {
124
0
      Out << "\"type\": \"";
125
0
      QualType Ty = Init->getTypeSourceInfo()->getType();
126
0
      Ty = Ty.getLocalUnqualifiedType();
127
0
      Ty.print(Out, Context.getLangOpts());
128
0
      Out << '\"';
129
0
    }
130
0
    break;
131
0
  }
132
0
133
0
  case ProgramPoint::BlockEdgeKind: {
134
0
    const BlockEdge &E = castAs<BlockEdge>();
135
0
    const Stmt *T = E.getSrc()->getTerminatorStmt();
136
0
    Out << "Edge\", \"src_id\": " << E.getSrc()->getBlockID()
137
0
        << ", \"dst_id\": " << E.getDst()->getBlockID() << ", \"terminator\": ";
138
0
139
0
    if (!T) {
140
0
      Out << "null, \"term_kind\": null";
141
0
      break;
142
0
    }
143
0
144
0
    E.getSrc()->printTerminatorJson(Out, Context.getLangOpts(),
145
0
                                    /*AddQuotes=*/true);
146
0
    Out << ", \"location\": ";
147
0
    printSourceLocationAsJson(Out, T->getBeginLoc(), SM);
148
0
149
0
    Out << ", \"term_kind\": \"";
150
0
    if (isa<SwitchStmt>(T)) {
151
0
      Out << "SwitchStmt\", \"case\": ";
152
0
      if (const Stmt *Label = E.getDst()->getLabel()) {
153
0
        if (const auto *C = dyn_cast<CaseStmt>(Label)) {
154
0
          Out << "{ \"lhs\": ";
155
0
          if (const Stmt *LHS = C->getLHS()) {
156
0
            LHS->printJson(Out, nullptr, PP, AddQuotes);
157
0
          } else {
158
0
            Out << "null";
159
0
    }
160
0
161
0
          Out << ", \"rhs\": ";
162
0
          if (const Stmt *RHS = C->getRHS()) {
163
0
            RHS->printJson(Out, nullptr, PP, AddQuotes);
164
0
          } else {
165
0
            Out << "null";
166
0
          }
167
0
          Out << " }";
168
0
        } else {
169
0
          assert(isa<DefaultStmt>(Label));
170
0
          Out << "\"default\"";
171
0
        }
172
0
      } else {
173
0
        Out << "\"implicit default\"";
174
0
      }
175
0
    } else if (isa<IndirectGotoStmt>(T)) {
176
0
      // FIXME: More info.
177
0
      Out << "IndirectGotoStmt\"";
178
0
    } else {
179
0
      Out << "Condition\", \"value\": "
180
0
          << (*E.getSrc()->succ_begin() == E.getDst() ? "true" : "false");
181
0
    }
182
0
    break;
183
0
  }
184
0
185
0
  default: {
186
0
    const Stmt *S = castAs<StmtPoint>().getStmt();
187
0
    assert(S != nullptr && "Expecting non-null Stmt");
188
0
189
0
    Out << "Statement\", \"stmt_kind\": \"" << S->getStmtClassName()
190
0
        << "\", \"stmt_id\": " << S->getID(Context)
191
0
        << ", \"pointer\": \"" << (const void *)S << "\", \"pretty\": ";
192
0
193
0
    S->printJson(Out, nullptr, PP, AddQuotes);
194
0
195
0
    Out << ", \"location\": ";
196
0
    printSourceLocationAsJson(Out, S->getBeginLoc(), SM);
197
0
198
0
    Out << ", \"stmt_point_kind\": \"";
199
0
    if (getAs<PreLoad>())
200
0
      Out << "PreLoad";
201
0
    else if (getAs<PreStore>())
202
0
      Out << "PreStore";
203
0
    else if (getAs<PostAllocatorCall>())
204
0
      Out << "PostAllocatorCall";
205
0
    else if (getAs<PostCondition>())
206
0
      Out << "PostCondition";
207
0
    else if (getAs<PostLoad>())
208
0
      Out << "PostLoad";
209
0
    else if (getAs<PostLValue>())
210
0
      Out << "PostLValue";
211
0
    else if (getAs<PostStore>())
212
0
      Out << "PostStore";
213
0
    else if (getAs<PostStmt>())
214
0
      Out << "PostStmt";
215
0
    else if (getAs<PostStmtPurgeDeadSymbols>())
216
0
      Out << "PostStmtPurgeDeadSymbols";
217
0
    else if (getAs<PreStmtPurgeDeadSymbols>())
218
0
      Out << "PreStmtPurgeDeadSymbols";
219
0
    else if (getAs<PreStmt>())
220
0
      Out << "PreStmt";
221
0
    else {
222
0
      Out << "\nKind: '" << getKind();
223
0
      llvm_unreachable("' is unhandled StmtPoint kind!");
224
0
    }
225
0
226
0
    Out << '\"';
227
0
    break;
228
0
  }
229
0
  }
230
0
}
231
232
SimpleProgramPointTag::SimpleProgramPointTag(StringRef MsgProvider,
233
                                             StringRef Msg)
234
3.51k
  : Desc((MsgProvider + " : " + Msg).str()) {}
235
236
0
StringRef SimpleProgramPointTag::getTagDescription() const {
237
0
  return Desc;
238
0
}