Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Analysis/Support/BumpVector.h
Line
Count
Source (jump to first uncovered line)
1
//===- BumpVector.h - Vector-like ADT that uses bump allocation -*- 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 provides BumpVector, a vector-like ADT whose contents are
10
//  allocated from a BumpPtrAllocator.
11
//
12
//===----------------------------------------------------------------------===//
13
14
// FIXME: Most of this is copy-and-paste from SmallVector.h.  We can
15
// refactor this core logic into something common that is shared between
16
// the two.  The main thing that is different is the allocation strategy.
17
18
#ifndef LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H
19
#define LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H
20
21
#include "llvm/ADT/PointerIntPair.h"
22
#include "llvm/Support/Allocator.h"
23
#include <cassert>
24
#include <cstddef>
25
#include <cstring>
26
#include <iterator>
27
#include <memory>
28
#include <type_traits>
29
30
namespace clang {
31
32
class BumpVectorContext {
33
  llvm::PointerIntPair<llvm::BumpPtrAllocator*, 1> Alloc;
34
35
public:
36
  /// Construct a new BumpVectorContext that creates a new BumpPtrAllocator
37
  /// and destroys it when the BumpVectorContext object is destroyed.
38
277k
  BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), 1) {}
39
40
3.22k
  BumpVectorContext(BumpVectorContext &&Other) : Alloc(Other.Alloc) {
41
3.22k
    Other.Alloc.setInt(false);
42
3.22k
    Other.Alloc.setPointer(nullptr);
43
3.22k
  }
44
45
  /// Construct a new BumpVectorContext that reuses an existing
46
  /// BumpPtrAllocator.  This BumpPtrAllocator is not destroyed when the
47
  /// BumpVectorContext object is destroyed.
48
3.86k
  BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, 0) {}
49
50
281k
  ~BumpVectorContext() {
51
281k
    if (Alloc.getInt())
52
277k
      delete Alloc.getPointer();
53
281k
  }
54
55
11.5M
  llvm::BumpPtrAllocator &getAllocator() { return *Alloc.getPointer(); }
56
};
57
58
template<typename T>
59
class BumpVector {
60
  T *Begin = nullptr;
61
  T *End = nullptr;
62
  T *Capacity = nullptr;
63
64
public:
65
  // Default ctor - Initialize to empty.
66
3.39M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
3.39M
    reserve(C, N);
68
3.39M
  }
clang::BumpVector<clang::VarDecl const*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
403
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
403
    reserve(C, N);
68
403
  }
clang::BumpVector<clang::CFGElement>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
1.03M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
1.03M
    reserve(C, N);
68
1.03M
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
2.07M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
2.07M
    reserve(C, N);
68
2.07M
  }
clang::BumpVector<clang::CFGBlock*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
234k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
234k
    reserve(C, N);
68
234k
  }
clang::BumpVector<clang::VarDecl*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
3.22k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
3.22k
    reserve(C, N);
68
3.22k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
40.6k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
40.6k
    reserve(C, N);
68
40.6k
  }
clang::BumpVector<clang::ento::MemRegion const*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
472
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
472
    reserve(C, N);
68
472
  }
69
70
234k
  ~BumpVector() {
71
234k
    if (std::is_class<T>::value) {
72
      // Destroy the constructed elements in the vector.
73
0
      destroy_range(Begin, End);
74
0
    }
75
234k
  }
76
77
  using size_type = size_t;
78
  using difference_type = ptrdiff_t;
79
  using value_type = T;
80
  using iterator = T *;
81
  using const_iterator = const T *;
82
83
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
84
  using reverse_iterator = std::reverse_iterator<iterator>;
85
86
  using reference = T &;
87
  using const_reference = const T &;
88
  using pointer = T *;
89
  using const_pointer = const T *;
90
91
  // forward iterator creation methods.
92
1.38M
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGElement>::begin()
Line
Count
Source
92
98.2k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin()
Line
Count
Source
92
182k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin()
Line
Count
Source
92
1.08M
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::begin()
Line
Count
Source
92
13.7k
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::MemRegion const*>::begin()
Line
Count
Source
92
4.57k
  iterator begin() { return Begin; }
93
2.10M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGElement>::begin() const
Line
Count
Source
93
423k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin() const
Line
Count
Source
93
1.67M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin() const
Line
Count
Source
93
5.17k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::VarDecl const*>::begin() const
Line
Count
Source
93
797
  const_iterator begin() const { return Begin; }
94
2.65M
  iterator end() { return End; }
