diff options
| author | Akira Hatanaka <ahatanaka@apple.com> | 2018-10-01 20:29:34 +0000 |
|---|---|---|
| committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-10-01 20:29:34 +0000 |
| commit | 31974847014eaad83ed15d3f385e3f761f7cfe4a (patch) | |
| tree | 314b7fb6684ec4fe863bfc1c224f6977dd7f3d45 /clang/lib/Sema | |
| parent | 97e0f52642565e843decca34894834787515e251 (diff) | |
| download | bcm5719-llvm-31974847014eaad83ed15d3f385e3f761f7cfe4a.tar.gz bcm5719-llvm-31974847014eaad83ed15d3f385e3f761f7cfe4a.zip | |
Revert r343518.
Bots are still failing.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/24420
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/12958
llvm-svn: 343531
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/ScopeInfo.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.cpp | 59 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 33 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 3 |
4 files changed, 31 insertions, 66 deletions
diff --git a/clang/lib/Sema/ScopeInfo.cpp b/clang/lib/Sema/ScopeInfo.cpp index bd8db6f4ed9..62a83ccb70a 100644 --- a/clang/lib/Sema/ScopeInfo.cpp +++ b/clang/lib/Sema/ScopeInfo.cpp @@ -54,8 +54,6 @@ void FunctionScopeInfo::Clear() { PossiblyUnreachableDiags.clear(); WeakObjectUses.clear(); ModifiedNonNullParams.clear(); - Blocks.clear(); - ByrefBlockVars.clear(); } static const NamedDecl *getBestPropertyDecl(const ObjCPropertyRefExpr *PropE) { diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index ccbbe50093b..d777afe9811 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1401,68 +1401,9 @@ void Sema::RecordParsingTemplateParameterDepth(unsigned Depth) { "Remove assertion if intentionally called in a non-lambda context."); } -// Check that the type of the VarDecl has an accessible copy constructor and -// resolve its destructor's exception spefication. -static void checkEscapingByref(VarDecl *VD, Sema &S) { - QualType T = VD->getType(); - EnterExpressionEvaluationContext scope( - S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); - SourceLocation Loc = VD->getLocation(); - Expr *VarRef = new (S.Context) DeclRefExpr(VD, false, T, VK_LValue, Loc); - ExprResult Result = S.PerformMoveOrCopyInitialization( - InitializedEntity::InitializeBlock(Loc, T, false), VD, VD->getType(), - VarRef, /*AllowNRVO=*/true); - if (!Result.isInvalid()) { - Result = S.MaybeCreateExprWithCleanups(Result); - Expr *Init = Result.getAs<Expr>(); - S.Context.setBlockVarCopyInit(VD, Init, S.canThrow(Init)); - } - - // The destructor's exception spefication is needed when IRGen generates - // block copy/destroy functions. Resolve it here. - if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl()) - if (CXXDestructorDecl *DD = RD->getDestructor()) { - auto *FPT = DD->getType()->getAs<FunctionProtoType>(); - S.ResolveExceptionSpec(Loc, FPT); - } -} - -static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) { - // Set the EscapingByref flag of __block variables captured by - // escaping blocks. - for (const BlockDecl *BD : FSI.Blocks) { - if (BD->doesNotEscape()) - continue; - for (const BlockDecl::Capture &BC : BD->captures()) { - VarDecl *VD = BC.getVariable(); - if (VD->hasAttr<BlocksAttr>()) - VD->setEscapingByref(); - } - } - - for (VarDecl *VD : FSI.ByrefBlockVars) { - // __block variables might require us to capture a copy-initializer. - if (!VD->isEscapingByref()) - continue; - // It's currently invalid to ever have a __block variable with an - // array type; should we diagnose that here? - // Regardless, we don't want to ignore array nesting when - // constructing this copy. - if (VD->getType()->isStructureOrClassType()) - checkEscapingByref(VD, S); - } -} - void Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, const Decl *D, const BlockExpr *blkExpr) { assert(!FunctionScopes.empty() && "mismatched push/pop!"); - - // This function shouldn't be called after popping the current function scope. - // markEscapingByrefs calls PerformMoveOrCopyInitialization, which can call - // PushFunctionScope, which can cause clearing out PreallocatedFunctionScope - // when FunctionScopes is empty. - markEscapingByrefs(*FunctionScopes.back(), *this); - FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); if (LangOpts.OpenMP) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 441c54dc358..f5ba87f635d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11826,8 +11826,37 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { QualType type = var->getType(); if (type->isDependentType()) return; - if (var->hasAttr<BlocksAttr>()) - getCurFunction()->addByrefBlockVar(var); + // __block variables might require us to capture a copy-initializer. + if (var->hasAttr<BlocksAttr>()) { + // It's currently invalid to ever have a __block variable with an + // array type; should we diagnose that here? + + // Regardless, we don't want to ignore array nesting when + // constructing this copy. + if (type->isStructureOrClassType()) { + EnterExpressionEvaluationContext scope( + *this, ExpressionEvaluationContext::PotentiallyEvaluated); + SourceLocation poi = var->getLocation(); + Expr *varRef =new (Context) DeclRefExpr(var, false, type, VK_LValue, poi); + ExprResult result + = PerformMoveOrCopyInitialization( + InitializedEntity::InitializeBlock(poi, type, false), + var, var->getType(), varRef, /*AllowNRVO=*/true); + if (!result.isInvalid()) { + result = MaybeCreateExprWithCleanups(result); + Expr *init = result.getAs<Expr>(); + Context.setBlockVarCopyInit(var, init, canThrow(init)); + } + + // The destructor's exception spefication is needed when IRGen generates + // block copy/destroy functions. Resolve it here. + if (const CXXRecordDecl *RD = type->getAsCXXRecordDecl()) + if (CXXDestructorDecl *DD = RD->getDestructor()) { + auto *FPT = DD->getType()->getAs<FunctionProtoType>(); + FPT = ResolveExceptionSpec(poi, FPT); + } + } + } Expr *Init = var->getInit(); bool IsGlobal = GlobalStorage && !var->isStaticLocal(); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5b5b8220bfc..26fb107688f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13530,9 +13530,6 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, } } - if (getCurFunction()) - getCurFunction()->addBlock(BSI->TheDecl); - return Result; } |

