2012-09-08 06:31:01 +08:00
|
|
|
//== ConstraintManager.cpp - Constraints on symbolic values -----*- C++ -*--==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defined the interface to manage constraints on symbolic values.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace ento;
|
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
ConstraintManager::~ConstraintManager() {}
|
2012-09-08 06:31:01 +08:00
|
|
|
|
|
|
|
static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
|
|
|
|
SymbolRef Sym) {
|
|
|
|
const MemRegion *R = State->getStateManager().getRegionManager()
|
|
|
|
.getSymbolicRegion(Sym);
|
|
|
|
return loc::MemRegionVal(R);
|
|
|
|
}
|
|
|
|
|
2012-11-01 00:44:55 +08:00
|
|
|
ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
|
2015-09-08 11:50:52 +08:00
|
|
|
SymbolRef Sym) {
|
2012-09-26 14:00:14 +08:00
|
|
|
QualType Ty = Sym->getType();
|
2012-09-08 06:31:01 +08:00
|
|
|
DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
|
|
|
|
: nonloc::SymbolVal(Sym);
|
|
|
|
const ProgramStatePair &P = assumeDual(State, V);
|
|
|
|
if (P.first && !P.second)
|
|
|
|
return ConditionTruthVal(false);
|
|
|
|
if (!P.first && P.second)
|
|
|
|
return ConditionTruthVal(true);
|
|
|
|
return ConditionTruthVal();
|
|
|
|
}
|