diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-12-20 19:36:06 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-12-20 19:36:06 +0000 |
commit | fa2b3e0b28771f4c8f6793b62b0630c6f39bcfe1 (patch) | |
tree | a70e01566aca3f3fc59140897f84d3a534858f50 /lib/StaticAnalyzer/Core/Store.cpp | |
parent | b27c4ef981e042f2003c16c2f2d7700a6a4a6c00 (diff) | |
download | clang-fa2b3e0b28771f4c8f6793b62b0630c6f39bcfe1.tar.gz |
Revert "[analyzer] pr38668: Do not attempt to cast loaded values..."
This reverts commit r349701.
The patch was incorrect. The whole point of CastRetrievedVal()
is to handle the case in which the type from which the cast is made
(i.e., the "type" of value `V`) has nothing to do with the type of
the region it was loaded from (i.e., `R->getValueType()`).
Differential Revision: https://reviews.llvm.org/D55875
rdar://problem/45062567
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/Store.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/Store.cpp | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/lib/StaticAnalyzer/Core/Store.cpp b/lib/StaticAnalyzer/Core/Store.cpp index ac9cb4bc42..794fd84364 100644 --- a/lib/StaticAnalyzer/Core/Store.cpp +++ b/lib/StaticAnalyzer/Core/Store.cpp @@ -394,28 +394,14 @@ SVal StoreManager::attemptDownCast(SVal Base, QualType TargetType, return UnknownVal(); } -static bool isScalarEnoughToAttemptACast(QualType T) { - return T->isIntegralOrEnumerationType() || T->isAnyPointerType() || - T->isReferenceType(); -} - /// CastRetrievedVal - Used by subclasses of StoreManager to implement /// implicit casts that arise from loads from regions that are reinterpreted /// as another region. SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R, - QualType CastTy) { - if (CastTy.isNull() || V.isUnknownOrUndef()) + QualType castTy) { + if (castTy.isNull() || V.isUnknownOrUndef()) return V; - QualType OrigTy = R->getValueType(); - - if (!isScalarEnoughToAttemptACast(OrigTy) || - !isScalarEnoughToAttemptACast(CastTy)) { - if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType()) - return V; - return UnknownVal(); - } - // When retrieving symbolic pointer and expecting a non-void pointer, // wrap them into element regions of the expected type if necessary. // SValBuilder::dispatchCast() doesn't do that, but it is necessary to @@ -424,13 +410,13 @@ SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R, // We might need to do that for non-void pointers as well. // FIXME: We really need a single good function to perform casts for us // correctly every time we need it. - if (CastTy->isPointerType() && !CastTy->isVoidPointerType()) + if (castTy->isPointerType() && !castTy->isVoidPointerType()) if (const auto *SR = dyn_cast_or_null<SymbolicRegion>(V.getAsRegion())) if (SR->getSymbol()->getType().getCanonicalType() != - CastTy.getCanonicalType()) - return loc::MemRegionVal(castRegion(SR, CastTy)); + castTy.getCanonicalType()) + return loc::MemRegionVal(castRegion(SR, castTy)); - return svalBuilder.dispatchCast(V, CastTy); + return svalBuilder.dispatchCast(V, castTy); } SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) { |