diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2019-01-29 10:27:14 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2019-01-29 10:27:14 +0000 |
commit | f41e3d087344c1eeac25918c99a6a72c746df533 (patch) | |
tree | 2b2a996c0e1390466a72c62ffbb14a3522278094 /clang/lib | |
parent | 5c33c5da1ada960f3de0323967bd5df777a02eb9 (diff) | |
download | bcm5719-llvm-f41e3d087344c1eeac25918c99a6a72c746df533.tar.gz bcm5719-llvm-f41e3d087344c1eeac25918c99a6a72c746df533.zip |
[analyzer] Toning down invalidation a bit
When a function takes the address of a field the analyzer will no longer
assume that the function will change other fields of the enclosing structs.
Differential Revision: https://reviews.llvm.org/D57230
llvm-svn: 352473
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 11dda7c3acb..8dc6646e0eb 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -303,11 +303,23 @@ ProgramStateRef CallEvent::invalidateRegions(unsigned BlockCount, for (unsigned Idx = 0, Count = getNumArgs(); Idx != Count; ++Idx) { // Mark this region for invalidation. We batch invalidate regions // below for efficiency. - if (PreserveArgs.count(Idx)) - if (const MemRegion *MR = getArgSVal(Idx).getAsRegion()) - ETraits.setTrait(MR->getBaseRegion(), - RegionAndSymbolInvalidationTraits::TK_PreserveContents); - // TODO: Factor this out + handle the lower level const pointers. + if (const MemRegion *MR = getArgSVal(Idx).getAsRegion()) { + bool UseBaseRegion = true; + if (const auto *FR = MR->getAs<FieldRegion>()) { + if (const auto *TVR = FR->getSuperRegion()->getAs<TypedValueRegion>()) { + if (!TVR->getValueType()->isUnionType()) { + ETraits.setTrait(MR, RegionAndSymbolInvalidationTraits:: + TK_DoNotInvalidateSuperRegion); + UseBaseRegion = false; + } + } + } + // todo: factor this out + handle the lower level const pointers. + if (PreserveArgs.count(Idx)) + ETraits.setTrait( + UseBaseRegion ? MR->getBaseRegion() : MR, + RegionAndSymbolInvalidationTraits::TK_PreserveContents); + } ValuesToInvalidate.push_back(getArgSVal(Idx)); |