Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SymbolManager.h - Management of Symbolic Values --------------------===//
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 SymbolManager, a class that manages symbolic values
10
//  created for use by ExprEngine and related classes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
15
#include "clang/AST/ASTContext.h"
16
#include "clang/AST/Expr.h"
17
#include "clang/Analysis/Analyses/LiveVariables.h"
18
#include "clang/Analysis/AnalysisDeclContext.h"
19
#include "clang/Basic/LLVM.h"
20
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
21
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
22
#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
23
#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
24
#include "llvm/ADT/FoldingSet.h"
25
#include "llvm/ADT/STLExtras.h"
26
#include "llvm/Support/Casting.h"
27
#include "llvm/Support/Compiler.h"
28
#include "llvm/Support/ErrorHandling.h"
29
#include "llvm/Support/raw_ostream.h"
30
#include <cassert>
31
32
using namespace clang;
33
using namespace ento;
34
35
0
void SymExpr::anchor() {}
36
37
0
LLVM_DUMP_METHOD void SymExpr::dump() const {
38
0
  dumpToStream(llvm::errs());
39
0
}
40
41
1
void SymIntExpr::dumpToStream(raw_ostream &os) const {
42
1
  os << '(';
43
1
  getLHS()->dumpToStream(os);
44
1
  os << ") "
45
1
     << BinaryOperator::getOpcodeStr(getOpcode()) << ' ';
46
1
  if (getRHS().isUnsigned())
47
0
    os << getRHS().getZExtValue();
48
1
  else
49
1
    os << getRHS().getSExtValue();
50
1
  if (getRHS().isUnsigned())
51
0
    os << 'U';
52
1
}
53
54
0
void IntSymExpr::dumpToStream(raw_ostream &os) const {
55
0
  if (getLHS().isUnsigned())
56
0
    os << getLHS().getZExtValue();
57
0
  else
58
0
    os << getLHS().getSExtValue();
59
0
  if (getLHS().isUnsigned())
60
0
    os << 'U';
61
0
  os << ' '
62
0
     << BinaryOperator::getOpcodeStr(getOpcode())
63
0
     << " (";
64
0
  getRHS()->dumpToStream(os);
65
0
  os << ')';
66
0
}
67
68
0
void SymSymExpr::dumpToStream(raw_ostream &os) const {
69
0
  os << '(';
70
0
  getLHS()->dumpToStream(os);
71
0
  os << ") "
72
0
     << BinaryOperator::getOpcodeStr(getOpcode())
73
0
     << " (";
74
0
  getRHS()->dumpToStream(os);
75
0
  os << ')';
76
0
}
77
78
0
void SymbolCast::dumpToStream(raw_ostream &os) const {
79
0
  os << '(' << ToTy.getAsString() << ") (";
80
0
  Operand->dumpToStream(os);
81
0
  os << ')';
82
0
}
83
84
154
void SymbolConjured::dumpToStream(raw_ostream &os) const {
85
154
  os << "conj_$" << getSymbolID() << '{' << T.getAsString() << ", LC"
86
154
     << LCtx->getID();
87
154
  if (S)
88
146
    os << ", S" << S->getID(LCtx->getDecl()->getASTContext());
89
8
  else
90
8
    os << ", no stmt";
91
154
  os << ", #" << Count << '}';
92
154
}
93
94
0
void SymbolDerived::dumpToStream(raw_ostream &os) const {
95
0
  os << "derived_$" << getSymbolID() << '{'
96
0
     << getParentSymbol() << ',' << getRegion() << '}';
97
0
}
98
99
0
void SymbolExtent::dumpToStream(raw_ostream &os) const {
100
0
  os << "extent_$" << getSymbolID() << '{' << getRegion() << '}';
101
0
}
102
103
0
void SymbolMetadata::dumpToStream(raw_ostream &os) const {
104
0
  os << "meta_$" << getSymbolID() << '{'
105
0
     << getRegion() << ',' << T.getAsString() << '}';
106
0
}
107
108
0
void SymbolData::anchor() {}
109
110
49
void SymbolRegionValue::dumpToStream(raw_ostream &os) const {
111
49
  os << "reg_$" << getSymbolID()
112
49
     << '<' << getType().getAsString() << ' ' << R << '>';
113
49
}
114
115
0
bool SymExpr::symbol_iterator::operator==(const symbol_iterator &X) const {
116
0
  return itr == X.itr;
117
0
}
118
119
5.58M
bool SymExpr::symbol_iterator::operator!=(const symbol_iterator &X) const {
120
5.58M
  return itr != X.itr;
121
5.58M
}
122
123
1.69M
SymExpr::symbol_iterator::symbol_iterator(const SymExpr *SE) {
124
1.69M
  itr.push_back(SE);
125
1.69M
}
126
127
2.66M
SymExpr::symbol_iterator &SymExpr::symbol_iterator::operator++() {
128
2.66M
  assert(!itr.empty() && "attempting to iterate on an 'end' iterator");
129
2.66M
  expand();
130
2.66M
  return *this;
131
2.66M
}
132
133
3.24M
SymbolRef SymExpr::symbol_iterator::operator*() {
134
3.24M
  assert(!itr.empty() && "attempting to dereference an 'end' iterator");
135
3.24M
  return itr.back();
136
3.24M
}
137
138
2.66M
void SymExpr::symbol_iterator::expand() {
139
2.66M
  const SymExpr *SE = itr.pop_back_val();
140
2.66M
141
2.66M
  switch (SE->getKind()) {
142
2.08M
    case SymExpr::SymbolRegionValueKind:
143
2.08M
    case SymExpr::SymbolConjuredKind:
144
2.08M
    case SymExpr::SymbolDerivedKind:
145
2.08M
    case SymExpr::SymbolExtentKind:
146
2.08M
    case SymExpr::SymbolMetadataKind:
147
2.08M
      return;
148
2.08M
    case SymExpr::SymbolCastKind:
149
84
      itr.push_back(cast<SymbolCast>(SE)->getOperand());
150
84
      return;
151
2.08M
    case SymExpr::SymIntExprKind:
152
168k
      itr.push_back(cast<SymIntExpr>(SE)->getLHS());
153
168k
      return;
154
2.08M
    case SymExpr::IntSymExprKind:
155
3.58k
      itr.push_back(cast<IntSymExpr>(SE)->getRHS());
156
3.58k
      return;
157
2.08M
    case SymExpr::SymSymExprKind: {
158
400k
      const auto *x = cast<SymSymExpr>(SE);
159
400k
      itr.push_back(x->getLHS());
160
400k
      itr.push_back(x->getRHS());
161
400k
      return;
162
0
    }
163
0
  }
164
0
  llvm_unreachable("unhandled expansion case");
165
0
}
166
167
const SymbolRegionValue*
168
101k
SymbolManager::getRegionValueSymbol(const TypedValueRegion* R) {
169
101k
  llvm::FoldingSetNodeID profile;
170
101k
  SymbolRegionValue::Profile(profile, R);
171
101k
  void *InsertPos;
172
101k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
173
101k
  if (!SD) {
174
11.3k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolRegionValue>();
175
11.3k
    new (SD) SymbolRegionValue(SymbolCounter, R);
176
11.3k
    DataSet.InsertNode(SD, InsertPos);
177
11.3k
    ++SymbolCounter;
178
11.3k
  }
179
101k
180
101k
  return cast<SymbolRegionValue>(SD);
181
101k
}
182
183
const SymbolConjured* SymbolManager::conjureSymbol(const Stmt *E,
184
                                                   const LocationContext *LCtx,
185
                                                   QualType T,
186
                                                   unsigned Count,
187
123k
                                                   const void *SymbolTag) {
188
123k
  llvm::FoldingSetNodeID profile;
189
123k
  SymbolConjured::Profile(profile, E, T, Count, LCtx, SymbolTag);
190
123k
  void *InsertPos;
191
123k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
192
123k
  if (!SD) {
193
56.9k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolConjured>();
194
56.9k
    new (SD) SymbolConjured(SymbolCounter, E, LCtx, T, Count, SymbolTag);
195
56.9k
    DataSet.InsertNode(SD, InsertPos);
196
56.9k
    ++SymbolCounter;
197
56.9k
  }
198
123k
199
123k
  return cast<SymbolConjured>(SD);
200
123k
}
201
202
const SymbolDerived*
203
SymbolManager::getDerivedSymbol(SymbolRef parentSymbol,
204
18.0k
                                const TypedValueRegion *R) {
205
18.0k
  llvm::FoldingSetNodeID profile;
206
18.0k
  SymbolDerived::Profile(profile, parentSymbol, R);
207
18.0k
  void *InsertPos;
208
18.0k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
209
18.0k
  if (!SD) {
210
2.23k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolDerived>();
211
2.23k
    new (SD) SymbolDerived(SymbolCounter, parentSymbol, R);
212
2.23k
    DataSet.InsertNode(SD, InsertPos);
213
2.23k
    ++SymbolCounter;
214
2.23k
  }
215
18.0k
216
18.0k
  return cast<SymbolDerived>(SD);
217
18.0k
}
218
219
const SymbolExtent*
220
2.12k
SymbolManager::getExtentSymbol(const SubRegion *R) {
221
2.12k
  llvm::FoldingSetNodeID profile;
222
2.12k
  SymbolExtent::Profile(profile, R);
223
2.12k
  void *InsertPos;
224
2.12k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
225
2.12k
  if (!SD) {
226
1.60k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolExtent>();
227
1.60k
    new (SD) SymbolExtent(SymbolCounter, R);
228
1.60k
    DataSet.InsertNode(SD, InsertPos);
229
1.60k
    ++SymbolCounter;
230
1.60k
  }
231
2.12k
232
2.12k
  return cast<SymbolExtent>(SD);
233
2.12k
}
234
235
const SymbolMetadata *
236
SymbolManager::getMetadataSymbol(const MemRegion* R, const Stmt *S, QualType T,
237
                                 const LocationContext *LCtx,
238
597
                                 unsigned Count, const void *SymbolTag) {
239
597
  llvm::FoldingSetNodeID profile;
240
597
  SymbolMetadata::Profile(profile, R, S, T, LCtx, Count, SymbolTag);
241
597
  void *InsertPos;
242
597
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
243
597
  if (!SD) {
244
573
    SD = (SymExpr*) BPAlloc.Allocate<SymbolMetadata>();
245
573
    new (SD) SymbolMetadata(SymbolCounter, R, S, T, LCtx, Count, SymbolTag);
246
573
    DataSet.InsertNode(SD, InsertPos);
247
573
    ++SymbolCounter;
248
573
  }
249
597
250
597
  return cast<SymbolMetadata>(SD);
251
597
}
252
253
const SymbolCast*
254
SymbolManager::getCastSymbol(const SymExpr *Op,
255
34
                             QualType From, QualType To) {
256
34
  llvm::FoldingSetNodeID ID;
257
34
  SymbolCast::Profile(ID, Op, From, To);
258
34
  void *InsertPos;
259
34
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
260
34
  if (!data) {
261
29
    data = (SymbolCast*) BPAlloc.Allocate<SymbolCast>();
262
29
    new (data) SymbolCast(Op, From, To);
263
29
    DataSet.InsertNode(data, InsertPos);
264
29
  }
265
34
266
34
  return cast<SymbolCast>(data);
267
34
}
268
269
const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs,
270
                                               BinaryOperator::Opcode op,
