Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/StaticAnalyzer/Core/BlockCounter.cpp
Line
Count
Source
1
//==- BlockCounter.h - ADT for counting block visits -------------*- 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 BlockCounter, an abstract data type used to count
10
//  the number of times a given block has been visited along a path
11
//  analyzed by CoreEngine.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "clang/StaticAnalyzer/Core/PathSensitive/BlockCounter.h"
16
#include "llvm/ADT/ImmutableMap.h"
17
18
using namespace clang;
19
using namespace ento;
20
21
namespace {
22
23
class CountKey {
24
  const StackFrameContext *CallSite;
25
  unsigned BlockID;
26
27
public:
28
  CountKey(const StackFrameContext *CS, unsigned ID)
29
434k
    : CallSite(CS), BlockID(ID) {}
30
31
1.74M
  bool operator==(const CountKey &RHS) const {
32
1.74M
    return (CallSite == RHS.CallSite) && 
(BlockID == RHS.BlockID)1.03M
;
33
1.74M
  }
34
35
1.15M
  bool operator<(const CountKey &RHS) const {
36
1.15M
    return std::tie(CallSite, BlockID) < std::tie(RHS.CallSite, RHS.BlockID);
37
1.15M
  }
38
39
440k
  void Profile(llvm::FoldingSetNodeID &ID) const {
40
440k
    ID.AddPointer(CallSite);
41
440k
    ID.AddInteger(BlockID);
42
440k
  }
43
};
44
45
}
46
47
typedef llvm::ImmutableMap<CountKey, unsigned> CountMap;
48
49
434k
static inline CountMap GetMap(void *D) {
50
434k
  return CountMap(static_cast<CountMap::TreeTy*>(D));
51
434k
}
52
53
125k
static inline CountMap::Factory& GetFactory(void *F) {
54
125k
  return *static_cast<CountMap::Factory*>(F);
55
125k
}
56
57
unsigned BlockCounter::getNumVisited(const StackFrameContext *CallSite,
58
320k
                                       unsigned BlockID) const {
59
320k
  CountMap M = GetMap(Data);
60
320k
  CountMap::data_type* T = M.lookup(CountKey(CallSite, BlockID));
61
320k
  return T ? 
*T172k
:
0147k
;
62
320k
}
63
64
10.8k
BlockCounter::Factory::Factory(llvm::BumpPtrAllocator& Alloc) {
65
10.8k
  F = new CountMap::Factory(Alloc);
66
10.8k
}
67
68
10.8k
BlockCounter::Factory::~Factory() {
69
10.8k
  delete static_cast<CountMap::Factory*>(F);
70
10.8k
}
71
72
BlockCounter
73
BlockCounter::Factory::IncrementCount(BlockCounter BC,
74
                                        const StackFrameContext *CallSite,
75
114k
                                        unsigned BlockID) {
76
114k
  return BlockCounter(GetFactory(F).add(GetMap(BC.Data),
77
114k
                                          CountKey(CallSite, BlockID),
78
114k
                             BC.getNumVisited(CallSite, BlockID)+1).getRoot());
79
114k
}
80
81
BlockCounter
82
10.8k
BlockCounter::Factory::GetEmptyCounter() {
83
10.8k
  return BlockCounter(GetFactory(F).getEmptyMap().getRoot());
84
10.8k
}