1 //===- ConstraintManager.cpp - Constraints on symbolic values. ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defined the interface to manage constraints on symbolic values.
12 //===----------------------------------------------------------------------===//
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"
21 using namespace clang;
24 ConstraintManager::~ConstraintManager() = default;
26 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
29 State->getStateManager().getRegionManager().getSymbolicRegion(Sym);
30 return loc::MemRegionVal(R);
33 ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
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);