271
                                               const llvm::APSInt& v,
272
168k
                                               QualType t) {
273
168k
  llvm::FoldingSetNodeID ID;
274
168k
  SymIntExpr::Profile(ID, lhs, op, v, t);
275
168k
  void *InsertPos;
276
168k
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
277
168k
278
168k
  if (!data) {
279
25.4k
    data = (SymIntExpr*) BPAlloc.Allocate<SymIntExpr>();
280
25.4k
    new (data) SymIntExpr(lhs, op, v, t);
281
25.4k
    DataSet.InsertNode(data, InsertPos);
282
25.4k
  }
283
168k
284
168k
  return cast<SymIntExpr>(data);
285
168k
}
286
287
const IntSymExpr *SymbolManager::getIntSymExpr(const llvm::APSInt& lhs,
288
                                               BinaryOperator::Opcode op,
289
                                               const SymExpr *rhs,
290
147
                                               QualType t) {
291
147
  llvm::FoldingSetNodeID ID;
292
147
  IntSymExpr::Profile(ID, lhs, op, rhs, t);
293
147
  void *InsertPos;
294
147
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
295
147
296
147
  if (!data) {
297
130
    data = (IntSymExpr*) BPAlloc.Allocate<IntSymExpr>();
298
130
    new (data) IntSymExpr(lhs, op, rhs, t);
299
130
    DataSet.InsertNode(data, InsertPos);
300
130
  }
301
147
302
147
  return cast<IntSymExpr>(data);
303
147
}
304
305
const SymSymExpr *SymbolManager::getSymSymExpr(const SymExpr *lhs,
306
                                               BinaryOperator::Opcode op,
307
                                               const SymExpr *rhs,
308
13.9k
                                               QualType t) {
309
13.9k
  llvm::FoldingSetNodeID ID;
310
13.9k
  SymSymExpr::Profile(ID, lhs, op, rhs, t);
311
13.9k
  void *InsertPos;
312
13.9k
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
313
13.9k
314
13.9k
  if (!data) {
315
2.19k
    data = (SymSymExpr*) BPAlloc.Allocate<SymSymExpr>();
316
2.19k
    new (data) SymSymExpr(lhs, op, rhs, t);
317
2.19k
    DataSet.InsertNode(data, InsertPos);
318
2.19k
  }
319
13.9k
320
13.9k
  return cast<SymSymExpr>(data);
321
13.9k
}
322
323
648k
QualType SymbolConjured::getType() const {
324
648k
  return T;
325
648k
}
326
327
148k
QualType SymbolDerived::getType() const {
328
148k
  return R->getValueType();
329
148k
}
330
331
16.9k
QualType SymbolExtent::getType() const {
332
16.9k
  ASTContext &Ctx = R->getMemRegionManager().getContext();
333
16.9k
  return Ctx.getSizeType();
334
16.9k
}
335
336
11.0k
QualType SymbolMetadata::getType() const {
337
11.0k
  return T;
338
11.0k
}
339
340
397k
QualType SymbolRegionValue::getType() const {
341
397k
  return R->getValueType();
342
397k
}
343
344
12.6k
SymbolManager::~SymbolManager() {
345
12.6k
  llvm::DeleteContainerSeconds(SymbolDependencies);
346
12.6k
}
347
348
255k
bool SymbolManager::canSymbolicate(QualType T) {
349
255k
  T = T.getCanonicalType();
350
255k
351
255k
  if (Loc::isLocType(T))
352
67.3k
    return true;
353
188k
354
188k
  if (T->isIntegralOrEnumerationType())
355
172k
    return true;
356
15.1k
357
15.1k
  if (T->isRecordType() && 
!T->isUnionType()3.42k
)
358
3.42k
    return true;
359
11.7k
360
11.7k
  return false;
361
11.7k
}
362
363
void SymbolManager::addSymbolDependency(const SymbolRef Primary,
364
127
                                        const SymbolRef Dependent) {
365
127
  SymbolDependTy::iterator I = SymbolDependencies.find(Primary);
366
127
  SymbolRefSmallVectorTy *dependencies = nullptr;
367
127
  if (I == SymbolDependencies.end()) {
368
117
    dependencies = new SymbolRefSmallVectorTy();
369
117
    SymbolDependencies[Primary] = dependencies;
370
117
  } else {
371
10
    dependencies = I->second;
372
10
  }
373
127
  dependencies->push_back(Dependent);
374
127
}
375
376
const SymbolRefSmallVectorTy *SymbolManager::getDependentSymbols(
377
5.45M
                                                     const SymbolRef Primary) {
378
5.45M
  SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary);
