opnsense-src/include/clang/Checker/PathSensitive/ValueManager.h

209 lines
6.9 KiB
C
Raw Normal View History

2009-06-02 13:58:47 -04:00
//== ValueManager.h - Aggregate manager of symbols and SVals ----*- C++ -*--==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines ValueManager, a class that manages symbolic values
// and SVals created for use by GRExprEngine and related classes. It
2009-06-23 10:50:21 -04:00
// wraps and owns SymbolManager, MemRegionManager, and BasicValueFactory.
2009-06-02 13:58:47 -04:00
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_ANALYSIS_AGGREGATE_VALUE_MANAGER_H
#define LLVM_CLANG_ANALYSIS_AGGREGATE_VALUE_MANAGER_H
2009-10-14 14:03:49 -04:00
#include "llvm/ADT/OwningPtr.h"
2010-02-16 04:31:36 -05:00
#include "clang/Checker/PathSensitive/MemRegion.h"
#include "clang/Checker/PathSensitive/SVals.h"
#include "clang/Checker/PathSensitive/BasicValueFactory.h"
#include "clang/Checker/PathSensitive/SymbolManager.h"
#include "clang/Checker/PathSensitive/SValuator.h"
2009-06-02 13:58:47 -04:00
namespace llvm { class BumpPtrAllocator; }
2009-10-14 14:03:49 -04:00
namespace clang {
class GRStateManager;
2009-06-02 13:58:47 -04:00
class ValueManager {
2009-10-14 14:03:49 -04:00
ASTContext &Context;
2009-06-02 13:58:47 -04:00
BasicValueFactory BasicVals;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
/// SymMgr - Object that manages the symbol information.
SymbolManager SymMgr;
2009-10-14 14:03:49 -04:00
/// SVator - SValuator object that creates SVals from expressions.
llvm::OwningPtr<SValuator> SVator;
2009-06-02 13:58:47 -04:00
MemRegionManager MemMgr;
2009-10-14 14:03:49 -04:00
GRStateManager &StateMgr;
const QualType ArrayIndexTy;
const unsigned ArrayIndexWidth;
2009-06-02 13:58:47 -04:00
public:
2009-10-14 14:03:49 -04:00
ValueManager(llvm::BumpPtrAllocator &alloc, ASTContext &context,
GRStateManager &stateMgr)
: Context(context), BasicVals(context, alloc),
SymMgr(context, BasicVals, alloc),
MemMgr(context, alloc), StateMgr(stateMgr),
ArrayIndexTy(context.IntTy),
ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {
// FIXME: Generalize later.
SVator.reset(clang::CreateSimpleSValuator(*this));
}
2009-06-02 13:58:47 -04:00
// Accessors to submanagers.
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
ASTContext &getContext() { return Context; }
const ASTContext &getContext() const { return Context; }
2009-10-14 14:03:49 -04:00
GRStateManager &getStateManager() { return StateMgr; }
2009-06-02 13:58:47 -04:00
BasicValueFactory &getBasicValueFactory() { return BasicVals; }
const BasicValueFactory &getBasicValueFactory() const { return BasicVals; }
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
SymbolManager &getSymbolManager() { return SymMgr; }
const SymbolManager &getSymbolManager() const { return SymMgr; }
2009-10-14 14:03:49 -04:00
SValuator &getSValuator() { return *SVator.get(); }
2009-06-02 13:58:47 -04:00
MemRegionManager &getRegionManager() { return MemMgr; }
const MemRegionManager &getRegionManager() const { return MemMgr; }
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
// Forwarding methods to SymbolManager.
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
const SymbolConjured* getConjuredSymbol(const Stmt* E, QualType T,
unsigned VisitCount,
const void* SymbolTag = 0) {
return SymMgr.getConjuredSymbol(E, T, VisitCount, SymbolTag);
}
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
const SymbolConjured* getConjuredSymbol(const Expr* E, unsigned VisitCount,
2009-10-14 14:03:49 -04:00
const void* SymbolTag = 0) {
2009-06-02 13:58:47 -04:00
return SymMgr.getConjuredSymbol(E, VisitCount, SymbolTag);
}
2009-07-04 09:58:54 -04:00
2009-06-02 13:58:47 -04:00
/// makeZeroVal - Construct an SVal representing '0' for the specified type.
2009-10-14 14:03:49 -04:00
DefinedOrUnknownSVal makeZeroVal(QualType T);
2009-06-02 13:58:47 -04:00
2009-07-04 09:58:54 -04:00
/// getRegionValueSymbolVal - make a unique symbol for value of R.
2009-10-14 14:03:49 -04:00
DefinedOrUnknownSVal getRegionValueSymbolVal(const MemRegion *R,
QualType T = QualType());
DefinedOrUnknownSVal getConjuredSymbolVal(const void *SymbolTag,
const Expr *E, unsigned Count);
DefinedOrUnknownSVal getConjuredSymbolVal(const void *SymbolTag,
const Expr *E, QualType T,
unsigned Count);
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
const TypedRegion *R);
DefinedSVal getFunctionPointer(const FunctionDecl *FD);
2009-12-01 06:08:04 -05:00
DefinedSVal getBlockPointer(const BlockDecl *BD, CanQualType locTy,
const LocationContext *LC);
2009-06-23 10:50:21 -04:00
NonLoc makeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals) {
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
}
2010-02-16 04:31:36 -05:00
NonLoc makeLazyCompoundVal(const void *store, const TypedRegion *R) {
return nonloc::LazyCompoundVal(BasicVals.getLazyCompoundValData(store, R));
2009-10-14 14:03:49 -04:00
}
2009-06-23 10:50:21 -04:00
NonLoc makeZeroArrayIndex() {
2009-10-14 14:03:49 -04:00
return nonloc::ConcreteInt(BasicVals.getValue(0, ArrayIndexTy));
}
NonLoc makeArrayIndex(uint64_t idx) {
return nonloc::ConcreteInt(BasicVals.getValue(idx, ArrayIndexTy));
2009-06-23 10:50:21 -04:00
}
2009-10-14 14:03:49 -04:00
SVal convertToArrayIndex(SVal V);
2009-06-27 06:45:02 -04:00
nonloc::ConcreteInt makeIntVal(const IntegerLiteral* I) {
2009-06-23 10:50:21 -04:00
return nonloc::ConcreteInt(BasicVals.getValue(I->getValue(),
I->getType()->isUnsignedIntegerType()));
}
2009-06-27 06:45:02 -04:00
nonloc::ConcreteInt makeIntVal(const llvm::APSInt& V) {
2009-06-23 10:50:21 -04:00
return nonloc::ConcreteInt(BasicVals.getValue(V));
}
2009-10-14 14:03:49 -04:00
2009-06-27 06:45:02 -04:00
loc::ConcreteInt makeIntLocVal(const llvm::APSInt &v) {
return loc::ConcreteInt(BasicVals.getValue(v));
}
2009-06-23 10:50:21 -04:00
NonLoc makeIntVal(const llvm::APInt& V, bool isUnsigned) {
return nonloc::ConcreteInt(BasicVals.getValue(V, isUnsigned));
}
2009-10-14 14:03:49 -04:00
DefinedSVal makeIntVal(uint64_t X, QualType T) {
if (Loc::IsLocType(T))
return loc::ConcreteInt(BasicVals.getValue(X, T));
2009-06-23 10:50:21 -04:00
return nonloc::ConcreteInt(BasicVals.getValue(X, T));
}
NonLoc makeIntVal(uint64_t X, bool isUnsigned) {
return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
}
2009-10-14 14:03:49 -04:00
NonLoc makeIntValWithPtrWidth(uint64_t X, bool isUnsigned) {
return nonloc::ConcreteInt(BasicVals.getIntWithPtrWidth(X, isUnsigned));
}
2009-06-23 10:50:21 -04:00
NonLoc makeIntVal(uint64_t X, unsigned BitWidth, bool isUnsigned) {
return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
}
NonLoc makeLocAsInteger(Loc V, unsigned Bits) {
return nonloc::LocAsInteger(BasicVals.getPersistentSValWithData(V, Bits));
}
2009-06-02 13:58:47 -04:00
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const llvm::APSInt& rhs, QualType T);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType T);
2009-10-14 14:03:49 -04:00
2009-06-23 10:50:21 -04:00
NonLoc makeTruthVal(bool b, QualType T) {
return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
}
NonLoc makeTruthVal(bool b) {
return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
}
Loc makeNull() {
return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
}
Loc makeLoc(SymbolRef Sym) {
return loc::MemRegionVal(MemMgr.getSymbolicRegion(Sym));
}
Loc makeLoc(const MemRegion* R) {
return loc::MemRegionVal(R);
}
Loc makeLoc(const AddrLabelExpr* E) {
return loc::GotoLabel(E->getLabel());
}
Loc makeLoc(const llvm::APSInt& V) {
return loc::ConcreteInt(BasicVals.getValue(V));
}
2009-06-02 13:58:47 -04:00
};
} // end clang namespace
#endif