Coverage Report

Created: 2020-02-15 09:57

/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
158k
  BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), 1) {}
39
40
3.08k
  BumpVectorContext(BumpVectorContext &&Other) : Alloc(Other.Alloc) {
41
3.08k
    Other.Alloc.setInt(false);
42
3.08k
    Other.Alloc.setPointer(nullptr);
43
3.08k
  }
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.70k
  BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, 0) {}
49
50
162k
  ~BumpVectorContext() {
51
162k
    if (Alloc.getInt())
52
158k
      delete Alloc.getPointer();
53
162k
  }
54
55
8.58M
  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
1.87M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
1.87M
    reserve(C, N);
68
1.87M
  }
clang::BumpVector<clang::VarDecl const*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
393
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
393
    reserve(C, N);
68
393
  }
clang::BumpVector<clang::CFGElement>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
568k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
568k
    reserve(C, N);
68
568k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
1.13M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
1.13M
    reserve(C, N);
68
1.13M
  }
clang::BumpVector<clang::CFGBlock*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
122k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
122k
    reserve(C, N);
68
122k
  }
clang::BumpVector<clang::VarDecl*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
3.08k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
3.08k
    reserve(C, N);
68
3.08k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
45.5k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
45.5k
    reserve(C, N);
68
45.5k
  }
clang::BumpVector<clang::ento::MemRegion const*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
466
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
466
    reserve(C, N);
68
466
  }
69
70
122k
  ~BumpVector() {
71
122k
    if (std::is_class<T>::value) {
72
0
      // Destroy the constructed elements in the vector.
73
0
      destroy_range(Begin, End);
74
0
    }
75
122k
  }
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
795k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin()
Line
Count
Source
92
604k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin()
Line
Count
Source
92
117k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGElement>::begin()
Line
Count
Source
92
57.1k
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::begin()
Line
Count
Source
92
11.2k
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::MemRegion const*>::begin()
Line
Count
Source
92
4.53k
  iterator begin() { return Begin; }
93
1.52M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin() const
Line
Count
Source
93
1.18M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGElement>::begin() const
Line
Count
Source
93
336k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin() const
Line
Count
Source
93
4.41k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::VarDecl const*>::begin() const
Line
Count
Source
93
778
  const_iterator begin() const { return Begin; }
94
1.48M
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock*>::end()
Line
Count
Source
94
1.29M
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end()
Line
Count
Source
94
117k
  iterator end() { return End; }
clang::BumpVector<clang::CFGElement>::end()
Line
Count
Source
94
57.0k
  iterator end() { return End; }
clang::BumpVector<clang::ento::ExplodedNode*>::end()
Line
Count
Source
94
9.90k
  iterator end() { return End; }
clang::BumpVector<clang::ento::MemRegion const*>::end()
Line
Count
Source
94
4.53k
  iterator end() { return End; }
95
1.34M
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end() const
Line
Count
Source
95
964k
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGElement>::end() const
Line
Count
Source
95
379k
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock*>::end() const
Line
Count
Source
95
4.43k
  const_iterator end() const { return End; }
clang::BumpVector<clang::VarDecl const*>::end() const
Line
Count
Source
95
778
  const_iterator end() const { return End; }
96
97
  // reverse iterator creation methods.
98
57.1k
  reverse_iterator rbegin() { return reverse_iterator(end()); }
