Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
Line
Count
Source
1
//==- WorkList.h - Worklist class used by CoreEngine ---------------*- 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 WorkList, a pure virtual class that represents an opaque
10
//  worklist used by CoreEngine to explore the reachability state space.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_WORKLIST_H
15
#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_WORKLIST_H
16
17
#include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
18
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
19
#include <cassert>
20
21
namespace clang {
22
23
class CFGBlock;
24
25
namespace ento {
26
27
class WorkListUnit {
28
  ExplodedNode *node;
29
  BlockCounter counter;
30
  const CFGBlock *block;
31
  unsigned blockIdx; // This is the index of the next statement.
32
33
public:
34
  WorkListUnit(ExplodedNode *N, BlockCounter C,
35
               const CFGBlock *B, unsigned idx)
36
  : node(N),
37
    counter(C),
38
    block(B),
39
892k
    blockIdx(idx) {}
40
41
  explicit WorkListUnit(ExplodedNode *N, BlockCounter C)
42
  : node(N),
43
    counter(C),
44
    block(nullptr),
45
384k
    blockIdx(0) {}
46
47
  /// Returns the node associated with the worklist unit.
48
2.40M
  ExplodedNode *getNode() const { return node; }
49
50
  /// Returns the block counter map associated with the worklist unit.
51
1.26M
  BlockCounter getBlockCounter() const { return counter; }
52
53
  /// Returns the CFGblock associated with the worklist unit.
54
892k
  const CFGBlock *getBlock() const { return block; }
55
56
  /// Return the index within the CFGBlock for the worklist unit.
57
892k
  unsigned getIndex() const { return blockIdx; }
58
};
59
60
class WorkList {
61
  BlockCounter CurrentCounter;
62
public:
63
  virtual ~WorkList();
64
  virtual bool hasWork() const = 0;
65
66
  virtual void enqueue(const WorkListUnit& U) = 0;
67
68
892k
  void enqueue(ExplodedNode *N, const CFGBlock *B, unsigned idx) {
69
892k
    enqueue(WorkListUnit(N, CurrentCounter, B, idx));
70
892k
  }
71
72
384k
  void enqueue(ExplodedNode *N) {
73
384k
    assert(N->getLocation().getKind() != ProgramPoint::PostStmtKind);
74
384k
    enqueue(WorkListUnit(N, CurrentCounter));
75
384k
  }
76
77
  virtual WorkListUnit dequeue() = 0;
78
79
1.38M
  void setBlockCounter(BlockCounter C) { CurrentCounter = C; }
80
320k
  BlockCounter getBlockCounter() const { return CurrentCounter; }
81
82
  static std::unique_ptr<WorkList> makeDFS();
83
  static std::unique_ptr<WorkList> makeBFS();
84
  static std::unique_ptr<WorkList> makeBFSBlockDFSContents();
85
  static std::unique_ptr<WorkList> makeUnexploredFirst();
86
  static std::unique_ptr<WorkList> makeUnexploredFirstPriorityQueue();
87
  static std::unique_ptr<WorkList> makeUnexploredFirstPriorityLocationQueue();
88
};
89
90
} // end ento namespace
91
92
} // end clang namespace
93
94
#endif