1*0b57cec5SDimitry Andric //===- ConstraintManager.cpp - Constraints on symbolic values. ------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // This file defined the interface to manage constraints on symbolic values. 10*0b57cec5SDimitry Andric // 11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h" 14*0b57cec5SDimitry Andric #include "clang/AST/Type.h" 15*0b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" 16*0b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" 17*0b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" 18*0b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 19*0b57cec5SDimitry Andric 20*0b57cec5SDimitry Andric using namespace clang; 21*0b57cec5SDimitry Andric using namespace ento; 22*0b57cec5SDimitry Andric 23*0b57cec5SDimitry Andric ConstraintManager::~ConstraintManager() = default; 24*0b57cec5SDimitry Andric getLocFromSymbol(const ProgramStateRef & State,SymbolRef Sym)25*0b57cec5SDimitry Andricstatic DefinedSVal getLocFromSymbol(const ProgramStateRef &State, 26*0b57cec5SDimitry Andric SymbolRef Sym) { 27*0b57cec5SDimitry Andric const MemRegion *R = 28*0b57cec5SDimitry Andric State->getStateManager().getRegionManager().getSymbolicRegion(Sym); 29*0b57cec5SDimitry Andric return loc::MemRegionVal(R); 30*0b57cec5SDimitry Andric } 31*0b57cec5SDimitry Andric checkNull(ProgramStateRef State,SymbolRef Sym)32*0b57cec5SDimitry AndricConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State, 33*0b57cec5SDimitry Andric SymbolRef Sym) { 34*0b57cec5SDimitry Andric QualType Ty = Sym->getType(); 35*0b57cec5SDimitry Andric DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym) 36*0b57cec5SDimitry Andric : nonloc::SymbolVal(Sym); 37*0b57cec5SDimitry Andric const ProgramStatePair &P = assumeDual(State, V); 38*0b57cec5SDimitry Andric if (P.first && !P.second) 39*0b57cec5SDimitry Andric return ConditionTruthVal(false); 40*0b57cec5SDimitry Andric if (!P.first && P.second) 41*0b57cec5SDimitry Andric return ConditionTruthVal(true); 42*0b57cec5SDimitry Andric return {}; 43*0b57cec5SDimitry Andric } 44