From 43e2aafea1cdeca3a3fc849b41a92cc18e001ac0 Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Mon, 6 Jul 2009 03:41:27 +0000 Subject: [PATCH] Start to gradually move region invalidation code into store manager. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74812 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/PathSensitive/Store.h | 2 + lib/Analysis/CFRefCount.cpp | 69 +------------------- lib/Analysis/Store.cpp | 57 ++++++++++++++++ 3 files changed, 62 insertions(+), 66 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h index 5aa53507fd..1070e11a9b 100644 --- a/include/clang/Analysis/PathSensitive/Store.h +++ b/include/clang/Analysis/PathSensitive/Store.h @@ -157,6 +157,8 @@ public: virtual const GRState *BindDeclWithNoInit(const GRState *state, const VarDecl *vd) = 0; + const GRState *InvalidateRegion(const GRState *state, const TypedRegion *R, + const Expr *E, unsigned Count); // FIXME: Make out-of-line. virtual const GRState *setExtent(const GRState *state, const MemRegion *region, SVal extent) { diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 3cca482633..a96281a5e9 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -2797,7 +2797,8 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst, // disambiguate conjured symbols. unsigned Count = Builder.getCurrentBlockCount(); const TypedRegion* R = dyn_cast(MR->getRegion()); - + StoreManager& StoreMgr = + Eng.getStateManager().getStoreManager(); if (R) { // Are we dealing with an ElementRegion? If the element type is // a basic integer type (e.g., char, int) and the underying region @@ -2829,78 +2830,14 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst, // Remove any existing reference-count binding. if (Sym) state = state->remove(Sym); - - if (R->isBoundable()) { - // Set the value of the variable to be a conjured symbol. - QualType T = R->getValueType(Ctx); - - if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())){ - ValueManager &ValMgr = Eng.getValueManager(); - SVal V = ValMgr.getConjuredSymbolVal(*I, T, Count); - state = state->bindLoc(ValMgr.makeLoc(R), V); - } - else if (const RecordType *RT = T->getAsStructureType()) { - // Handle structs in a not so awesome way. Here we just - // eagerly bind new symbols to the fields. In reality we - // should have the store manager handle this. The idea is just - // to prototype some basic functionality here. All of this logic - // should one day soon just go away. - const RecordDecl *RD = RT->getDecl()->getDefinition(Ctx); - - // No record definition. There is nothing we can do. - if (!RD) - continue; - - MemRegionManager &MRMgr = - state->getStateManager().getRegionManager(); - - // Iterate through the fields and construct new symbols. - for (RecordDecl::field_iterator FI=RD->field_begin(), - FE=RD->field_end(); FI!=FE; ++FI) { - - // For now just handle scalar fields. - FieldDecl *FD = *FI; - QualType FT = FD->getType(); - const FieldRegion* FR = MRMgr.getFieldRegion(FD, R); - - if (Loc::IsLocType(FT) || - (FT->isIntegerType() && FT->isScalarType())) { - SVal V = ValMgr.getConjuredSymbolVal(*I, FT, Count); - state = state->bindLoc(ValMgr.makeLoc(FR), V); - } - else if (FT->isStructureType()) { - // set the default value of the struct field to conjured - // symbol. Note that the type of the symbol is irrelavant. - // We cannot use the type of the struct otherwise ValMgr won't - // give us the conjured symbol. - StoreManager& StoreMgr = - Eng.getStateManager().getStoreManager(); - SVal V = ValMgr.getConjuredSymbolVal(*I, - Eng.getContext().IntTy, - Count); - state = StoreMgr.setDefaultValue(state, FR, V); - } - } - } else if (const ArrayType *AT = Ctx.getAsArrayType(T)) { - // Set the default value of the array to conjured symbol. - StoreManager& StoreMgr = Eng.getStateManager().getStoreManager(); - SVal V = ValMgr.getConjuredSymbolVal(*I, AT->getElementType(), - Count); - state = StoreMgr.setDefaultValue(state, R, V); - } else { - // Just blast away other values. - state = state->bindLoc(*MR, UnknownVal()); - } - } + state = StoreMgr.InvalidateRegion(state, R, *I, Count); } else if (isa(MR->getRegion())) { // Invalidate the alloca region by setting its default value to // conjured symbol. The type of the symbol is irrelavant. SVal V = ValMgr.getConjuredSymbolVal(*I, Eng.getContext().IntTy, Count); - StoreManager& StoreMgr = - Eng.getStateManager().getStoreManager(); state = StoreMgr.setDefaultValue(state, MR->getRegion(), V); } else diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp index cb099862f0..c836de9940 100644 --- a/lib/Analysis/Store.cpp +++ b/lib/Analysis/Store.cpp @@ -109,3 +109,60 @@ StoreManager::CastRegion(const GRState* state, const MemRegion* R, return CastResult(state, R); } + +const GRState *StoreManager::InvalidateRegion(const GRState *state, + const TypedRegion *R, + const Expr *E, unsigned Count) { + if (!R->isBoundable()) + return state; + + ASTContext& Ctx = StateMgr.getContext(); + QualType T = R->getValueType(Ctx); + + if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) { + SVal V = ValMgr.getConjuredSymbolVal(E, T, Count); + return Bind(state, ValMgr.makeLoc(R), V); + } + else if (const RecordType *RT = T->getAsStructureType()) { + // FIXME: handle structs with default region value. + const RecordDecl *RD = RT->getDecl()->getDefinition(Ctx); + + // No record definition. There is nothing we can do. + if (!RD) + return state; + + // Iterate through the fields and construct new symbols. + for (RecordDecl::field_iterator FI=RD->field_begin(), + FE=RD->field_end(); FI!=FE; ++FI) { + + // For now just handle scalar fields. + FieldDecl *FD = *FI; + QualType FT = FD->getType(); + const FieldRegion* FR = MRMgr.getFieldRegion(FD, R); + + if (Loc::IsLocType(FT) || + (FT->isIntegerType() && FT->isScalarType())) { + SVal V = ValMgr.getConjuredSymbolVal(E, FT, Count); + state = state->bindLoc(ValMgr.makeLoc(FR), V); + } + else if (FT->isStructureType()) { + // set the default value of the struct field to conjured + // symbol. Note that the type of the symbol is irrelavant. + // We cannot use the type of the struct otherwise ValMgr won't + // give us the conjured symbol. + SVal V = ValMgr.getConjuredSymbolVal(E, Ctx.IntTy, Count); + state = setDefaultValue(state, FR, V); + } + } + } else if (const ArrayType *AT = Ctx.getAsArrayType(T)) { + // Set the default value of the array to conjured symbol. + SVal V = ValMgr.getConjuredSymbolVal(E, AT->getElementType(), + Count); + state = setDefaultValue(state, R, V); + } else { + // Just blast away other values. + state = Bind(state, ValMgr.makeLoc(R), UnknownVal()); + } + + return state; +} -- 2.40.0