Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
5
void SymbolConjured::dumpToStream(raw_ostream &os) const {
85
5
  os << "conj_$" << getSymbolID() << '{' << T.getAsString() << ", LC"
86
5
     << LCtx->getID();
87
5
  if (S)
88
5
    os << ", S" << S->getID(LCtx->getDecl()->getASTContext());
89
0
  else
90
0
    os << ", no stmt";
91
5
  os << ", #" << Count << '}';
92
5
}
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
3
void SymbolRegionValue::dumpToStream(raw_ostream &os) const {
111
3
  os << "reg_$" << getSymbolID()
112
3
     << '<' << getType().getAsString() << ' ' << R << '>';
113
3
}
114
115
0
bool SymExpr::symbol_iterator::operator==(const symbol_iterator &X) const {
116
0
  return itr == X.itr;
117
0
}
118
119
3.97M
bool SymExpr::symbol_iterator::operator!=(const symbol_iterator &X) const {
120
3.97M
  return itr != X.itr;
121
3.97M
}
122
123
1.10M
SymExpr::symbol_iterator::symbol_iterator(const SymExpr *SE) {
124
1.10M
  itr.push_back(SE);
125
1.10M
}
126
127
2.03M
SymExpr::symbol_iterator &SymExpr::symbol_iterator::operator++() {
128
2.03M
  assert(!itr.empty() && "attempting to iterate on an 'end' iterator");
129
2.03M
  expand();
130
2.03M
  return *this;
131
2.03M
}
132
133
2.48M
SymbolRef SymExpr::symbol_iterator::operator*() {
134
2.48M
  assert(!itr.empty() && "attempting to dereference an 'end' iterator");
135
2.48M
  return itr.back();
136
2.48M
}
137
138
2.03M
void SymExpr::symbol_iterator::expand() {
139
2.03M
  const SymExpr *SE = itr.pop_back_val();
140
2.03M
141
2.03M
  switch (SE->getKind()) {
142
2.03M
    case SymExpr::SymbolRegionValueKind:
143
1.49M
    case SymExpr::SymbolConjuredKind:
144
1.49M
    case SymExpr::SymbolDerivedKind:
145
1.49M
    case SymExpr::SymbolExtentKind:
146
1.49M
    case SymExpr::SymbolMetadataKind:
147
1.49M
      return;
148
1.49M
    case SymExpr::SymbolCastKind:
149
84
      itr.push_back(cast<SymbolCast>(SE)->getOperand());
150
84
      return;
151
1.49M
    case SymExpr::SymIntExprKind:
152
140k
      itr.push_back(cast<SymIntExpr>(SE)->getLHS());
153
140k
      return;
154
1.49M
    case SymExpr::IntSymExprKind:
155
3.58k
      itr.push_back(cast<IntSymExpr>(SE)->getRHS());
156
3.58k
      return;
157
1.49M
    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
77.9k
SymbolManager::getRegionValueSymbol(const TypedValueRegion* R) {
169
77.9k
  llvm::FoldingSetNodeID profile;
170
77.9k
  SymbolRegionValue::Profile(profile, R);
171
77.9k
  void *InsertPos;
172
77.9k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
173
77.9k
  if (!SD) {
174
8.77k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolRegionValue>();
175
8.77k
    new (SD) SymbolRegionValue(SymbolCounter, R);
176
8.77k
    DataSet.InsertNode(SD, InsertPos);
177
8.77k
    ++SymbolCounter;
178
8.77k
  }
179
77.9k
180
77.9k
  return cast<SymbolRegionValue>(SD);
181
77.9k
}
182
183
const SymbolConjured* SymbolManager::conjureSymbol(const Stmt *E,
184
                                                   const LocationContext *LCtx,
185
                                                   QualType T,
186
                                                   unsigned Count,
187
94.7k
                                                   const void *SymbolTag) {
188
94.7k
  llvm::FoldingSetNodeID profile;
189
94.7k
  SymbolConjured::Profile(profile, E, T, Count, LCtx, SymbolTag);
190
94.7k
  void *InsertPos;
191
94.7k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
192
94.7k
  if (!SD) {
193
45.6k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolConjured>();
194
45.6k
    new (SD) SymbolConjured(SymbolCounter, E, LCtx, T, Count, SymbolTag);
195
45.6k
    DataSet.InsertNode(SD, InsertPos);
196
45.6k
    ++SymbolCounter;
197
45.6k
  }
198
94.7k
199
94.7k
  return cast<SymbolConjured>(SD);
200
94.7k
}
201
202
const SymbolDerived*
203
SymbolManager::getDerivedSymbol(SymbolRef parentSymbol,
204
11.5k
                                const TypedValueRegion *R) {
205
11.5k
  llvm::FoldingSetNodeID profile;
206
11.5k
  SymbolDerived::Profile(profile, parentSymbol, R);
207
11.5k
  void *InsertPos;
208
11.5k
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
209
11.5k
  if (!SD) {
210
1.37k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolDerived>();
211
1.37k
    new (SD) SymbolDerived(SymbolCounter, parentSymbol, R);
212
1.37k
    DataSet.InsertNode(SD, InsertPos);
213
1.37k
    ++SymbolCounter;
214
1.37k
  }
215
11.5k
216
11.5k
  return cast<SymbolDerived>(SD);
217
11.5k
}
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.58k
    SD = (SymExpr*) BPAlloc.Allocate<SymbolExtent>();
227
1.58k
    new (SD) SymbolExtent(SymbolCounter, R);
228
1.58k
    DataSet.InsertNode(SD, InsertPos);
229
1.58k
    ++SymbolCounter;
230
1.58k
  }
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
480
                                 unsigned Count, const void *SymbolTag) {
239
480
  llvm::FoldingSetNodeID profile;
240
480
  SymbolMetadata::Profile(profile, R, S, T, LCtx, Count, SymbolTag);
241
480
  void *InsertPos;
242
480
  SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
243
480
  if (!SD) {
244
456
    SD = (SymExpr*) BPAlloc.Allocate<SymbolMetadata>();
245
456
    new (SD) SymbolMetadata(SymbolCounter, R, S, T, LCtx, Count, SymbolTag);
246
456
    DataSet.InsertNode(SD, InsertPos);
247
456
    ++SymbolCounter;
248
456
  }
249
480
250
480
  return cast<SymbolMetadata>(SD);
251
480
}
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
152k
                                               QualType t) {
273
152k
  llvm::FoldingSetNodeID ID;
274
152k
  SymIntExpr::Profile(ID, lhs, op, v, t);
275
152k
  void *InsertPos;
276
152k
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
277
152k
278
152k
  if (!data) {
279
18.3k
    data = (SymIntExpr*) BPAlloc.Allocate<SymIntExpr>();
280
18.3k
    new (data) SymIntExpr(lhs, op, v, t);
281
18.3k
    DataSet.InsertNode(data, InsertPos);
282
18.3k
  }
283
152k
284
152k
  return cast<SymIntExpr>(data);
285
152k
}
286
287
const IntSymExpr *SymbolManager::getIntSymExpr(const llvm::APSInt& lhs,
288
                                               BinaryOperator::Opcode op,
289
                                               const SymExpr *rhs,
290
143
                                               QualType t) {
291
143
  llvm::FoldingSetNodeID ID;
292
143
  IntSymExpr::Profile(ID, lhs, op, rhs, t);
293
143
  void *InsertPos;
294
143
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
295
143
296
143
  if (!data) {
297
126
    data = (IntSymExpr*) BPAlloc.Allocate<IntSymExpr>();
298
126
    new (data) IntSymExpr(lhs, op, rhs, t);
299
126
    DataSet.InsertNode(data, InsertPos);
300
126
  }
301
143
302
143
  return cast<IntSymExpr>(data);
303
143
}
304
305
const SymSymExpr *SymbolManager::getSymSymExpr(const SymExpr *lhs,
306
                                               BinaryOperator::Opcode op,
307
                                               const SymExpr *rhs,
308
11.6k
                                               QualType t) {
309
11.6k
  llvm::FoldingSetNodeID ID;
310
11.6k
  SymSymExpr::Profile(ID, lhs, op, rhs, t);
311
11.6k
  void *InsertPos;
312
11.6k
  SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
313
11.6k
314
11.6k
  if (!data) {
315
1.53k
    data = (SymSymExpr*) BPAlloc.Allocate<SymSymExpr>();
316
1.53k
    new (data) SymSymExpr(lhs, op, rhs, t);
317
1.53k
    DataSet.InsertNode(data, InsertPos);
318
1.53k
  }
319
11.6k
320
11.6k
  return cast<SymSymExpr>(data);
321
11.6k
}
322
323
306k
QualType SymbolConjured::getType() const {
324
306k
  return T;
325
306k
}
326
327
106k
QualType SymbolDerived::getType() const {
328
106k
  return R->getValueType();
329
106k
}
330
331
9.69k
QualType SymbolExtent::getType() const {
332
9.69k
  ASTContext &Ctx = R->getMemRegionManager()->getContext();
333
9.69k
  return Ctx.getSizeType();
334
9.69k
}
335
336
6.76k
QualType SymbolMetadata::getType() const {
337
6.76k
  return T;
338
6.76k
}
339
340
248k
QualType SymbolRegionValue::getType() const {
341
248k
  return R->getValueType();
342
248k
}
343
344
10.8k
SymbolManager::~SymbolManager() {
345
10.8k
  llvm::DeleteContainerSeconds(SymbolDependencies);
346
10.8k
}
347
348
190k
bool SymbolManager::canSymbolicate(QualType T) {
349
190k
  T = T.getCanonicalType();
350
190k
351
190k
  if (Loc::isLocType(T))
352
47.5k
    return true;
353
143k
354
143k
  if (T->isIntegralOrEnumerationType())
355
133k
    return true;
356
9.18k
357
9.18k
  if (T->isRecordType() && 
!T->isUnionType()694
)
358
694
    return true;
359
8.49k
360
8.49k
  return false;
361
8.49k
}
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
4.77M
                                                     const SymbolRef Primary) {
378
4.77M
  SymbolDependTy::const_iterator I = SymbolDependencies.find(Primary);
379
4.77M
  if (I == SymbolDependencies.end())
380
4.76M
    return nullptr;
381
1.78k
  return I->second;
382
1.78k
}
383
384
8.21M
void SymbolReaper::markDependentsLive(SymbolRef sym) {
385
8.21M
  // Do not mark dependents more then once.
386
8.21M
  SymbolMapTy::iterator LI = TheLiving.find(sym);
387
8.21M
  assert(LI != TheLiving.end() && "The primary symbol is not live.");
388
8.21M
  if (LI->second == HaveMarkedDependents)
389
3.44M
    return;
390
4.77M
  LI->second = HaveMarkedDependents;
391
4.77M
392
4.77M
  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.02k
        continue;
396
937
      markLive(I);
397
937
    }
398
1.78k
  }
399
4.77M
}
400
401
4.77M
void SymbolReaper::markLive(SymbolRef sym) {
402
4.77M
  TheLiving[sym] = NotProcessed;
403
4.77M
  markDependentsLive(sym);
404
4.77M
}
405
406
1.27M
void SymbolReaper::markLive(const MemRegion *region) {
407
1.27M
  RegionRoots.insert(region->getBaseRegion());
408
1.27M
  markElementIndicesLive(region);
409
1.27M
}
410
411
2.76M
void SymbolReaper::markElementIndicesLive(const MemRegion *region) {
412
5.44M
  for (auto SR = dyn_cast<SubRegion>(region); SR;
413
2.76M
       
SR = dyn_cast<SubRegion>(SR->getSuperRegion())2.67M
) {
414
2.67M
    if (const auto ER = dyn_cast<ElementRegion>(SR)) {
415
186k
      SVal Idx = ER->getIndex();
416
982k
      for (auto SI = Idx.symbol_begin(), SE = Idx.symbol_end(); SI != SE; 
++SI795k
)
417
795k
        markLive(*SI);
418
186k
    }
419
2.67M
  }
420
2.76M
}
421
422
1.62k
void SymbolReaper::markInUse(SymbolRef sym) {
423
1.62k
  if (isa<SymbolMetadata>(sym))
424
1.56k
    MetadataInUse.insert(sym);
425
1.62k
}
426
427
1.14M
bool SymbolReaper::isLiveRegion(const MemRegion *MR) {
428
1.14M
  // TODO: For now, liveness of a memory region is equivalent to liveness of its
429
1.14M
  // base region. In fact we can do a bit better: say, if a particular FieldDecl
430
1.14M
  // is not used later in the path, we can diagnose a leak of a value within
431
1.14M
  // that field earlier than, say, the variable that contains the field dies.
432
1.14M
  MR = MR->getBaseRegion();
433
1.14M
434
1.14M
  if (RegionRoots.count(MR))
435
314k
    return true;
436
826k
437
826k
  if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
438
636k
    return isLive(SR->getSymbol());
439
189k
440
189k
  if (const auto *VR = dyn_cast<VarRegion>(MR))
441
178k
    return isLive(VR, true);
442
11.1k
443
11.1k
  // FIXME: This is a gross over-approximation. What we really need is a way to
444
11.1k
  // tell if anything still refers to this region. Unlike SymbolicRegions,
445
11.1k
  // AllocaRegions don't have associated symbols, though, so we don't actually
446
11.1k
  // have a way to track their liveness.
447
11.1k
  if (isa<AllocaRegion>(MR))
448
4.84k
    return true;
449
6.27k
450
6.27k
  if (isa<CXXThisRegion>(MR))
451
4.36k
    return true;
452
1.91k
453
1.91k
  if (isa<MemSpaceRegion>(MR))
454
0
    return true;
455
1.91k
456
1.91k
  if (isa<CodeTextRegion>(MR))
457
27
    return true;
458
1.88k
459
1.88k
  return false;
460
1.88k
}
461
462
6.41M
bool SymbolReaper::isLive(SymbolRef sym) {
463
6.41M
  if (TheLiving.count(sym)) {
464
3.44M
    markDependentsLive(sym);
465
3.44M
    return true;
466
3.44M
  }
467
2.96M
468
2.96M
  bool KnownLive;
469
2.96M
470
2.96M
  switch (sym->getKind()) {
471
2.96M
  case SymExpr::SymbolRegionValueKind:
472
1.07M
    KnownLive = isLiveRegion(cast<SymbolRegionValue>(sym)->getRegion());
473
1.07M
    break;
474
2.96M
  case SymExpr::SymbolConjuredKind:
475
109k
    KnownLive = false;
476
109k
    break;
477
2.96M
  case SymExpr::SymbolDerivedKind:
478
104k
    KnownLive = isLive(cast<SymbolDerived>(sym)->getParentSymbol());
479
104k
    break;
480
2.96M
  case SymExpr::SymbolExtentKind:
481
16.7k
    KnownLive = isLiveRegion(cast<SymbolExtent>(sym)->getRegion());
482
16.7k
    break;
483
2.96M
  case SymExpr::SymbolMetadataKind:
484
2.23k
    KnownLive = MetadataInUse.count(sym) &&
485
2.23k
                
isLiveRegion(cast<SymbolMetadata>(sym)->getRegion())1.84k
;
486
2.23k
    if (KnownLive)
487
556
      MetadataInUse.erase(sym);
488
2.23k
    break;
489
2.96M
  case SymExpr::SymIntExprKind:
490
1.49M
    KnownLive = isLive(cast<SymIntExpr>(sym)->getLHS());
491
1.49M
    break;
492
2.96M
  case SymExpr::IntSymExprKind:
493
25
    KnownLive = isLive(cast<IntSymExpr>(sym)->getRHS());
494
25
    break;
495
2.96M
  case SymExpr::SymSymExprKind:
496
172k
    KnownLive = isLive(cast<SymSymExpr>(sym)->getLHS()) &&
497
172k
                
isLive(cast<SymSymExpr>(sym)->getRHS())145k
;
498
172k
    break;
499
2.96M
  case SymExpr::SymbolCastKind:
500
40
    KnownLive = isLive(cast<SymbolCast>(sym)->getOperand());
501
40
    break;
502
2.96M
  }
503
2.96M
504
2.96M
  if (KnownLive)
505
2.67M
    markLive(sym);
506
2.96M
507
2.96M
  return KnownLive;
508
2.96M
}
509
510
bool
511
1.88M
SymbolReaper::isLive(const Stmt *ExprVal, const LocationContext *ELCtx) const {
512
1.88M
  if (LCtx == nullptr)
513
32.9k
    return false;
514
1.85M
515
1.85M
  if (LCtx != ELCtx) {
516
768k
    // If the reaper's location context is a parent of the expression's
517
768k
    // location context, then the expression value is now "out of scope".
518
768k
    if (LCtx->isParentOf(ELCtx))
519
96.2k
      return false;
520
672k
    return true;
521
672k
  }
522
1.08M
523
1.08M
  // If no statement is provided, everything is this and parent contexts is live.
524
1.08M
  if (!Loc)
525
84.3k
    return true;
526
1.00M
527
1.00M
  return LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, ExprVal);
