1 //===- ConstraintManager.cpp - Constraints on symbolic values. ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defined the interface to manage constraints on symbolic values.
11 //===----------------------------------------------------------------------===//
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"
20 using namespace clang;
23 ConstraintManager::~ConstraintManager() = default;
25 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
28 State->getStateManager().getRegionManager().getSymbolicRegion(Sym);
29 return loc::MemRegionVal(R);
32 ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
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);