clang::BumpVector<clang::CFGElement>::end()
Line
Count
Source
94
98.2k
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end()
Line
Count
Source
94
182k
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock*>::end()
Line
Count
Source
94
2.35M
  iterator end() { return End; }
clang::BumpVector<clang::ento::ExplodedNode*>::end()
Line
Count
Source
94
12.3k
  iterator end() { return End; }
clang::BumpVector<clang::ento::MemRegion const*>::end()
Line
Count
Source
94
4.57k
  iterator end() { return End; }
95
1.99M
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGElement>::end() const
Line
Count
Source
95
469k
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end() const
Line
Count
Source
95
1.52M
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock*>::end() const
Line
Count
Source
95
5.19k
  const_iterator end() const { return End; }
clang::BumpVector<clang::VarDecl const*>::end() const
Line
Count
Source
95
797
  const_iterator end() const { return End; }
96
97
  // reverse iterator creation methods.
98
98.2k
  reverse_iterator rbegin() { return reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin()
Line
Count
Source
98
98.2k
  reverse_iterator rbegin() { return reverse_iterator(end()); }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rbegin()
clang::BumpVector<clang::CFGBlock*>::rbegin()
Line
Count
Source
98
78
  reverse_iterator rbegin() { return reverse_iterator(end()); }
99
80.2k
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin() const
Line
Count
Source
99
79.6k
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock*>::rbegin() const
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rbegin() const
Line
Count
Source
99
569
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
100
98.3k
  reverse_iterator rend() { return reverse_iterator(begin()); }
clang::BumpVector<clang::CFGElement>::rend()
Line
Count
Source
100
98.2k
  reverse_iterator rend() { return reverse_iterator(begin()); }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rend()
clang::BumpVector<clang::CFGBlock*>::rend()
Line
Count
Source
100
78
  reverse_iterator rend() { return reverse_iterator(begin()); }
101
80.0k
  const_reverse_iterator rend() const {
102
80.0k
    return const_reverse_iterator(begin());
103
80.0k
  }
clang::BumpVector<clang::CFGElement>::rend() const
Line
Count
Source
101
79.6k
  const_reverse_iterator rend() const {
102
79.6k
    return const_reverse_iterator(begin());
103
79.6k
  }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock*>::rend() const
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rend() const
Line
Count
Source
101
410
  const_reverse_iterator rend() const {
102
410
    return const_reverse_iterator(begin());
103
410
  }
104
105
1.36M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGElement>::empty() const
Line
Count
Source
105
1.30M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::empty() const
Line
Count
Source
105
54.3k
  bool empty() const { return Begin == End; }
106
12.1M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGElement>::size() const
Line
Count
Source
106
9.14M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::size() const
Line
Count
Source
106
2.59M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock*>::size() const
Line
Count
Source
106
245k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl const*>::size() const
Line
Count
Source
106
403
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl*>::size() const
Line
Count
Source
106
8.07k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::size() const
Line
Count
Source
106
127k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::ento::MemRegion const*>::size() const
Line
Count
Source
106
472
  size_type size() const { return End-Begin; }
107
108
  reference operator[](unsigned idx) {
109
    assert(Begin + idx < End);
110
    return Begin[idx];
111
  }
112
3.27M
  const_reference operator[](unsigned idx) const {
113
3.27M
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
3.27M
  }
clang::BumpVector<clang::VarDecl*>::operator[](unsigned int) const
Line
Count
Source
112
20.5k
  const_reference operator[](unsigned idx) const {
113
20.5k
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
20.5k
  }
clang::BumpVector<clang::CFGElement>::operator[](unsigned int) const
Line
Count
Source
112
3.25M
  const_reference operator[](unsigned idx) const {
113
3.25M
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
3.25M
  }
116
117
0
  reference front() {
118
0
    return begin()[0];
119
0
  }
120
64.7k
  const_reference front() const {
121
64.7k
    return begin()[0];
122
64.7k
  }
123
124
1.27M
  reference back() {
125
1.27M
    return end()[-1];
126
1.27M
  }
127
112k
  const_reference back() const {
128
112k
    return end()[-1];
129
112k
  }
130
131
  void pop_back() {
132
    --End;
133
    End->~T();
134
  }
135
136
  T pop_back_val() {
137
    T Result = back();
138
    pop_back();
139
    return Result;
140
  }
141
142
  void clear() {
143
    if (std::is_class<T>::value) {
144
      destroy_range(Begin, End);
145
    }
146
    End = Begin;
147
  }
148
149
  /// data - Return a pointer to the vector's buffer, even if empty().
150
  pointer data() {
151
    return pointer(Begin);
152
  }
153
154
  /// data - Return a pointer to the vector's buffer, even if empty().
155
  const_pointer data() const {
156
    return const_pointer(Begin);
157
  }
158
159
7.47M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
7.47M
    if (End < Capacity) {
161
7.47M
    Retry:
162
7.47M
      new (End) T(Elt);
163
7.47M
      ++End;
164
7.47M
      return;
165
6.60M
    }
166
874k
    grow(C);
167
874k
    goto Retry;
168
7.47M
  }
