diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-08-29 01:11:59 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-08-29 01:11:59 +0000 |
commit | 73212dff6437d409e0c1b779fdcac2f4f98ca8b0 (patch) | |
tree | ad0323fde92f022b1ca9bd2346c8c6c7f3c7ee5b /lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp | |
parent | 8a64bb58c3b24d7d97895e435bbc0965c99bd3be (diff) |
[analyzer] C++ objects returned on the stack may be wrapped in ExprWithCleanups.
In C++, objects being returned on the stack are actually copy-constructed into
the return value. That means that when a temporary is returned, it still has
to be destroyed, i.e. the returned expression will be wrapped in an
ExprWithCleanups node. Our "returning stack memory" checker needs to look
through this node to see if we really are returning an object by value.
PR13722
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index b1f4f623e2..6a4b2d9ef8 100644 --- a/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -118,6 +118,7 @@ void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS, const Expr *RetE = RS->getRetValue(); if (!RetE) return; + RetE = RetE->IgnoreParens(); const LocationContext *LCtx = C.getLocationContext(); SVal V = C.getState()->getSVal(RetE, LCtx); @@ -144,7 +145,10 @@ void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS, return; // Returning a record by value is fine. (In this case, the returned - // expression will be a copy-constructor.) + // expression will be a copy-constructor, possibly wrapped in an + // ExprWithCleanups node.) + if (const ExprWithCleanups *Cleanup = dyn_cast<ExprWithCleanups>(RetE)) + RetE = Cleanup->getSubExpr(); if (isa<CXXConstructExpr>(RetE) && RetE->getType()->isRecordType()) return; |