xref: /llvm-project/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (revision 8d3c9602959df4caadfade1f40512231f7d6bbe8)
1 //===-- DataflowEnvironment.cpp ---------------------------------*- 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 defines an Environment class that is used by dataflow analyses
10 //  that run over Control-Flow Graphs (CFGs) to keep track of the state of the
11 //  program at given program points.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
20 #include "clang/Analysis/FlowSensitive/Value.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/DenseSet.h"
23 #include "llvm/Support/Casting.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include <cassert>
26 #include <memory>
27 #include <utility>
28 
29 namespace clang {
30 namespace dataflow {
31 
32 // FIXME: convert these to parameters of the analysis or environment. Current
33 // settings have been experimentaly validated, but only for a particular
34 // analysis.
35 static constexpr int MaxCompositeValueDepth = 3;
36 static constexpr int MaxCompositeValueSize = 1000;
37 
38 /// Returns a map consisting of key-value entries that are present in both maps.
39 template <typename K, typename V>
40 llvm::DenseMap<K, V> intersectDenseMaps(const llvm::DenseMap<K, V> &Map1,
41                                         const llvm::DenseMap<K, V> &Map2) {
42   llvm::DenseMap<K, V> Result;
43   for (auto &Entry : Map1) {
44     auto It = Map2.find(Entry.first);
45     if (It != Map2.end() && Entry.second == It->second)
46       Result.insert({Entry.first, Entry.second});
47   }
48   return Result;
49 }
50 
51 static bool areEquivalentIndirectionValues(Value *Val1, Value *Val2) {
52   if (auto *IndVal1 = dyn_cast<ReferenceValue>(Val1)) {
53     auto *IndVal2 = cast<ReferenceValue>(Val2);
54     return &IndVal1->getReferentLoc() == &IndVal2->getReferentLoc();
55   }
56   if (auto *IndVal1 = dyn_cast<PointerValue>(Val1)) {
57     auto *IndVal2 = cast<PointerValue>(Val2);
58     return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
59   }
60   return false;
61 }
62 
63 /// Returns true if and only if `Val1` is equivalent to `Val2`.
64 static bool equivalentValues(QualType Type, Value *Val1,
65                              const Environment &Env1, Value *Val2,
66                              const Environment &Env2,
67                              Environment::ValueModel &Model) {
68   return Val1 == Val2 || areEquivalentIndirectionValues(Val1, Val2) ||
69          Model.compareEquivalent(Type, *Val1, Env1, *Val2, Env2);
70 }
71 
72 /// Attempts to merge distinct values `Val1` and `Val2` in `Env1` and `Env2`,
73 /// respectively, of the same type `Type`. Merging generally produces a single
74 /// value that (soundly) approximates the two inputs, although the actual
75 /// meaning depends on `Model`.
76 static Value *mergeDistinctValues(QualType Type, Value *Val1,
77                                   const Environment &Env1, Value *Val2,
78                                   const Environment &Env2,
79                                   Environment &MergedEnv,
80                                   Environment::ValueModel &Model) {
81   // Join distinct boolean values preserving information about the constraints
82   // in the respective path conditions.
83   //
84   // FIXME: Does not work for backedges, since the two (or more) paths will not
85   // have mutually exclusive conditions.
86   if (auto *Expr1 = dyn_cast<BoolValue>(Val1)) {
87     auto *Expr2 = cast<BoolValue>(Val2);
88     auto &MergedVal = MergedEnv.makeAtomicBoolValue();
89     MergedEnv.addToFlowCondition(MergedEnv.makeOr(
90         MergedEnv.makeAnd(Env1.getFlowConditionToken(),
91                           MergedEnv.makeIff(MergedVal, *Expr1)),
92         MergedEnv.makeAnd(Env2.getFlowConditionToken(),
93                           MergedEnv.makeIff(MergedVal, *Expr2))));
94     return &MergedVal;
95   }
96 
97   // FIXME: add unit tests that cover this statement.
98   if (areEquivalentIndirectionValues(Val1, Val2)) {
99     return Val1;
100   }
101 
102   // FIXME: Consider destroying `MergedValue` immediately if `ValueModel::merge`
103   // returns false to avoid storing unneeded values in `DACtx`.
104   if (Value *MergedVal = MergedEnv.createValue(Type))
105     if (Model.merge(Type, *Val1, Env1, *Val2, Env2, *MergedVal, MergedEnv))
106       return MergedVal;
107 
108   return nullptr;
109 }
110 
111 /// Initializes a global storage value.
112 static void initGlobalVar(const VarDecl &D, Environment &Env) {
113   if (!D.hasGlobalStorage() ||
114       Env.getStorageLocation(D, SkipPast::None) != nullptr)
115     return;
116 
117   auto &Loc = Env.createStorageLocation(D);
118   Env.setStorageLocation(D, Loc);
119   if (auto *Val = Env.createValue(D.getType()))
120     Env.setValue(Loc, *Val);
121 }
122 
123 /// Initializes a global storage value.
124 static void initGlobalVar(const Decl &D, Environment &Env) {
125   if (auto *V = dyn_cast<VarDecl>(&D))
126     initGlobalVar(*V, Env);
127 }
128 
129 /// Initializes global storage values that are declared or referenced from
130 /// sub-statements of `S`.
131 // FIXME: Add support for resetting globals after function calls to enable
132 // the implementation of sound analyses.
133 static void initGlobalVars(const Stmt &S, Environment &Env) {
134   for (auto *Child : S.children()) {
135     if (Child != nullptr)
136       initGlobalVars(*Child, Env);
137   }
138 
139   if (auto *DS = dyn_cast<DeclStmt>(&S)) {
140     if (DS->isSingleDecl()) {
141       initGlobalVar(*DS->getSingleDecl(), Env);
142     } else {
143       for (auto *D : DS->getDeclGroup())
144         initGlobalVar(*D, Env);
145     }
146   } else if (auto *E = dyn_cast<DeclRefExpr>(&S)) {
147     initGlobalVar(*E->getDecl(), Env);
148   } else if (auto *E = dyn_cast<MemberExpr>(&S)) {
149     initGlobalVar(*E->getMemberDecl(), Env);
150   }
151 }
152 
153 Environment::Environment(DataflowAnalysisContext &DACtx)
154     : DACtx(&DACtx), FlowConditionToken(&DACtx.makeFlowConditionToken()) {}
155 
156 Environment::Environment(const Environment &Other)
157     : DACtx(Other.DACtx), ReturnLoc(Other.ReturnLoc),
158       ThisPointeeLoc(Other.ThisPointeeLoc), DeclToLoc(Other.DeclToLoc),
159       ExprToLoc(Other.ExprToLoc), LocToVal(Other.LocToVal),
160       MemberLocToStruct(Other.MemberLocToStruct),
161       FlowConditionToken(&DACtx->forkFlowCondition(*Other.FlowConditionToken)) {
162 }
163 
164 Environment &Environment::operator=(const Environment &Other) {
165   Environment Copy(Other);
166   *this = std::move(Copy);
167   return *this;
168 }
169 
170 Environment::Environment(DataflowAnalysisContext &DACtx,
171                          const DeclContext &DeclCtx)
172     : Environment(DACtx) {
173   if (const auto *FuncDecl = dyn_cast<FunctionDecl>(&DeclCtx)) {
174     assert(FuncDecl->getBody() != nullptr);
175     initGlobalVars(*FuncDecl->getBody(), *this);
176     for (const auto *ParamDecl : FuncDecl->parameters()) {
177       assert(ParamDecl != nullptr);
178       auto &ParamLoc = createStorageLocation(*ParamDecl);
179       setStorageLocation(*ParamDecl, ParamLoc);
180       if (Value *ParamVal = createValue(ParamDecl->getType()))
181         setValue(ParamLoc, *ParamVal);
182     }
183 
184     QualType ReturnType = FuncDecl->getReturnType();
185     ReturnLoc = &createStorageLocation(ReturnType);
186   }
187 
188   if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(&DeclCtx)) {
189     auto *Parent = MethodDecl->getParent();
190     assert(Parent != nullptr);
191     if (Parent->isLambda())
192       MethodDecl = dyn_cast<CXXMethodDecl>(Parent->getDeclContext());
193 
194     if (MethodDecl && !MethodDecl->isStatic()) {
195       QualType ThisPointeeType = MethodDecl->getThisObjectType();
196       // FIXME: Add support for union types.
197       if (!ThisPointeeType->isUnionType()) {
198         ThisPointeeLoc = &createStorageLocation(ThisPointeeType);
199         if (Value *ThisPointeeVal = createValue(ThisPointeeType))
200           setValue(*ThisPointeeLoc, *ThisPointeeVal);
201       }
202     }
203   }
204 }
205 
206 Environment Environment::pushCall(const CallExpr *Call) const {
207   Environment Env(*this);
208   // FIXME: Support references here.
209   Env.ReturnLoc = Env.getStorageLocation(*Call, SkipPast::Reference);
210 
211   const auto *FuncDecl = Call->getDirectCallee();
212   assert(FuncDecl != nullptr);
213   // FIXME: In order to allow the callee to reference globals, we probably need
214   // to call `initGlobalVars` here in some way.
215 
216   if (const auto *MethodCall = dyn_cast<CXXMemberCallExpr>(Call)) {
217     if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
218       Env.ThisPointeeLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
219     }
220   }
221 
222   auto ParamIt = FuncDecl->param_begin();
223   auto ArgIt = Call->arg_begin();
224   auto ArgEnd = Call->arg_end();
225 
226   // FIXME: Parameters don't always map to arguments 1:1; examples include
227   // overloaded operators implemented as member functions, and parameter packs.
228   for (; ArgIt != ArgEnd; ++ParamIt, ++ArgIt) {
229     assert(ParamIt != FuncDecl->param_end());
230 
231     const Expr *Arg = *ArgIt;
232     auto *ArgLoc = Env.getStorageLocation(*Arg, SkipPast::Reference);
233     assert(ArgLoc != nullptr);
234 
235     const VarDecl *Param = *ParamIt;
236     auto &Loc = Env.createStorageLocation(*Param);
237     Env.setStorageLocation(*Param, Loc);
238 
239     QualType ParamType = Param->getType();
240     if (ParamType->isReferenceType()) {
241       auto &Val = Env.takeOwnership(std::make_unique<ReferenceValue>(*ArgLoc));
242       Env.setValue(Loc, Val);
243     } else if (auto *ArgVal = Env.getValue(*ArgLoc)) {
244       Env.setValue(Loc, *ArgVal);
245     } else if (Value *Val = Env.createValue(ParamType)) {
246       Env.setValue(Loc, *Val);
247     }
248   }
249 
250   return Env;
251 }
252 
253 void Environment::popCall(const Environment &CalleeEnv) {
254   // We ignore `DACtx` because it's already the same in both. We don't want the
255   // callee's `ReturnLoc` or `ThisPointeeLoc`. We don't bring back `DeclToLoc`
256   // and `ExprToLoc` because we want to be able to later analyze the same callee
257   // in a different context, and `setStorageLocation` requires there to not
258   // already be a storage location assigned. Conceptually, these maps capture
259   // information from the local scope, so when popping that scope, we do not
260   // propagate the maps.
261   this->LocToVal = std::move(CalleeEnv.LocToVal);
262   this->MemberLocToStruct = std::move(CalleeEnv.MemberLocToStruct);
263   this->FlowConditionToken = std::move(CalleeEnv.FlowConditionToken);
264 }
265 
266 bool Environment::equivalentTo(const Environment &Other,
267                                Environment::ValueModel &Model) const {
268   assert(DACtx == Other.DACtx);
269 
270   if (ReturnLoc != Other.ReturnLoc)
271     return false;
272 
273   if (ThisPointeeLoc != Other.ThisPointeeLoc)
274     return false;
275 
276   if (DeclToLoc != Other.DeclToLoc)
277     return false;
278 
279   if (ExprToLoc != Other.ExprToLoc)
280     return false;
281 
282   // Compare the contents for the intersection of their domains.
283   for (auto &Entry : LocToVal) {
284     const StorageLocation *Loc = Entry.first;
285     assert(Loc != nullptr);
286 
287     Value *Val = Entry.second;
288     assert(Val != nullptr);
289 
290     auto It = Other.LocToVal.find(Loc);
291     if (It == Other.LocToVal.end())
292       continue;
293     assert(It->second != nullptr);
294 
295     if (!equivalentValues(Loc->getType(), Val, *this, It->second, Other, Model))
296       return false;
297   }
298 
299   return true;
300 }
301 
302 LatticeJoinEffect Environment::join(const Environment &Other,
303                                     Environment::ValueModel &Model) {
304   assert(DACtx == Other.DACtx);
305   assert(ReturnLoc == Other.ReturnLoc);
306   assert(ThisPointeeLoc == Other.ThisPointeeLoc);
307 
308   auto Effect = LatticeJoinEffect::Unchanged;
309 
310   Environment JoinedEnv(*DACtx);
311 
312   JoinedEnv.ReturnLoc = ReturnLoc;
313   JoinedEnv.ThisPointeeLoc = ThisPointeeLoc;
314 
315   JoinedEnv.DeclToLoc = intersectDenseMaps(DeclToLoc, Other.DeclToLoc);
316   if (DeclToLoc.size() != JoinedEnv.DeclToLoc.size())
317     Effect = LatticeJoinEffect::Changed;
318 
319   JoinedEnv.ExprToLoc = intersectDenseMaps(ExprToLoc, Other.ExprToLoc);
320   if (ExprToLoc.size() != JoinedEnv.ExprToLoc.size())
321     Effect = LatticeJoinEffect::Changed;
322 
323   JoinedEnv.MemberLocToStruct =
324       intersectDenseMaps(MemberLocToStruct, Other.MemberLocToStruct);
325   if (MemberLocToStruct.size() != JoinedEnv.MemberLocToStruct.size())
326     Effect = LatticeJoinEffect::Changed;
327 
328   // FIXME: set `Effect` as needed.
329   JoinedEnv.FlowConditionToken = &DACtx->joinFlowConditions(
330       *FlowConditionToken, *Other.FlowConditionToken);
331 
332   for (auto &Entry : LocToVal) {
333     const StorageLocation *Loc = Entry.first;
334     assert(Loc != nullptr);
335 
336     Value *Val = Entry.second;
337     assert(Val != nullptr);
338 
339     auto It = Other.LocToVal.find(Loc);
340     if (It == Other.LocToVal.end())
341       continue;
342     assert(It->second != nullptr);
343 
344     if (Val == It->second) {
345       JoinedEnv.LocToVal.insert({Loc, Val});
346       continue;
347     }
348 
349     if (Value *MergedVal = mergeDistinctValues(
350             Loc->getType(), Val, *this, It->second, Other, JoinedEnv, Model))
351       JoinedEnv.LocToVal.insert({Loc, MergedVal});
352   }
353   if (LocToVal.size() != JoinedEnv.LocToVal.size())
354     Effect = LatticeJoinEffect::Changed;
355 
356   *this = std::move(JoinedEnv);
357 
358   return Effect;
359 }
360 
361 StorageLocation &Environment::createStorageLocation(QualType Type) {
362   return DACtx->createStorageLocation(Type);
363 }
364 
365 StorageLocation &Environment::createStorageLocation(const VarDecl &D) {
366   // Evaluated declarations are always assigned the same storage locations to
367   // ensure that the environment stabilizes across loop iterations. Storage
368   // locations for evaluated declarations are stored in the analysis context.
369   return DACtx->getStableStorageLocation(D);
370 }
371 
372 StorageLocation &Environment::createStorageLocation(const Expr &E) {
373   // Evaluated expressions are always assigned the same storage locations to
374   // ensure that the environment stabilizes across loop iterations. Storage
375   // locations for evaluated expressions are stored in the analysis context.
376   return DACtx->getStableStorageLocation(E);
377 }
378 
379 void Environment::setStorageLocation(const ValueDecl &D, StorageLocation &Loc) {
380   assert(DeclToLoc.find(&D) == DeclToLoc.end());
381   DeclToLoc[&D] = &Loc;
382 }
383 
384 StorageLocation *Environment::getStorageLocation(const ValueDecl &D,
385                                                  SkipPast SP) const {
386   auto It = DeclToLoc.find(&D);
387   return It == DeclToLoc.end() ? nullptr : &skip(*It->second, SP);
388 }
389 
390 void Environment::setStorageLocation(const Expr &E, StorageLocation &Loc) {
391   const Expr &CanonE = ignoreCFGOmittedNodes(E);
392   assert(ExprToLoc.find(&CanonE) == ExprToLoc.end());
393   ExprToLoc[&CanonE] = &Loc;
394 }
395 
396 StorageLocation *Environment::getStorageLocation(const Expr &E,
397                                                  SkipPast SP) const {
398   // FIXME: Add a test with parens.
399   auto It = ExprToLoc.find(&ignoreCFGOmittedNodes(E));
400   return It == ExprToLoc.end() ? nullptr : &skip(*It->second, SP);
401 }
402 
403 StorageLocation *Environment::getThisPointeeStorageLocation() const {
404   return ThisPointeeLoc;
405 }
406 
407 StorageLocation *Environment::getReturnStorageLocation() const {
408   return ReturnLoc;
409 }
410 
411 PointerValue &Environment::getOrCreateNullPointerValue(QualType PointeeType) {
412   return DACtx->getOrCreateNullPointerValue(PointeeType);
413 }
414 
415 void Environment::setValue(const StorageLocation &Loc, Value &Val) {
416   LocToVal[&Loc] = &Val;
417 
418   if (auto *StructVal = dyn_cast<StructValue>(&Val)) {
419     auto &AggregateLoc = *cast<AggregateStorageLocation>(&Loc);
420 
421     const QualType Type = AggregateLoc.getType();
422     assert(Type->isStructureOrClassType());
423 
424     for (const FieldDecl *Field : getObjectFields(Type)) {
425       assert(Field != nullptr);
426       StorageLocation &FieldLoc = AggregateLoc.getChild(*Field);
427       MemberLocToStruct[&FieldLoc] = std::make_pair(StructVal, Field);
428       if (auto *FieldVal = StructVal->getChild(*Field))
429         setValue(FieldLoc, *FieldVal);
430     }
431   }
432 
433   auto It = MemberLocToStruct.find(&Loc);
434   if (It != MemberLocToStruct.end()) {
435     // `Loc` is the location of a struct member so we need to also update the
436     // value of the member in the corresponding `StructValue`.
437 
438     assert(It->second.first != nullptr);
439     StructValue &StructVal = *It->second.first;
440 
441     assert(It->second.second != nullptr);
442     const ValueDecl &Member = *It->second.second;
443 
444     StructVal.setChild(Member, Val);
445   }
446 }
447 
448 Value *Environment::getValue(const StorageLocation &Loc) const {
449   auto It = LocToVal.find(&Loc);
450   return It == LocToVal.end() ? nullptr : It->second;
451 }
452 
453 Value *Environment::getValue(const ValueDecl &D, SkipPast SP) const {
454   auto *Loc = getStorageLocation(D, SP);
455   if (Loc == nullptr)
456     return nullptr;
457   return getValue(*Loc);
458 }
459 
460 Value *Environment::getValue(const Expr &E, SkipPast SP) const {
461   auto *Loc = getStorageLocation(E, SP);
462   if (Loc == nullptr)
463     return nullptr;
464   return getValue(*Loc);
465 }
466 
467 Value *Environment::createValue(QualType Type) {
468   llvm::DenseSet<QualType> Visited;
469   int CreatedValuesCount = 0;
470   Value *Val = createValueUnlessSelfReferential(Type, Visited, /*Depth=*/0,
471                                                 CreatedValuesCount);
472   if (CreatedValuesCount > MaxCompositeValueSize) {
473     llvm::errs() << "Attempting to initialize a huge value of type: " << Type
474                  << '\n';
475   }
476   return Val;
477 }
478 
479 Value *Environment::createValueUnlessSelfReferential(
480     QualType Type, llvm::DenseSet<QualType> &Visited, int Depth,
481     int &CreatedValuesCount) {
482   assert(!Type.isNull());
483 
484   // Allow unlimited fields at depth 1; only cap at deeper nesting levels.
485   if ((Depth > 1 && CreatedValuesCount > MaxCompositeValueSize) ||
486       Depth > MaxCompositeValueDepth)
487     return nullptr;
488 
489   if (Type->isBooleanType()) {
490     CreatedValuesCount++;
491     return &makeAtomicBoolValue();
492   }
493 
494   if (Type->isIntegerType()) {
495     CreatedValuesCount++;
496     return &takeOwnership(std::make_unique<IntegerValue>());
497   }
498 
499   if (Type->isReferenceType()) {
500     CreatedValuesCount++;
501     QualType PointeeType = Type->castAs<ReferenceType>()->getPointeeType();
502     auto &PointeeLoc = createStorageLocation(PointeeType);
503 
504     if (Visited.insert(PointeeType.getCanonicalType()).second) {
505       Value *PointeeVal = createValueUnlessSelfReferential(
506           PointeeType, Visited, Depth, CreatedValuesCount);
507       Visited.erase(PointeeType.getCanonicalType());
508 
509       if (PointeeVal != nullptr)
510         setValue(PointeeLoc, *PointeeVal);
511     }
512 
513     return &takeOwnership(std::make_unique<ReferenceValue>(PointeeLoc));
514   }
515 
516   if (Type->isPointerType()) {
517     CreatedValuesCount++;
518     QualType PointeeType = Type->castAs<PointerType>()->getPointeeType();
519     auto &PointeeLoc = createStorageLocation(PointeeType);
520 
521     if (Visited.insert(PointeeType.getCanonicalType()).second) {
522       Value *PointeeVal = createValueUnlessSelfReferential(
523           PointeeType, Visited, Depth, CreatedValuesCount);
524       Visited.erase(PointeeType.getCanonicalType());
525 
526       if (PointeeVal != nullptr)
527         setValue(PointeeLoc, *PointeeVal);
528     }
529 
530     return &takeOwnership(std::make_unique<PointerValue>(PointeeLoc));
531   }
532 
533   if (Type->isStructureOrClassType()) {
534     CreatedValuesCount++;
535     // FIXME: Initialize only fields that are accessed in the context that is
536     // being analyzed.
537     llvm::DenseMap<const ValueDecl *, Value *> FieldValues;
538     for (const FieldDecl *Field : getObjectFields(Type)) {
539       assert(Field != nullptr);
540 
541       QualType FieldType = Field->getType();
542       if (Visited.contains(FieldType.getCanonicalType()))
543         continue;
544 
545       Visited.insert(FieldType.getCanonicalType());
546       if (auto *FieldValue = createValueUnlessSelfReferential(
547               FieldType, Visited, Depth + 1, CreatedValuesCount))
548         FieldValues.insert({Field, FieldValue});
549       Visited.erase(FieldType.getCanonicalType());
550     }
551 
552     return &takeOwnership(
553         std::make_unique<StructValue>(std::move(FieldValues)));
554   }
555 
556   return nullptr;
557 }
558 
559 StorageLocation &Environment::skip(StorageLocation &Loc, SkipPast SP) const {
560   switch (SP) {
561   case SkipPast::None:
562     return Loc;
563   case SkipPast::Reference:
564     // References cannot be chained so we only need to skip past one level of
565     // indirection.
566     if (auto *Val = dyn_cast_or_null<ReferenceValue>(getValue(Loc)))
567       return Val->getReferentLoc();
568     return Loc;
569   case SkipPast::ReferenceThenPointer:
570     StorageLocation &LocPastRef = skip(Loc, SkipPast::Reference);
571     if (auto *Val = dyn_cast_or_null<PointerValue>(getValue(LocPastRef)))
572       return Val->getPointeeLoc();
573     return LocPastRef;
574   }
575   llvm_unreachable("bad SkipPast kind");
576 }
577 
578 const StorageLocation &Environment::skip(const StorageLocation &Loc,
579                                          SkipPast SP) const {
580   return skip(*const_cast<StorageLocation *>(&Loc), SP);
581 }
582 
583 void Environment::addToFlowCondition(BoolValue &Val) {
584   DACtx->addFlowConditionConstraint(*FlowConditionToken, Val);
585 }
586 
587 bool Environment::flowConditionImplies(BoolValue &Val) const {
588   return DACtx->flowConditionImplies(*FlowConditionToken, Val);
589 }
590 
591 void Environment::dump() const {
592   DACtx->dumpFlowCondition(*FlowConditionToken);
593 }
594 
595 } // namespace dataflow
596 } // namespace clang
597