clang::BumpVector<clang::CFGElement>::push_back(clang::CFGElement const&, clang::BumpVectorContext&)
Line
Count
Source
159
4.41M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.41M
    if (End < Capacity) {
161
4.41M
    Retry:
162
4.41M
      new (End) T(Elt);
163
4.41M
      ++End;
164
4.41M
      return;
165
3.86M
    }
166
554k
    grow(C);
167
554k
    goto Retry;
168
4.41M
  }
clang::BumpVector<clang::VarDecl const*>::push_back(clang::VarDecl const* const&, clang::BumpVectorContext&)
Line
Count
Source
159
327
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
327
    if (End < Capacity) {
161
327
    Retry:
162
327
      new (End) T(Elt);
163
327
      ++End;
164
327
      return;
165
327
    }
166
0
    grow(C);
167
0
    goto Retry;
168
327
  }
clang::BumpVector<clang::VarDecl*>::push_back(clang::VarDecl* const&, clang::BumpVectorContext&)
Line
Count
Source
159
4.82k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.82k
    if (End < Capacity) {
161
4.82k
    Retry:
162
4.82k
      new (End) T(Elt);
163
4.82k
      ++End;
164
4.82k
      return;
165
4.80k
    }
166
22
    grow(C);
167
22
    goto Retry;
168
4.82k
  }
clang::BumpVector<clang::CFGBlock*>::push_back(clang::CFGBlock* const&, clang::BumpVectorContext&)
Line
Count
Source
159
1.03M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
1.03M
    if (End < Capacity) {
161
1.03M
    Retry:
162
1.03M
      new (End) T(Elt);
163
1.03M
      ++End;
164
1.03M
      return;
165
1.02M
    }
166
11.7k
    grow(C);
167
11.7k
    goto Retry;
168
1.03M
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::push_back(clang::CFGBlock::AdjacentBlock const&, clang::BumpVectorContext&)
Line
Count
Source
159
1.93M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
1.93M
    if (End < Capacity) {
161
1.93M
    Retry:
162
1.93M
      new (End) T(Elt);
163
1.93M
      ++End;
164
1.93M
      return;
165
1.62M
    }
166
308k
    grow(C);
167
308k
    goto Retry;
168
1.93M
  }
clang::BumpVector<clang::ento::ExplodedNode*>::push_back(clang::ento::ExplodedNode* const&, clang::BumpVectorContext&)
Line
Count
Source
159
84.5k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
84.5k
    if (End < Capacity) {
161
84.5k
    Retry:
162
84.5k
      new (End) T(Elt);
163
84.5k
      ++End;
164
84.5k
      return;
165
84.3k
    }
166
260
    grow(C);
167
260
    goto Retry;
168
84.5k
  }
clang::BumpVector<clang::ento::MemRegion const*>::push_back(clang::ento::MemRegion const* const&, clang::BumpVectorContext&)
Line
Count
Source
159
594
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
594
    if (End < Capacity) {
161
594
    Retry:
162
594
      new (End) T(Elt);
163
594
      ++End;
164
594
      return;
165
594
    }
166
0
    grow(C);
167
0
    goto Retry;
168
594
  }
169
170
  /// insert - Insert some number of copies of element into a position. Return
171
  /// iterator to position after last inserted copy.
172
  iterator insert(iterator I, size_t Cnt, const_reference E,
173
70
      BumpVectorContext &C) {
174
70
    assert(I >= Begin && I <= End && "Iterator out of bounds.");
175
70
    if (End + Cnt <= Capacity) {
176
70
    Retry:
177
70
      move_range_right(I, End, Cnt);
178
70
      construct_range(I, I + Cnt, E);
179
70
      End += Cnt;
180
70
      return I + Cnt;
181
70
    }
182
0
    ptrdiff_t D = I - Begin;
183
0
    grow(C, size() + Cnt);
184
0
    I = Begin + D;
185
0
    goto Retry;
186
70
  }
187
188
3.39M
  void reserve(BumpVectorContext &C, unsigned N) {
189
3.39M
    if (unsigned(Capacity-Begin) < N)
190
3.39M
      grow(C, N);
191
3.39M
  }
