diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-08-06 21:43:54 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-08-06 21:43:54 +0000 |
commit | d4e5a606c9c64e24c05e5f4610796087e911fb9c (patch) | |
tree | fd0c4cbe1d96b37cbc059684d11f0d51fd2af036 /lib/Analysis/RegionStore.cpp | |
parent | 470c2a9ab6807be8a695e583a41b20ed69082260 (diff) |
Fix a couple false positive "uninitialized value" warnings with RegionStore
involving reasoning about unions (which we don't handle yet).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 3216756045..8cb4d98021 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/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<SVal> 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<SVal> RegionStoreManager::getDefaultBinding(const GRState *state, + const MemRegion *R) { + + if (R->isBoundable()) + if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) + if (TR->getValueType(getContext())->isUnionType()) + return UnknownVal(); + + return Optional<SVal>::create(state->get<RegionDefaultValue>(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<RegionDefaultValue>(superR)) { + if (const Optional<SVal> &D = getDefaultBinding(state, superR)) { if (SymbolRef parentSym = D->getAsSymbol()) return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |