clang 10.0.0git

ConstraintManager.cpp
Go to the documentation of this file.
1 //===- ConstraintManager.cpp - Constraints on 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 defined the interface to manage constraints on symbolic values.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
14 #include "clang/AST/Type.h"
15 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
19
20 using namespace clang;
21 using namespace ento;
22
23 ConstraintManager::~ConstraintManager() = default;
24
25 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
26 SymbolRef Sym) {
27 const MemRegion *R =
28 State->getStateManager().getRegionManager().getSymbolicRegion(Sym);
29 return loc::MemRegionVal(R);
30 }
31
32 ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
33 SymbolRef Sym) {
34 QualType Ty = Sym->getType();
35 DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
36 : nonloc::SymbolVal(Sym);
37 const ProgramStatePair &P = assumeDual(State, V);
38 if (P.first && !P.second)
39 return ConditionTruthVal(false);
40 if (!P.first && P.second)
41 return ConditionTruthVal(true);
42 return {};
43 }
clang::ento::DefinedSVal
Definition: SVals.h:262
ento
SVals.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:654
Type.h
C Language Family Type Representation.
clang::ento::ProgramStateRef
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Definition: ProgramState_Fwd.h:37
P
StringRef P
Definition: ASTMatchersInternal.cpp:485
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:32
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:29
clang::ento::ConstraintManager::~ConstraintManager
virtual ~ConstraintManager()
clang::ento::SymbolRef
const SymExpr * SymbolRef
Definition: SymExpr.h:110
State
LineState State
Definition: UnwrappedLineFormatter.cpp:932
ProgramState_Fwd.h
clang::ento::Loc::isLocType
static bool isLocType(QualType T)
Definition: SVals.h:329
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:93
V
#define V(N, I)
Definition: ASTContext.h:2941
ProgramState.h
getLocFromSymbol
static DefinedSVal getLocFromSymbol(const ProgramStateRef &State, SymbolRef Sym)
Definition: ConstraintManager.cpp:25
llvm::IntrusiveRefCntPtr< const ProgramState >
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ento::nonloc::SymbolVal
Represents symbolic expression that isn&#39;t a location.
Definition: SVals.h:349
clang::ento::ConstraintManager::ProgramStatePair
std::pair< ProgramStateRef, ProgramStateRef > ProgramStatePair
Definition: ConstraintManager.h:89
clang::ento::ConditionTruthVal
Definition: ConstraintManager.h:38