528
1.00M
}
529
530
797k
bool SymbolReaper::isLive(const VarRegion *VR, bool includeStoreBindings) const{
531
797k
  const StackFrameContext *VarContext = VR->getStackFrame();
532
797k
533
797k
  if (!VarContext)
534
84.4k
    return true;
535
712k
536
712k
  if (!LCtx)
537
15.8k
    return false;
538
697k
  const StackFrameContext *CurrentContext = LCtx->getStackFrame();
539
697k
540
697k
  if (VarContext == CurrentContext) {
541
326k
    // If no statement is provided, everything is live.
542
326k
    if (!Loc)
543
32.5k
      return true;
544
293k
545
293k
    if (LCtx->getAnalysis<RelaxedLiveVariables>()->isLive(Loc, VR->getDecl()))
546
214k
      return true;
547
79.2k
548
79.2k
    if (!includeStoreBindings)
549
64.6k
      return false;
550
14.6k
551
14.6k
    unsigned &cachedQuery =
552
14.6k
      const_cast<SymbolReaper *>(this)->includedRegionCache[VR];
553
14.6k
554
14.6k
    if (cachedQuery) {
555
3.23k
      return cachedQuery == 1;
556
3.23k
    }
557
11.3k
558
11.3k
    // Query the store to see if the region occurs in any live bindings.
559
11.3k
    if (Store store = reapedStore.getStore()) {
560
3.52k
      bool hasRegion =
561
3.52k
        reapedStore.getStoreManager().includedInBindings(store, VR);
562
3.52k
      cachedQuery = hasRegion ? 
10
: 2;
563
3.52k
      return hasRegion;
564
3.52k
    }
565
7.85k
566
7.85k
    return false;
567
7.85k
  }
568
370k
569
370k
  return VarContext->isParentOf(CurrentContext);
570
370k
}