379
5.45M
  if (I == SymbolDependencies.end())
380
5.45M
    return nullptr;
381
1.78k
  return I->second;
382
1.78k
}
383
384
7.09M
void SymbolReaper::markDependentsLive(SymbolRef sym) {
385
7.09M
  // Do not mark dependents more then once.
386
7.09M
  SymbolMapTy::iterator LI = TheLiving.find(sym);
387
7.09M
  assert(LI != TheLiving.end() && "The primary symbol is not live.");
388
7.09M
  if (LI->second == HaveMarkedDependents)
389
1.64M
    return;
390
5.45M
  LI->second = HaveMarkedDependents;
391
5.45M
392
5.45M
  if (const SymbolRefSmallVectorTy *Deps = SymMgr.getDependentSymbols(sym)) {
393
1.95k
    for (const auto I : *Deps) {
394
1.95k
      if (TheLiving.find(I) != TheLiving.end())
395
1.01k
        continue;
396
938
      markLive(I);
397
938
    }
398
1.78k
  }
399
5.45M
}
400
401
5.45M
void SymbolReaper::markLive(SymbolRef sym) {
402
5.45M
  TheLiving[sym] = NotProcessed;
403
5.45M
  markDependentsLive(sym);
404
5.45M
}
405
406
2.43M
void SymbolReaper::markLive(const MemRegion *region) {
407
2.43M
  RegionRoots.insert(region->getBaseRegion());
408
2.43M
  markElementIndicesLive(region);
409
2.43M
}
410
411
4.70M
void SymbolReaper::markElementIndicesLive(const MemRegion *region) {
412
9.13M
  for (auto SR = dyn_cast<SubRegion>(region); SR;
413
4.70M
       
SR = dyn_cast<SubRegion>(SR->getSuperRegion())4.43M
) {
414
4.43M
    if (const auto ER = dyn_cast<ElementRegion>(SR)) {
415
260k
      SVal Idx = ER->getIndex();
416
1.05M
      for (auto SI = Idx.symbol_begin(), SE = Idx.symbol_end(); SI != SE; 
++SI795k
)
417
795k
        markLive(*SI);
418
260k
    }
419
4.43M
  }
420
4.70M
}
421
422
1.66k
void SymbolReaper::markInUse(SymbolRef sym) {
423
1.66k
  if (isa<SymbolMetadata>(sym))
424
1.61k
    MetadataInUse.insert(sym);
425
1.66k
}
426
427
2.15M
bool SymbolReaper::isLiveRegion(const MemRegion *MR) {
428
2.15M
  // TODO: For now, liveness of a memory region is equivalent to liveness of its
429
2.15M
  // base region. In fact we can do a bit better: say, if a particular FieldDecl
430
2.15M
  // is not used later in the path, we can diagnose a leak of a value within
431
2.15M
  // that field earlier than, say, the variable that contains the field dies.
432
2.15M
  MR = MR->getBaseRegion();
433
2.15M
434
2.15M
  if (RegionRoots.count(MR))
435
422k
    return true;
436
1.73M
437
1.73M
  if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
438
639k
    return isLive(SR->getSymbol());
439
1.09M
440
1.09M
  if (const auto *VR = dyn_cast<VarRegion>(MR))
441
1.07M
    return isLive(VR, true);
442
14.8k
443
14.8k
  // FIXME: This is a gross over-approximation. What we really need is a way to
444
14.8k
  // tell if anything still refers to this region. Unlike SymbolicRegions,
445
14.8k
  // AllocaRegions don't have associated symbols, though, so we don't actually
446
14.8k
  // have a way to track their liveness.
447
14.8k
  if (isa<AllocaRegion>(MR))
448
4.84k
    return true;
449
9.98k
450
9.98k
  if (isa<CXXThisRegion>(MR))
451
5.90k
    return true;
452
4.07k
453
4.07k
  if (isa<MemSpaceRegion>(MR))
454
0
    return true;
455
4.07k
456
4.07k
  if (isa<CodeTextRegion>(MR))
457
31
    return true;
458
4.04k
459
4.04k
  return false;
460
4.04k
}
461
462
4.51M
bool SymbolReaper::isLive(SymbolRef sym) {
463
4.51M
  if (TheLiving.count(sym)) {
464
1.64M
    markDependentsLive(sym);
465
1.64M
    return true;
466
1.64M
  }
467
2.86M
468
2.86M
  bool KnownLive;
469
2.86M
470
2.86M
  switch (sym->getKind()) {
471
1.06M
  case SymExpr::SymbolRegionValueKind:
472
1.06M
    KnownLive = isLiveRegion(cast<SymbolRegionValue>(sym)->getRegion());
473
1.06M
    break;
474
76.0k
  case SymExpr::SymbolConjuredKind:
475
76.0k
    KnownLive = false;
476
76.0k
    break;
477
79.5k
  case SymExpr::SymbolDerivedKind:
478
79.5k
    KnownLive = isLive(cast<SymbolDerived>(sym)->getParentSymbol());
479
79.5k
    break;
480
16.0k
  case SymExpr::SymbolExtentKind:
481
16.0k
    KnownLive = isLiveRegion(cast<SymbolExtent>(sym)->getRegion());
482
16.0k
    break;
483
1.68k
  case SymExpr::SymbolMetadataKind:
484
1.68k
    KnownLive = MetadataInUse.count(sym) &&
485
1.68k
                
isLiveRegion(cast<SymbolMetadata>(sym)->getRegion())1.45k
;
486
1.68k
    if (KnownLive)
487
581
      MetadataInUse.erase(sym);
488
1.68k
    break;
489
1.46M
  case SymExpr::SymIntExprKind:
490
1.46M
    KnownLive = isLive(cast<SymIntExpr>(sym)->getLHS());
491
1.46M
    break;
492
14
  case SymExpr::IntSymExprKind:
493
14
    KnownLive = isLive(cast<IntSymExpr>(sym)->getRHS());
494
14
    break;
495
161k
  case SymExpr::SymSymExprKind:
496
161k
    KnownLive = isLive(cast<SymSymExpr>(sym)->getLHS()) &&
497
161k
                
isLive(cast<SymSymExpr>(sym)->getRHS())147k
;
498
161k
    break;
499
20
  case SymExpr::SymbolCastKind:
500
20
    KnownLive = isLive(cast<SymbolCast>(sym)->getOperand());
501
20
    break;
502
2.86M
  }
503
2.86M
504
2.86M
  if (KnownLive)
505
2.68M
    markLive(sym);
506
2.86M
507
2.86M
  return KnownLive;
508
2.86M
}
509
510
bool
511
2.85M
SymbolReaper::isLive(const Stmt *ExprVal, const LocationContext *ELCtx) const {
512
2.85M
  if (LCtx == nullptr)
513
37.9k
    return false;
514
2.82M
515
2.82M
  if (LCtx != ELCtx) {
516
1.33M
    // If the reaper's location context is a parent of the expression's
517
1.33M
    // location context, then the expression value is now "out of scope".
518
1.33M
    if (LCtx->isParentOf(ELCtx))
519
173k
      return false;
520
1.16M
    return true;
521
1.16M
  }
522
1.48M
523
1.48M
  // If no statement is provided, everything is this and parent contexts is live.
524
1.48M
  if (!Loc)
525
170k
    return true;
526
1.31M
527
1.31M
  return LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, ExprVal);
