Coverage Report

Created: 2022-01-18 06:27

/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
261k
  BumpVectorContext() : Alloc(new llvm::BumpPtrAllocator(), 1) {}
39
40
3.29k
  BumpVectorContext(BumpVectorContext &&Other) : Alloc(Other.Alloc) {
41
3.29k
    Other.Alloc.setInt(false);
42
3.29k
    Other.Alloc.setPointer(nullptr);
43
3.29k
  }
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.93k
  BumpVectorContext(llvm::BumpPtrAllocator &A) : Alloc(&A, 0) {}
49
50
265k
  ~BumpVectorContext() {
51
265k
    if (Alloc.getInt())
52
261k
      delete Alloc.getPointer();
53
265k
  }
54
55
11.3M
  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.21M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
3.21M
    reserve(C, N);
68
3.21M
  }
clang::BumpVector<clang::VarDecl const*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
404
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
404
    reserve(C, N);
68
404
  }
clang::BumpVector<clang::CFGElement>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
985k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
985k
    reserve(C, N);
68
985k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
1.97M
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
1.97M
    reserve(C, N);
68
1.97M
  }
clang::BumpVector<clang::CFGBlock*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
216k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
216k
    reserve(C, N);
68
216k
  }
clang::BumpVector<clang::VarDecl*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
3.29k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
3.29k
    reserve(C, N);
68
3.29k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::BumpVector(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
66
41.0k
  explicit BumpVector(BumpVectorContext &C, unsigned N) {
67
41.0k
    reserve(C, N);
68
41.0k
  }
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
216k
  ~BumpVector() {
71
216k
    if (std::is_class<T>::value) {
72
      // Destroy the constructed elements in the vector.
73
0
      destroy_range(Begin, End);
74
0
    }
75
216k
  }
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.33M
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGElement>::begin()
Line
Count
Source
92
98.4k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin()
Line
Count
Source
92
184k
  iterator begin() { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin()
Line
Count
Source
92
1.02M
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::begin()
Line
Count
Source
92
13.9k
  iterator begin() { return Begin; }
clang::BumpVector<clang::ento::MemRegion const*>::begin()
Line
Count
Source
92
4.57k
  iterator begin() { return Begin; }
93
2.19M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGElement>::begin() const
Line
Count
Source
93
462k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::begin() const
Line
Count
Source
93
1.72M
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::CFGBlock*>::begin() const
Line
Count
Source
93
5.36k
  const_iterator begin() const { return Begin; }
clang::BumpVector<clang::VarDecl const*>::begin() const
Line
Count
Source
93
799
  const_iterator begin() const { return Begin; }
94
2.53M
  iterator end() { return End; }
clang::BumpVector<clang::CFGElement>::end()
Line
Count
Source
94
98.3k
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end()
Line
Count
Source
94
184k
  iterator end() { return End; }
clang::BumpVector<clang::CFGBlock*>::end()
Line
Count
Source
94
2.23M
  iterator end() { return End; }
clang::BumpVector<clang::ento::ExplodedNode*>::end()
Line
Count
Source
94
12.5k
  iterator end() { return End; }
clang::BumpVector<clang::ento::MemRegion const*>::end()
Line
Count
Source
94
4.57k
  iterator end() { return End; }
95
2.08M
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGElement>::end() const
Line
Count
Source
95
508k
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::end() const
Line
Count
Source
95
1.56M
  const_iterator end() const { return End; }
clang::BumpVector<clang::CFGBlock*>::end() const
Line
Count
Source
95
5.38k
  const_iterator end() const { return End; }
clang::BumpVector<clang::VarDecl const*>::end() const
Line
Count
Source
95
799
  const_iterator end() const { return End; }
96
97
  // reverse iterator creation methods.
98
98.4k
  reverse_iterator rbegin() { return reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin()
Line
Count
Source
98
98.3k
  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
144k
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
clang::BumpVector<clang::CFGElement>::rbegin() const
Line
Count
Source
99
143k
  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.5k
  reverse_iterator rend() { return reverse_iterator(begin()); }
clang::BumpVector<clang::CFGElement>::rend()
Line
Count
Source
100
98.4k
  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
143k
  const_reverse_iterator rend() const {
102
143k
    return const_reverse_iterator(begin());
103
143k
  }
clang::BumpVector<clang::CFGElement>::rend() const
Line
Count
Source
101
143k
  const_reverse_iterator rend() const {
102
143k
    return const_reverse_iterator(begin());
103
143k
  }
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.38M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGElement>::empty() const
Line
Count
Source
105
1.33M
  bool empty() const { return Begin == End; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::empty() const
Line
Count
Source
105
54.8k
  bool empty() const { return Begin == End; }
106
12.0M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGElement>::size() const
Line
Count
Source
106
9.23M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::size() const
Line
Count
Source
106
2.49M
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::CFGBlock*>::size() const
Line
Count
Source
106
228k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl const*>::size() const
Line
Count
Source
106
404
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::VarDecl*>::size() const
Line
Count
Source
106
8.24k
  size_type size() const { return End-Begin; }
clang::BumpVector<clang::ento::ExplodedNode*>::size() const
Line
Count
Source
106
128k
  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.37M
  const_reference operator[](unsigned idx) const {
113
3.37M
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
3.37M
  }
clang::BumpVector<clang::VarDecl*>::operator[](unsigned int) const
Line
Count
Source
112
20.9k
  const_reference operator[](unsigned idx) const {
113
20.9k
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
20.9k
  }
clang::BumpVector<clang::CFGElement>::operator[](unsigned int) const
Line
Count
Source
112
3.35M
  const_reference operator[](unsigned idx) const {
113
3.35M
    assert(Begin + idx < End);
114
0
    return Begin[idx];
115
3.35M
  }
116
117
0
  reference front() {
118
0
    return begin()[0];
119
0
  }
120
65.8k
  const_reference front() const {
121
65.8k
    return begin()[0];
122
65.8k
  }
123
124
1.20M
  reference back() {
125
1.20M
    return end()[-1];
126
1.20M
  }
127
114k
  const_reference back() const {
128
114k
    return end()[-1];
129
114k
  }
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
6.97M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
6.97M
    if (End < Capacity) {
161
6.97M
    Retry:
162
6.97M
      new (End) T(Elt);
163
6.97M
      ++End;
164
6.97M
      return;
165
6.15M
    }
166
816k
    grow(C);
167
816k
    goto Retry;
168
6.97M
  }
clang::BumpVector<clang::CFGElement>::push_back(clang::CFGElement const&, clang::BumpVectorContext&)
Line
Count
Source
159
4.04M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.04M
    if (End < Capacity) {
161
4.04M
    Retry:
162
4.04M
      new (End) T(Elt);
163
4.04M
      ++End;
164
4.04M
      return;
165
3.54M
    }
166
497k
    grow(C);
167
497k
    goto Retry;
168
4.04M
  }
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.92k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
4.92k
    if (End < Capacity) {
161
4.92k
    Retry:
162
4.92k
      new (End) T(Elt);
163
4.92k
      ++End;
164
4.92k
      return;
165
4.89k
    }
166
29
    grow(C);
167
29
    goto Retry;
168
4.92k
  }
clang::BumpVector<clang::CFGBlock*>::push_back(clang::CFGBlock* const&, clang::BumpVectorContext&)
Line
Count
Source
159
985k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
985k
    if (End < Capacity) {
161
985k
    Retry:
162
985k
      new (End) T(Elt);
163
985k
      ++End;
164
985k
      return;
165
973k
    }
166
11.7k
    grow(C);
167
11.7k
    goto Retry;
168
985k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::push_back(clang::CFGBlock::AdjacentBlock const&, clang::BumpVectorContext&)
Line
Count
Source
159
1.85M
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
1.85M
    if (End < Capacity) {
161
1.85M
    Retry:
162
1.85M
      new (End) T(Elt);
163
1.85M
      ++End;
164
1.85M
      return;
165
1.55M
    }
166
307k
    grow(C);
167
307k
    goto Retry;
168
1.85M
  }
clang::BumpVector<clang::ento::ExplodedNode*>::push_back(clang::ento::ExplodedNode* const&, clang::BumpVectorContext&)
Line
Count
Source
159
85.6k
  void push_back(const_reference Elt, BumpVectorContext &C) {
160
85.6k
    if (End < Capacity) {
161
85.6k
    Retry:
162
85.6k
      new (End) T(Elt);
163
85.6k
      ++End;
164
85.6k
      return;
165
85.3k
    }
166
264
    grow(C);
167
264
    goto Retry;
168
85.6k
  }
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
71
      BumpVectorContext &C) {
174
71
    assert(I >= Begin && I <= End && "Iterator out of bounds.");
175
71
    if (End + Cnt <= Capacity) {
176
71
    Retry:
177
71
      move_range_right(I, End, Cnt);
178
71
      construct_range(I, I + Cnt, E);
179
71
      End += Cnt;
180
71
      return I + Cnt;
181
71
    }
182
0
    ptrdiff_t D = I - Begin;
183
0
    grow(C, size() + Cnt);
184
0
    I = Begin + D;
185
0
    goto Retry;
186
71
  }
187
188
3.21M
  void reserve(BumpVectorContext &C, unsigned N) {
189
3.21M
    if (unsigned(Capacity-Begin) < N)
190
3.21M
      grow(C, N);
191
3.21M
  }
clang::BumpVector<clang::CFGElement>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
985k
  void reserve(BumpVectorContext &C, unsigned N) {
189
985k
    if (unsigned(Capacity-Begin) < N)
190
985k
      grow(C, N);
191
985k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
1.97M
  void reserve(BumpVectorContext &C, unsigned N) {
189
1.97M
    if (unsigned(Capacity-Begin) < N)
190
1.97M
      grow(C, N);
191
1.97M
  }
clang::BumpVector<clang::CFGBlock*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
216k
  void reserve(BumpVectorContext &C, unsigned N) {
189
216k
    if (unsigned(Capacity-Begin) < N)
190
216k
      grow(C, N);
191
216k
  }
clang::BumpVector<clang::VarDecl const*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
404
  void reserve(BumpVectorContext &C, unsigned N) {
189
404
    if (unsigned(Capacity-Begin) < N)
190
404
      grow(C, N);
191
404
  }
clang::BumpVector<clang::VarDecl*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
3.29k
  void reserve(BumpVectorContext &C, unsigned N) {
189
3.29k
    if (unsigned(Capacity-Begin) < N)
190
3.29k
      grow(C, N);
191
3.29k
  }
clang::BumpVector<clang::ento::ExplodedNode*>::reserve(clang::BumpVectorContext&, unsigned int)
Line
Count
Source
188
41.0k
  void reserve(BumpVectorContext &C, unsigned N) {
189
41.0k
    if (unsigned(Capacity-Begin) < N)
190
41.0k
      grow(C, N);
191
41.0k
  }
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
71
  void construct_range(T *S, T *E, const T &Elt) {
203
98
    for (; S != E; 
++S27
)
204
27
      new (S) T(Elt);
205
71
  }
206
207
804k
  void destroy_range(T *S, T *E) {
208
4.63M
    while (S != E) {
209
3.83M
      --E;
210
3.83M
      E->~T();
211
3.83M
    }
212
804k
  }
clang::BumpVector<clang::CFGElement>::destroy_range(clang::CFGElement*, clang::CFGElement*)
Line
Count
Source
207
497k
  void destroy_range(T *S, T *E) {
208
3.98M
    while (S != E) {
209
3.48M
      --E;
210
3.48M
      E->~T();
211
3.48M
    }
212
497k
  }
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::destroy_range(clang::CFGBlock::AdjacentBlock*, clang::CFGBlock::AdjacentBlock*)
Line
Count
Source
207
307k
  void destroy_range(T *S, T *E) {
208
650k
    while (S != E) {
209
343k
      --E;
210
343k
      E->~T();
211
343k
    }
212
307k
  }
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
71
  void move_range_right(T *S, T *E, size_t D) {
215
170
    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
71
  }
221
};
222
223
// Define this out-of-line to dissuade the C++ compiler from inlining it.
224
template <typename T>
225
4.03M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
4.03M
  size_t CurCapacity = Capacity-Begin;
227
4.03M
  size_t CurSize = size();
228
4.03M
  size_t NewCapacity = 2*CurCapacity;
229
4.03M
  if (NewCapacity < MinSize)
230
3.21M
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
4.03M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
4.03M
  if (Begin != End) {
237
816k
    if (std::is_class<T>::value) {
238
804k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
804k
      destroy_range(Begin, End);
241
804k
    } 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
816k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
4.03M
  Begin = NewElts;
250
4.03M
  End = NewElts+CurSize;
251
4.03M
  Capacity = Begin+NewCapacity;
252
4.03M
}
clang::BumpVector<clang::CFGElement>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
1.48M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
1.48M
  size_t CurCapacity = Capacity-Begin;
