diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-02-15 20:51:59 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-02-15 20:51:59 +0000 |
commit | 86ced61713098b13d58f24f4dfd0806dddaeb20c (patch) | |
tree | a39453c98d7700e8c9b460b06b8cf46c79dc7e6a /lib | |
parent | 155bc5fa0d90f001ac6d4242b72fddd9d6017f71 (diff) |
Merging r295150:
------------------------------------------------------------------------
r295150 | ahatanak | 2017-02-14 21:15:28 -0800 (Tue, 14 Feb 2017) | 13 lines
[Sema] Disallow returning a __block variable via a move.
r274291 made changes to prefer calling a move constructor to calling a
copy constructor when returning from a function. This caused programs to
crash when a __block variable in the heap was moved out and used later.
This commit fixes the bug by disallowing moving out of __block variables
implicitly.
rdar://problem/28181080
Differential Revision: https://reviews.llvm.org/D29908
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@295234 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a8832e9a1c..390e1b52c8 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2743,15 +2743,17 @@ bool Sema::isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, // ...automatic... if (!VD->hasLocalStorage()) return false; + // Return false if VD is a __block variable. We don't want to implicitly move + // out of a __block variable during a return because we cannot assume the + // variable will no longer be used. + if (VD->hasAttr<BlocksAttr>()) return false; + if (AllowParamOrMoveConstructible) return true; // ...non-volatile... if (VD->getType().isVolatileQualified()) return false; - // __block variables can't be allocated in a way that permits NRVO. - if (VD->hasAttr<BlocksAttr>()) return false; - // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. if (!VD->getType()->isDependentType() && VD->hasAttr<AlignedAttr>() && |