528
1.31M
}
529
530
1.99M
bool SymbolReaper::isLive(const VarRegion *VR, bool includeStoreBindings) const{
531
1.99M
  const StackFrameContext *VarContext = VR->getStackFrame();
532
1.99M
533
1.99M
  if (!VarContext)
534
87.3k
    return true;
535
1.91M
536
1.91M
  if (!LCtx)
537
26.5k
    return false;
538
1.88M
  const StackFrameContext *CurrentContext = LCtx->getStackFrame();
539
1.88M
540
1.88M
  if (VarContext == CurrentContext) {
541
519k
    // If no statement is provided, everything is live.
542
519k
    if (!Loc)
543
62.3k
      return true;
544
456k
545
456k
    // Anonymous parameters of an inheriting constructor are live for the entire
546
456k
    // duration of the constructor.
547
456k
    if (isa<CXXInheritedCtorInitExpr>(Loc))
548
6
      return true;
549
456k
550
456k
    if (LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, VR->getDecl()))
551
304k
      return true;
552
152k
553
152k
    if (!includeStoreBindings)
554
118k
      return false;
555
33.1k
556
33.1k
    unsigned &cachedQuery =
557
33.1k
      const_cast<SymbolReaper *>(this)->includedRegionCache[VR];
558
33.1k
559
33.1k
    if (cachedQuery) {
560
838
      return cachedQuery == 1;
561
838
    }
562
32.2k
563
32.2k
    // Query the store to see if the region occurs in any live bindings.
564
32.2k
    if (Store store = reapedStore.getStore()) {
565
25.7k
      bool hasRegion =
566
25.7k
        reapedStore.getStoreManager().includedInBindings(store, VR);
567
25.7k
      cachedQuery = hasRegion ? 
10
: 2;
568
25.7k
      return hasRegion;
569
25.7k
    }
570
6.57k
571
6.57k
    return false;
572
6.57k
  }
573
1.36M
574
1.36M
  return VarContext->isParentOf(CurrentContext);
575
1.36M
}