diff options
author | Pavel Labath <labath@google.com> | 2013-07-26 11:50:42 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2013-07-26 11:50:42 +0000 |
commit | cf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6 (patch) | |
tree | f00c5294fa6452b542d3d8caf1f33ade145f5183 /clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | |
parent | 240d480c5f6ae6cbfe40bfb40d83164008a99b09 (diff) | |
download | bcm5719-llvm-cf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6.tar.gz bcm5719-llvm-cf878bbe65b9f4b4b5ca96f5f6f33f8ff31349d6.zip |
[analyzer] Fix FP warnings when binding a temporary to a local static variable
Summary:
When binding a temporary object to a static local variable, the analyzer would
complain about a dangling reference even though the temporary's lifetime should
be extended past the end of the function. This commit tries to detect these
cases and construct them in a global memory region instead of a local one.
Reviewers: jordan_rose
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1133
llvm-svn: 187196
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ExprEngine.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 04629dc0170..552b2eca26e 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -209,7 +209,18 @@ ExprEngine::createTemporaryRegionIfNeeded(ProgramStateRef State, // Create a temporary object region for the inner expression (which may have // a more derived type) and bind the value into it. - const TypedValueRegion *TR = MRMgr.getCXXTempObjectRegion(Inner, LC); + const TypedValueRegion *TR = NULL; + if (const MaterializeTemporaryExpr *MT = + dyn_cast<MaterializeTemporaryExpr>(Result)) { + StorageDuration SD = MT->getStorageDuration(); + // If this object is bound to a reference with static storage duration, we + // put it in a different region to prevent "address leakage" warnings. + if (SD == SD_Static || SD == SD_Thread) + TR = MRMgr.getCXXStaticTempObjectRegion(Inner); + } + if (!TR) + TR = MRMgr.getCXXTempObjectRegion(Inner, LC); + SVal Reg = loc::MemRegionVal(TR); if (V.isUnknown()) |