clang::BumpVector<clang::CFGBlock*>::rbegin()
Line
Count
Source
98
76
  reverse_iterator rbegin() { return reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin()
Line
Count
Source
98
57.0k
  reverse_iterator rbegin() { return reverse_iterator(end()); }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rbegin()
99
74.5k
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin() const
Line
Count
Source
99
73.9k
  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
537
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
100
57.1k
  reverse_iterator rend() { return reverse_iterator(begin()); }
clang::BumpVector<clang::CFGBlock*>::rend()
Line
Count
Source
100
76
  reverse_iterator rend() { return reverse_iterator(begin()); }
clang::BumpVector<clang::CFGElement>::rend()
Line
Count
Source
100
57.1k
  reverse_iterator rend() { return reverse_iterator(begin()); }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rend()
101
74.3k
  const_reverse_iterator rend() const {
102
74.3k
    return const_reverse_iterator(begin());
103
74.3k
  }
clang::BumpVector<clang::CFGElement>::rend() const
Line
Count
Source
101
73.9k
  const_reverse_iterator rend() const {
102
73.9k
    return const_reverse_iterator(begin());
103
73.9k
  }
Unexecuted instantiation: clang::BumpVector<clang::CFGBlock*>::rend() const
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::rend() const
Line
Count
Source
101
388
  const_reverse_iterator rend() const {
102
388
    return const_reverse_iterator(begin());
103
388
  }
104
105
1.65M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGElement>::empty() const
Line
Count
Source
105
1.63M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::empty() const
Line
Count
Source
105
24.0k
  bool empty() const { return Begin == End; }
106
11.1M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::size() const
Line
Count
Source
106
1.58M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGElement>::size() const
Line
Count
Source
106
9.25M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock*>::size() const
Line
Count
Source
106
129k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl const*>::size() const
Line
Count
Source
106
393
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl*>::size() const
Line
Count
Source
106
7.80k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::size() const
Line
Count
Source
106
149k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::ento::MemRegion const*>::size() const
Line
Count
Source
106
466
  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.62M
  const_reference operator[](unsigned idx) const {
113
3.62M
    assert(Begin + idx < End);
114
3.62M
    return Begin[idx];
115
3.62M
  }
clang::BumpVector<clang::VarDecl*>::operator[](unsigned int) const
Line
Count
Source
112
20.2k
  const_reference operator[](unsigned idx) const {
113
20.2k
    assert(Begin + idx < End);
114
20.2k
    return Begin[idx];
115
20.2k
  }
clang::BumpVector<clang::CFGElement>::operator[](unsigned int) const
Line
Count
Source
112
3.60M
  const_reference operator[](unsigned idx) const {
113
3.60M
    assert(Begin + idx < End);
114
3.60M
    return Begin[idx];
115
3.60M
  }
116
117
0
  reference front() {
118
0
    return begin()[0];
119
0
  }
120
91.8k
  const_reference front() const {
121
91.8k
    return begin()[0];
122
91.8k
  }
123
124
690k
  reference back() {
125
690k
    return end()[-1];
126
690k
  }
127
136k
  const_reference back() const {
128
136k
    return end()[-1];
129
136k
  }
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
4.13M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.13M
    if (End < Capacity) {
161
4.13M
    Retry:
162
4.13M
      new (End) T(Elt);
163
4.13M
      ++End;
164
4.13M
      return;
165
462k
    }
166
462k
    grow(C);
167
462k
    goto Retry;
168
462k
  }
clang::BumpVector<clang::CFGElement>::push_back(clang::CFGElement const&, clang::BumpVectorContext&)
Line
Count
Source
159
2.38M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
2.38M
    if (End < Capacity) {
161
2.38M
    Retry:
162
2.38M
      new (End) T(Elt);
163
2.38M
      ++End;
164
2.38M
      return;
165
270k
    }
166
270k
    grow(C);
167
270k
    goto Retry;
168
270k
  }
clang::BumpVector<clang::VarDecl const*>::push_back(clang::VarDecl const* const&, clang::BumpVectorContext&)
Line
Count
Source
159
324
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
324
    if (End < Capacity) {
161
324
    Retry:
162
324
      new (End) T(Elt);
163
324
      ++End;
164
324
      return;
165
0
    }
166
0
    grow(C);
167
0
    goto Retry;
168
0
  }
clang::BumpVector<clang::VarDecl*>::push_back(clang::VarDecl* const&, clang::BumpVectorContext&)
Line
Count
Source
159
4.70k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.70k
    if (End < Capacity) {
161
4.70k
    Retry:
162
4.70k
      new (End) T(Elt);
163
4.70k
      ++End;
164
4.70k
      return;
165
21
    }
166
21
    grow(C);
167
21
    goto Retry;
168
21
  }
clang::BumpVector<clang::CFGBlock*>::push_back(clang::CFGBlock* const&, clang::BumpVectorContext&)
Line
Count
Source
159
568k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
568k
    if (End < Capacity) {
161
568k
    Retry:
162
568k
      new (End) T(Elt);
163
568k
      ++End;
164
568k
      return;
165
7.79k
    }
166
7.79k
    grow(C);
167
7.79k
    goto Retry;