227
1.48M
  size_t CurSize = size();
228
1.48M
  size_t NewCapacity = 2*CurCapacity;
229
1.48M
  if (NewCapacity < MinSize)
230
985k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
1.48M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
1.48M
  if (Begin != End) {
237
497k
    if (std::is_class<T>::value) {
238
497k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
497k
      destroy_range(Begin, End);
241
497k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
497k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
1.48M
  Begin = NewElts;
250
1.48M
  End = NewElts+CurSize;
251
1.48M
  Capacity = Begin+NewCapacity;
252
1.48M
}
clang::BumpVector<clang::CFGBlock::AdjacentBlock>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
2.27M
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
2.27M
  size_t CurCapacity = Capacity-Begin;
227
2.27M
  size_t CurSize = size();
228
2.27M
  size_t NewCapacity = 2*CurCapacity;
229
2.27M
  if (NewCapacity < MinSize)
230
1.97M
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
2.27M
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
2.27M
  if (Begin != End) {
237
307k
    if (std::is_class<T>::value) {
238
307k
      std::uninitialized_copy(Begin, End, NewElts);
239
      // Destroy the original elements.
240
307k
      destroy_range(Begin, End);
241
307k
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
0
    }
245
307k
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
2.27M
  Begin = NewElts;
250
2.27M
  End = NewElts+CurSize;
251
2.27M
  Capacity = Begin+NewCapacity;
252
2.27M
}
clang::BumpVector<clang::CFGBlock*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
228k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
228k
  size_t CurCapacity = Capacity-Begin;
227
228k
  size_t CurSize = size();
228
228k
  size_t NewCapacity = 2*CurCapacity;
229
228k
  if (NewCapacity < MinSize)
230
216k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
228k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
228k
  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
228k
  Begin = NewElts;
250
228k
  End = NewElts+CurSize;
251
228k
  Capacity = Begin+NewCapacity;
252
228k
}
clang::BumpVector<clang::VarDecl const*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
404
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
404
  size_t CurCapacity = Capacity-Begin;
227
404
  size_t CurSize = size();
228
404
  size_t NewCapacity = 2*CurCapacity;
229
404
  if (NewCapacity < MinSize)
230
404
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
404
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
404
  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
404
  Begin = NewElts;
250
404
  End = NewElts+CurSize;
251
404
  Capacity = Begin+NewCapacity;
252
404
}
clang::BumpVector<clang::VarDecl*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
3.32k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
3.32k
  size_t CurCapacity = Capacity-Begin;
227
3.32k
  size_t CurSize = size();
228
3.32k
  size_t NewCapacity = 2*CurCapacity;
229
3.32k
  if (NewCapacity < MinSize)
230
3.29k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
3.32k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
3.32k
  if (Begin != End) {
237
29
    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
29
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
29
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
29
    }
245
29
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
3.32k
  Begin = NewElts;
250
3.32k
  End = NewElts+CurSize;
251
3.32k
  Capacity = Begin+NewCapacity;
252
3.32k
}
clang::BumpVector<clang::ento::ExplodedNode*>::grow(clang::BumpVectorContext&, unsigned long)
Line
Count
Source
225
41.3k
void BumpVector<T>::grow(BumpVectorContext &C, size_t MinSize) {
226
41.3k
  size_t CurCapacity = Capacity-Begin;
227
41.3k
  size_t CurSize = size();
228
41.3k
  size_t NewCapacity = 2*CurCapacity;
229
41.3k
  if (NewCapacity < MinSize)
230
41.0k
    NewCapacity = MinSize;
231
232
  // Allocate the memory from the BumpPtrAllocator.
233
41.3k
  T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
234
235
  // Copy the elements over.
236
41.3k
  if (Begin != End) {
237
264
    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
264
    } else {
242
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
243
264
      memcpy(NewElts, Begin, CurSize * sizeof(T));
244
264
    }
245
264
  }
246
247
  // For now, leak 'Begin'.  We can add it back to a freelist in
248
  // BumpVectorContext.
249
41.3k
  Begin = NewElts;
250
41.3k
  End = NewElts+CurSize;
251
41.3k
  Capacity = Begin+NewCapacity;
252
41.3k
}
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