clang 8.0.0

ConstraintManager.cpp
Go to the documentation of this file.
1 //===- ConstraintManager.cpp - Constraints on symbolic values. ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defined the interface to manage constraints on symbolic values.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
15 #include "clang/AST/Type.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
20
21 using namespace clang;
22 using namespace ento;
23
24 ConstraintManager::~ConstraintManager() = default;
25
26 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
27 SymbolRef Sym) {
28 const MemRegion *R =
29 State->getStateManager().getRegionManager().getSymbolicRegion(Sym);
30 return loc::MemRegionVal(R);
31 }
32
33 ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
34 SymbolRef Sym) {
35 QualType Ty = Sym->getType();
36 DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
37 : nonloc::SymbolVal(Sym);
38 const ProgramStatePair &P = assumeDual(State, V);
39 if (P.first && !P.second)
40 return ConditionTruthVal(false);
41 if (!P.first && P.second)
42 return ConditionTruthVal(true);
43 return {};
44 }
clang::ento::DefinedSVal
Definition: SVals.h:260
ento
SVals.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::ento::SymbolRef
const SymExpr * SymbolRef
Definition: PathDiagnostic.h:59
Type.h
C Language Family Type Representation.
clang::ento::ProgramStateRef
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Definition: ProgramState_Fwd.h:38
P
StringRef P
Definition: ASTMatchersInternal.cpp:439
ConstraintManager.h
MemRegion.h
clang::ento::ConstraintManager::checkNull
virtual ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym)
Returns whether or not a symbol is known to be null ("true"), known to be non-null ("false")...
Definition: ConstraintManager.cpp:33
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:30
clang::ento::ConstraintManager::~ConstraintManager
virtual ~ConstraintManager()
State
LineState State
Definition: UnwrappedLineFormatter.cpp:877
ProgramState_Fwd.h
clang::ento::Loc::isLocType
static bool isLocType(QualType T)
Definition: SVals.h:327
clang::ento::SymExpr::getType
virtual QualType getType() const =0
clang::ento::ConstraintManager::assumeDual
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false...
Definition: ConstraintManager.h:91
ProgramState.h
getLocFromSymbol
static DefinedSVal getLocFromSymbol(const ProgramStateRef &State, SymbolRef Sym)
Definition: ConstraintManager.cpp:26
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:45
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::ento::nonloc::SymbolVal
Represents symbolic expression that isn&#39;t a location.
Definition: SVals.h:347
clang::ento::ConstraintManager::ProgramStatePair
std::pair< ProgramStateRef, ProgramStateRef > ProgramStatePair
Definition: ConstraintManager.h:87
clang::ento::ConditionTruthVal
Definition: ConstraintManager.h:39