clang::BumpVector<clang::CFGElement>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
1.03M
  void reserve(BumpVectorContext &C, unsigned N) {
189
1.03M
    if (unsigned(Capacity-Begin) < N)
190
1.03M
      grow(C, N);
191
1.03M
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
2.07M
  void reserve(BumpVectorContext &C, unsigned N) {
189
2.07M
    if (unsigned(Capacity-Begin) < N)
190
2.07M
      grow(C, N);
191
2.07M
  }
clang::BumpVector<clang::CFGBlock*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
234k
  void reserve(BumpVectorContext &C, unsigned N) {
189
234k
    if (unsigned(Capacity-Begin) < N)
190
234k
      grow(C, N);
191
234k
  }
clang::BumpVector<clang::VarDecl const*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
403
  void reserve(BumpVectorContext &C, unsigned N) {
189
403
    if (unsigned(Capacity-Begin) < N)
190
403
      grow(C, N);
191
403
  }
clang::BumpVector<clang::VarDecl*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
3.22k
  void reserve(BumpVectorContext &C, unsigned N) {
189
3.22k
    if (unsigned(Capacity-Begin) < N)
190
3.22k
      grow(C, N);
191
3.22k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
40.6k
  void reserve(BumpVectorContext &C, unsigned N) {
189
40.6k
    if (unsigned(Capacity-Begin) < N)
190
40.6k
      grow(C, N);
191
40.6k
  }
clang::BumpVector<clang::ento::MemRegion const*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
472
  void reserve(BumpVectorContext &C, unsigned N) {
189
472
    if (unsigned(Capacity-Begin) < N)
190
472
      grow(C, N);
191
472
  }
192
193
  /// capacity - Return the total number of elements in the currently allocated
194
  /// buffer.
195
  size_t capacity() const { return Capacity - Begin; }
196
197
private:
198
  /// grow - double the size of the allocated memory, guaranteeing space for at
199
  /// least one more element or MinSize if specified.
200
  void grow(BumpVectorContext &C, size_type MinSize = 1);
201
202
70
  void construct_range(T *S, T *E, const T &Elt) {
203
97
    for (; S != E; 
++S27
)
204
27
      new (S) T(Elt);
205
70
  }
206
207
862k
  void destroy_range(T *S, T *E) {
208
5.12M
    while (S != E) {
209
4.26M
      --E;
210
4.26M
      E->~T();
211
4.26M
    }
212
862k
  }
clang::BumpVector<clang::CFGElement>::destroy_range(clang::CFGElement*, clang::CFGElement*)
Line
Count
Source
207
554k
  void destroy_range(T *S, T *E) {
208
4.47M
    while (S != E) {
209
3.92M
      --E;
210
3.92M
      E->~T();
211
3.92M
    }
212
554k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::destroy_range(clang::CFGBlock::AdjacentBlock*, clang::CFGBlock::AdjacentBlock*)
Line
Count
Source
207
308k
  void destroy_range(T *S, T *E) {
208
652k
    while (S != E) {
209
344k
      --E;
210
344k
      E->~T();
211
344k
    }
212
308k
  }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock*>::destroy_range(clang::CFGBlock**, clang::CFGBlock**)
Unexecuted instantiation: clang::BumpVector<clang::VarDecl const*>::destroy_range(clang::VarDecl const**, clang::VarDecl const**)
Unexecuted instantiation: clang::BumpVector<clang::VarDecl*>::destroy_range(clang::VarDecl**, clang::VarDecl**)
Unexecuted instantiation: clang::BumpVector<clang::ento::ExplodedNode*>::destroy_range(clang::ento::ExplodedNode**, clang::ento::ExplodedNode**)
Unexecuted instantiation: clang::BumpVector<clang::ento::MemRegion const*>::destroy_range(clang::ento::MemRegion const**, clang::ento::MemRegion const**)
213
214
70
  void move_range_right(T *S, T *E, size_t D) {
215
169
    for (T *I = E + D - 1, *IL = S + D - 1; I != IL; 
--I99
) {
216
99
      --E;
217
99
      new (I) T(*E);
218
99
      E->~T();
219
99
    }
220
70
  }
221
};
222
223
// Define this out-of-line to dissuade the C++ compiler from inlining it.
224
template <typename T>
225
4.27M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
4.27M
  size_t CurCapacity = Capacity-Begin;
227
4.27M
  size_t CurSize = size();
228
4.27M
  size_t NewCapacity = 2*CurCapacity;
229
4.27M
  if (NewCapacity < MinSize)
230
3.39M
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
4.27M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
4.27M
  if (Begin != End) {
237
874k
    if (std::is_class<T>::value) {
238
862k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
862k
      destroy_range(Begin, End);
241
862k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
12.0k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
12.0k
    }
245
874k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
4.27M
  Begin = NewElts;
250
4.27M
  End = NewElts+CurSize;
251
4.27M
  Capacity = Begin+NewCapacity;
252
4.27M
}
clang::BumpVector<clang::CFGElement>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
1.59M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
1.59M
  size_t CurCapacity = Capacity-Begin;
227
1.59M
  size_t CurSize = size();
228
1.59M
  size_t NewCapacity = 2*CurCapacity;
229
1.59M
  if (NewCapacity < MinSize)
230
1.03M
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
1.59M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
1.59M
  if (Begin != End) {
237
554k
    if (std::is_class<T>::value) {
238
554k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
554k
      destroy_range(Begin, End);
241
554k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
554k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
1.59M
  Begin = NewElts;
250
1.59M
  End = NewElts+CurSize;
251
1.59M
  Capacity = Begin+NewCapacity;
252
1.59M
}
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
2.38M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
2.38M
  size_t CurCapacity = Capacity-Begin;
227
2.38M
  size_t CurSize = size();
228
2.38M
  size_t NewCapacity = 2*CurCapacity;
229
2.38M
  if (NewCapacity < MinSize)
230
2.07M
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
2.38M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
2.38M
  if (Begin != End) {
237
308k
    if (std::is_class<T>::value) {
238
308k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
308k
      destroy_range(Begin, End);
241
308k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
308k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
2.38M
  Begin = NewElts;
250
2.38M
  End = NewElts+CurSize;
251
2.38M
  Capacity = Begin+NewCapacity;
252
2.38M
}
clang::BumpVector<clang::CFGBlock*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
245k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
245k
  size_t CurCapacity = Capacity-Begin;
227
245k
  size_t CurSize = size();
228
245k
  size_t NewCapacity = 2*CurCapacity;
229
245k
  if (NewCapacity < MinSize)
230
234k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
245k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
245k
  if (Begin != End) {
237
11.7k
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
11.7k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
11.7k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
11.7k
    }
245
11.7k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
245k
  Begin = NewElts;
250
245k
  End = NewElts+CurSize;
251
245k
  Capacity = Begin+NewCapacity;
252
245k
}
clang::BumpVector<clang::VarDecl const*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
403
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
403
  size_t CurCapacity = Capacity-Begin;
227
403
  size_t CurSize = size();
228
403
  size_t NewCapacity = 2*CurCapacity;
229
403
  if (NewCapacity < MinSize)
230
403
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
403
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
403
  if (Begin != End) {
237
0
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
0
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
0
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
403
  Begin = NewElts;
250
403
  End = NewElts+CurSize;
251
403
  Capacity = Begin+NewCapacity;
252
403
}
clang::BumpVector<clang::VarDecl*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
3.24k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
3.24k
  size_t CurCapacity = Capacity-Begin;
227
3.24k
  size_t CurSize = size();
228
3.24k
  size_t NewCapacity = 2*CurCapacity;
229
3.24k
  if (NewCapacity < MinSize)
230
3.22k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
3.24k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
3.24k
  if (Begin != End) {
237
22
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
22
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
22
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
22
    }
245
22
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
3.24k
  Begin = NewElts;
250
3.24k
  End = NewElts+CurSize;
251
3.24k
  Capacity = Begin+NewCapacity;
252
3.24k
}
clang::BumpVector<clang::ento::ExplodedNode*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
40.8k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
40.8k
  size_t CurCapacity = Capacity-Begin;
227
40.8k
  size_t CurSize = size();
228
40.8k
  size_t NewCapacity = 2*CurCapacity;
229
40.8k
  if (NewCapacity < MinSize)
230
40.6k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
40.8k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
40.8k
  if (Begin != End) {
237
260
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
260
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
260
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
260
    }
245
260
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
40.8k
  Begin = NewElts;
250
40.8k
  End = NewElts+CurSize;
251
40.8k
  Capacity = Begin+NewCapacity;
252
40.8k
}
clang::BumpVector<clang::ento::MemRegion const*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
472
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
472
  size_t CurCapacity = Capacity-Begin;
227
472
  size_t CurSize = size();
228
472
  size_t NewCapacity = 2*CurCapacity;
229
472
  if (NewCapacity < MinSize)
230
472
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
472
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
472
  if (Begin != End) {
237
0
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
0
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
0
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
472
  Begin = NewElts;
250
472
  End = NewElts+CurSize;
251
472
  Capacity = Begin+NewCapacity;
252
472
}
253
254
} // namespace clang
255
256
#endif // LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H