168
7.79k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::push_back(clang::CFGBlock::AdjacentBlock const&, clang::BumpVectorContext&)
Line
Count
Source
159
1.08M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
1.08M
    if (End < Capacity) {
161
1.08M
    Retry:
162
1.08M
      new (End) T(Elt);
163
1.08M
      ++End;
164
1.08M
      return;
165
183k
    }
166
183k
    grow(C);
167
183k
    goto Retry;
168
183k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::push_back(clang::ento::ExplodedNode* const&, clang::BumpVectorContext&)
Line
Count
Source
159
94.9k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
94.9k
    if (End < Capacity) {
161
94.9k
    Retry:
162
94.9k
      new (End) T(Elt);
163
94.9k
      ++End;
164
94.9k
      return;
165
218
    }
166
218
    grow(C);
167
218
    goto Retry;
168
218
  }
clang::BumpVector<clang::ento::MemRegion const*>::push_back(clang::ento::MemRegion const* const&, clang::BumpVectorContext&)
Line
Count
Source
159
588
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
588
    if (End < Capacity) {
161
588
    Retry:
162
588
      new (End) T(Elt);
163
588
      ++End;
164
588
      return;
165
0
    }
166
0
    grow(C);
167
0
    goto Retry;
168
0
  }
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
68
      BumpVectorContext &C) {
174
68
    assert(I >= Begin && I <= End && "Iterator out of bounds.");
175
68
    if (End + Cnt <= Capacity) {
176
68
    Retry:
177
68
      move_range_right(I, End, Cnt);
178
68
      construct_range(I, I + Cnt, E);
179
68
      End += Cnt;
180
68
      return I + Cnt;
181
0
    }
182
0
    ptrdiff_t D = I - Begin;
183
0
    grow(C, size() + Cnt);
184
0
    I = Begin + D;
185
0
    goto Retry;
186
0
  }
187
188
1.87M
  void reserve(BumpVectorContext &C, unsigned N) {
189
1.87M
    if (unsigned(Capacity-Begin) < N)
190
1.87M
      grow(C, N);
191
1.87M
  }
