From 2f6eb14af4c4de9b334320f9d25203c675133cef Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 6 Aug 2009 21:43:54 +0000 Subject: Fix a couple false positive "uninitialized value" warnings with RegionStore involving reasoning about unions (which we don't handle yet). llvm-svn: 78342 --- clang/lib/Analysis/RegionStore.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'clang/lib/Analysis/RegionStore.cpp') diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index 32167560451..8cb4d980214 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/lib/Analysis/RegionStore.cpp @@ -18,6 +18,7 @@ #include "clang/Analysis/PathSensitive/GRState.h" #include "clang/Analysis/PathSensitive/GRStateTrait.h" #include "clang/Analysis/Analyses/LiveVariables.h" +#include "clang/Analysis/Support/Optional.h" #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/ImmutableMap.h" @@ -187,6 +188,11 @@ public: RegionStoreSubRegionMap *getRegionStoreSubRegionMap(const GRState *state); + + /// getDefaultBinding - Returns an SVal* representing an optional default + /// binding associated with a region and its subregions. + Optional getDefaultBinding(const GRState *state, const MemRegion *R); + /// getLValueString - Returns an SVal representing the lvalue of a /// StringLiteral. Within RegionStore a StringLiteral has an /// associated StringRegion, and the lvalue of a StringLiteral is @@ -829,6 +835,17 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, // Loading values from regions. //===----------------------------------------------------------------------===// +Optional RegionStoreManager::getDefaultBinding(const GRState *state, + const MemRegion *R) { + + if (R->isBoundable()) + if (const TypedRegion *TR = dyn_cast(R)) + if (TR->getValueType(getContext())->isUnionType()) + return UnknownVal(); + + return Optional::create(state->get(R)); +} + static bool IsReinterpreted(QualType RTy, QualType UsedTy, ASTContext &Ctx) { RTy = Ctx.getCanonicalType(RTy); UsedTy = Ctx.getCanonicalType(UsedTy); @@ -911,6 +928,10 @@ RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { if (RTy->isStructureType()) return SValuator::CastResult(state, RetrieveStruct(state, R)); + + // FIXME: Handle unions. + if (RTy->isUnionType()) + return SValuator::CastResult(state, UnknownVal()); if (RTy->isArrayType()) return SValuator::CastResult(state, RetrieveArray(state, R)); @@ -1109,7 +1130,7 @@ SVal RegionStoreManager::RetrieveField(const GRState* state, const MemRegion* superR = R->getSuperRegion(); while (superR) { - if (const SVal* D = state->get(superR)) { + if (const Optional &D = getDefaultBinding(state, superR)) { if (SymbolRef parentSym = D->getAsSymbol()) return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); -- cgit v1.2.3