summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/LoopWidening.cpp
diff options
context:
space:
mode:
authorHenry Wong <movietravelcode@outlook.com>2018-04-15 10:34:06 +0000
committerHenry Wong <movietravelcode@outlook.com>2018-04-15 10:34:06 +0000
commit525d4122c9ed09f50dee8683a14f4700cf5eb130 (patch)
treed95a7c812eef453c2978a3612a947ca9d1d4d3c1 /clang/lib/StaticAnalyzer/Core/LoopWidening.cpp
parent6be1f01935f23d92c967024ee718a7f48748283c (diff)
downloadbcm5719-llvm-525d4122c9ed09f50dee8683a14f4700cf5eb130.tar.gz
bcm5719-llvm-525d4122c9ed09f50dee8683a14f4700cf5eb130.zip
[analyzer] Do not invalidate the `this` pointer.
Summary: `this` pointer is not an l-value, although we have modeled `CXXThisRegion` for `this` pointer, we can only bind it once, which is when we start to inline method. And this patch fixes https://bugs.llvm.org/show_bug.cgi?id=35506. In addition, I didn't find any other cases other than loop-widen that could invalidate `this` pointer. Reviewers: NoQ, george.karpenkov, a.sidorin, seaneveson, szepet Reviewed By: NoQ Subscribers: xazax.hun, rnkovacs, cfe-commits, MTC Differential Revision: https://reviews.llvm.org/D45491 llvm-svn: 330095
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/LoopWidening.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/LoopWidening.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/LoopWidening.cpp b/clang/lib/StaticAnalyzer/Core/LoopWidening.cpp
index 05865c294cb..a609aa96d77 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -59,6 +59,18 @@ ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
ITraits.setTrait(Region,
RegionAndSymbolInvalidationTraits::TK_EntireMemSpace);
}
+
+ // 'this' pointer is not an lvalue, we should not invalidate it. If the loop
+ // is located in a method, constructor or destructor, the value of 'this'
+ // pointer shoule remain unchanged.
+ if (const CXXMethodDecl *CXXMD = dyn_cast<CXXMethodDecl>(STC->getDecl())) {
+ const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
+ CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
+ STC);
+ ITraits.setTrait(ThisR,
+ RegionAndSymbolInvalidationTraits::TK_PreserveContents);
+ }
+
return PrevState->invalidateRegions(Regions, getLoopCondition(LoopStmt),
BlockCount, LCtx, true, nullptr, nullptr,
&ITraits);
OpenPOWER on IntegriCloud