clang::BumpVector<clang::CFGElement>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
568k
  void reserve(BumpVectorContext &C, unsigned N) {
189
568k
    if (unsigned(Capacity-Begin) < N)
190
568k
      grow(C, N);
191
568k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
1.13M
  void reserve(BumpVectorContext &C, unsigned N) {
189
1.13M
    if (unsigned(Capacity-Begin) < N)
190
1.13M
      grow(C, N);
191
1.13M
  }
clang::BumpVector<clang::CFGBlock*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
122k
  void reserve(BumpVectorContext &C, unsigned N) {
189
122k
    if (unsigned(Capacity-Begin) < N)
190
122k
      grow(C, N);
191
122k
  }
clang::BumpVector<clang::VarDecl const*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
393
  void reserve(BumpVectorContext &C, unsigned N) {
189
393
    if (unsigned(Capacity-Begin) < N)
190
393
      grow(C, N);
191
393
  }
clang::BumpVector<clang::VarDecl*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
3.08k
  void reserve(BumpVectorContext &C, unsigned N) {
189
3.08k
    if (unsigned(Capacity-Begin) < N)
190
3.08k
      grow(C, N);
191
3.08k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
45.5k
  void reserve(BumpVectorContext &C, unsigned N) {
189
45.5k
    if (unsigned(Capacity-Begin) < N)
190
45.5k
      grow(C, N);
191
45.5k
  }
clang::BumpVector<clang::ento::MemRegion const*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
466
  void reserve(BumpVectorContext &C, unsigned N) {
189
466
    if (unsigned(Capacity-Begin) < N)
190
466
      grow(C, N);
191
466
  }
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
68
  void construct_range(T *S, T *E, const T &Elt) {
203
95
    for (; S != E; 
++S27
)
204
27
      new (S) T(Elt);
205
68
  }
206
207
454k
  void destroy_range(T *S, T *E) {
208
2.73M
    while (S != E) {
209
2.28M
      --E;
210
2.28M
      E->~T();
211
2.28M
    }
212
454k
  }
clang::BumpVector<clang::CFGElement>::destroy_range(clang::CFGElement*, clang::CFGElement*)
Line
Count
Source
207
270k
  void destroy_range(T *S, T *E) {
208
2.34M
    while (S != E) {
209
2.07M
      --E;
210
2.07M
      E->~T();
211
2.07M
    }
212
270k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::destroy_range(clang::CFGBlock::AdjacentBlock*, clang::CFGBlock::AdjacentBlock*)
Line
Count
Source
207
183k
  void destroy_range(T *S, T *E) {
208
389k
    while (S != E) {
209
205k
      --E;
210
205k
      E->~T();
211
205k
    }
212
183k
  }
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
68
  void move_range_right(T *S, T *E, size_t D) {
215
165
    for (T *I = E + D - 1, *IL = S + D - 1; I != IL; 
--I97
) {
216
97
      --E;
217
97
      new (I) T(*E);
218
97
      E->~T();
219
97
    }
220
68
  }
221
};
222
223
// Define this out-of-line to dissuade the C++ compiler from inlining it.
224
template <typename T>
225
2.33M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
2.33M
  size_t CurCapacity = Capacity-Begin;
227
2.33M
  size_t CurSize = size();
228
2.33M
  size_t NewCapacity = 2*CurCapacity;
229
2.33M
  if (NewCapacity < MinSize)
230
1.87M
    NewCapacity = MinSize;
231
2.33M
232
2.33M
  // Allocate the memory from the BumpPtrAllocator.
233
2.33M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
2.33M
235
2.33M
  // Copy the elements over.
236
2.33M
  if (Begin != End) {
237
462k
    if (std::is_class<T>::value) {
238
454k
      std::uninitialized_copy(Begin, End, NewElts);
239
454k
      // Destroy the original elements.
240
454k
      destroy_range(Begin, End);
241
454k
    } else {
242
8.03k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
8.03k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
8.03k
    }
245
462k
  }
246
2.33M
247
2.33M
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
2.33M
  // BumpVectorContext.
249
2.33M
  Begin = NewElts;
250
2.33M
  End = NewElts+CurSize;
251
2.33M
  Capacity = Begin+NewCapacity;
252
2.33M
}
clang::BumpVector<clang::CFGElement>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
838k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
838k
  size_t CurCapacity = Capacity-Begin;
227
838k
  size_t CurSize = size();
228
838k
  size_t NewCapacity = 2*CurCapacity;
229
838k
  if (NewCapacity < MinSize)
230
568k
    NewCapacity = MinSize;
231
838k
232
838k
  // Allocate the memory from the BumpPtrAllocator.
233
838k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
838k
235
838k
  // Copy the elements over.
236
838k
  if (Begin != End) {
237
270k
    if (std::is_class<T>::value) {
238
270k
      std::uninitialized_copy(Begin, End, NewElts);
239
270k
      // Destroy the original elements.
240
270k
      destroy_range(Begin, End);
241
270k
    } else {
242
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
270k
  }
246
838k
247
838k
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
838k
  // BumpVectorContext.
249
838k
  Begin = NewElts;
250
838k
  End = NewElts+CurSize;
251
838k
  Capacity = Begin+NewCapacity;
252
838k
}
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
1.32M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
1.32M
  size_t CurCapacity = Capacity-Begin;
227
1.32M
  size_t CurSize = size();
228
1.32M
  size_t NewCapacity = 2*CurCapacity;
229
1.32M
  if (NewCapacity < MinSize)
230
1.13M
    NewCapacity = MinSize;
231
1.32M
232
1.32M
  // Allocate the memory from the BumpPtrAllocator.
233
1.32M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
1.32M
235
1.32M
  // Copy the elements over.
236
1.32M
  if (Begin != End) {
237
183k
    if (std::is_class<T>::value) {
238
183k
      std::uninitialized_copy(Begin, End, NewElts);
239
183k
      // Destroy the original elements.
240
183k
      destroy_range(Begin, End);
241
183k
    } else {
242
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
183k
  }
246
1.32M
247
1.32M
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
1.32M
  // BumpVectorContext.
249
1.32M
  Begin = NewElts;
250
1.32M
  End = NewElts+CurSize;
251
1.32M
  Capacity = Begin+NewCapacity;
252
1.32M
}
clang::BumpVector<clang::CFGBlock*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
129k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
129k
  size_t CurCapacity = Capacity-Begin;
227
129k
  size_t CurSize = size();
228
129k
  size_t NewCapacity = 2*CurCapacity;
229
129k
  if (NewCapacity < MinSize)
230
122k
    NewCapacity = MinSize;
231
129k
232
129k
  // Allocate the memory from the BumpPtrAllocator.
233
129k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
129k
235
129k
  // Copy the elements over.
236
129k
  if (Begin != End) {
237
7.79k
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
0
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
7.79k
    } else {
242
7.79k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
7.79k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
7.79k
    }
245
7.79k
  }
246
129k
247
129k
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
129k
  // BumpVectorContext.
249
129k
  Begin = NewElts;
250
129k
  End = NewElts+CurSize;
251
129k
  Capacity = Begin+NewCapacity;
252
129k
}
clang::BumpVector<clang::VarDecl const*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
393
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
393
  size_t CurCapacity = Capacity-Begin;
227
393
  size_t CurSize = size();
228
393
  size_t NewCapacity = 2*CurCapacity;
229
393
  if (NewCapacity < MinSize)
230
393
    NewCapacity = MinSize;
231
393
232
393
  // Allocate the memory from the BumpPtrAllocator.
233
393
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
393
235
393
  // Copy the elements over.
236
393
  if (Begin != End) {
237
0
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
0
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
0
    } else {
242
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
0
  }
246
393
247
393
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
393
  // BumpVectorContext.
249
393
  Begin = NewElts;
250
393
  End = NewElts+CurSize;
251
393
  Capacity = Begin+NewCapacity;
252
393
}
clang::BumpVector<clang::VarDecl*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
3.10k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
3.10k
  size_t CurCapacity = Capacity-Begin;
227
3.10k
  size_t CurSize = size();
228
3.10k
  size_t NewCapacity = 2*CurCapacity;
229
3.10k
  if (NewCapacity < MinSize)
230
3.08k
    NewCapacity = MinSize;
231
3.10k
232
3.10k
  // Allocate the memory from the BumpPtrAllocator.
233
3.10k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
3.10k
235
3.10k
  // Copy the elements over.
236
3.10k
  if (Begin != End) {
237
21
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
0
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
21
    } else {
242
21
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
21
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
21
    }
245
21
  }
246
3.10k
247
3.10k
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
3.10k
  // BumpVectorContext.
249
3.10k
  Begin = NewElts;
250
3.10k
  End = NewElts+CurSize;
251
3.10k
  Capacity = Begin+NewCapacity;
252
3.10k
}
clang::BumpVector<clang::ento::ExplodedNode*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
45.7k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
45.7k
  size_t CurCapacity = Capacity-Begin;
227
45.7k
  size_t CurSize = size();
228
45.7k
  size_t NewCapacity = 2*CurCapacity;
229
45.7k
  if (NewCapacity < MinSize)
230
45.5k
    NewCapacity = MinSize;
231
45.7k
232
45.7k
  // Allocate the memory from the BumpPtrAllocator.
233
45.7k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
45.7k
235
45.7k
  // Copy the elements over.
236
45.7k
  if (Begin != End) {
237
218
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
0
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
218
    } else {
242
218
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
218
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
218
    }
245
218
  }
246
45.7k
247
45.7k
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
45.7k
  // BumpVectorContext.
249
45.7k
  Begin = NewElts;
250
45.7k
  End = NewElts+CurSize;
251
45.7k
  Capacity = Begin+NewCapacity;
252
45.7k
}
clang::BumpVector<clang::ento::MemRegion const*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
466
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
466
  size_t CurCapacity = Capacity-Begin;
227
466
  size_t CurSize = size();
228
466
  size_t NewCapacity = 2*CurCapacity;
229
466
  if (NewCapacity < MinSize)
230
466
    NewCapacity = MinSize;
231
466
232
466
  // Allocate the memory from the BumpPtrAllocator.
233
466
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
466
235
466
  // Copy the elements over.
236
466
  if (Begin != End) {
237
0
    if (std::is_class<T>::value) {
238
0
      std::uninitialized_copy(Begin, End, NewElts);
239
0
      // Destroy the original elements.
240
0
      destroy_range(Begin, End);
241
0
    } else {
242
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
0
  }
246
466
247
466
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
466
  // BumpVectorContext.
249
466
  Begin = NewElts;
250
466
  End = NewElts+CurSize;
251
466
  Capacity = Begin+NewCapacity;
252
466
}
253
254
} // namespace clang
255
256
#endif // LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H