clang API Documentation

ConstraintManager.cpp
Go to the documentation of this file.
00001 //== ConstraintManager.cpp - Constraints on symbolic values -----*- C++ -*--==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defined the interface to manage constraints on symbolic values.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
00015 
00016 using namespace clang;
00017 using namespace ento;
00018 
00019 ConstraintManager::~ConstraintManager() {}
00020 
00021 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
00022                                     SymbolRef Sym) {
00023   const MemRegion *R = State->getStateManager().getRegionManager()
00024                                                .getSymbolicRegion(Sym);
00025   return loc::MemRegionVal(R);
00026 }
00027 
00028 ConditionTruthVal ConstraintManager::checkNull(ProgramStateRef State,
00029                                                SymbolRef Sym) {  
00030   QualType Ty = Sym->getType();
00031   DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
00032                                      : nonloc::SymbolVal(Sym);
00033   const ProgramStatePair &P = assumeDual(State, V);
00034   if (P.first && !P.second)
00035     return ConditionTruthVal(false);
00036   if (!P.first && P.second)
00037     return ConditionTruthVal(true);
00038   return ConditionTruthVal();
00039 }