diff options
author | Reid Kleckner <rnk@google.com> | 2018-03-08 01:12:22 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-03-08 01:12:22 +0000 |
commit | 8d485b845b1dc8cdd78c7c4028be94f2abadbf50 (patch) | |
tree | dfa1abc2972cd5ff48b111643d9142a9cad62869 /clang/lib/Sema/Sema.cpp | |
parent | 5d3310208ae811396ca0cf256f96d4234ce5ae75 (diff) | |
download | bcm5719-llvm-8d485b845b1dc8cdd78c7c4028be94f2abadbf50.tar.gz bcm5719-llvm-8d485b845b1dc8cdd78c7c4028be94f2abadbf50.zip |
Revert "[Sema] Make getCurFunction() return null outside function parsing"
This reverts r326965. It seems to have caused repeating test failures in
clang/test/Sema/diagnose_if.c on some buildbots.
I cannot reproduce the problem, and it's not immediately obvious what
the problem is, so let's revert to green.
llvm-svn: 326974
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index c61e2fdcab2..d0ed6bf75f3 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -162,7 +162,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, ExpressionEvaluationContext::PotentiallyEvaluated, 0, CleanupInfo{}, nullptr, false); - PreallocatedFunctionScope.reset(new FunctionScopeInfo(Diags)); + FunctionScopes.push_back(new FunctionScopeInfo(Diags)); // Initilization of data sharing attributes stack for OpenMP InitDataSharingAttributesStack(); @@ -332,11 +332,11 @@ void Sema::Initialize() { Sema::~Sema() { if (VisContext) FreeVisContext(); - // Kill all the active scopes. - for (sema::FunctionScopeInfo *FSI : FunctionScopes) - if (FSI != PreallocatedFunctionScope.get()) - delete FSI; + for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) + delete FunctionScopes[I]; + if (FunctionScopes.size() == 1) + delete FunctionScopes[0]; // Tell the SemaConsumer to forget about us; we're going out of scope. if (SemaConsumer *SC = dyn_cast<SemaConsumer>(&Consumer)) @@ -1340,13 +1340,17 @@ Scope *Sema::getScopeForContext(DeclContext *Ctx) { /// \brief Enter a new function scope void Sema::PushFunctionScope() { - if (FunctionScopes.empty()) { - // Use PreallocatedFunctionScope to avoid allocating memory when possible. - PreallocatedFunctionScope->Clear(); - FunctionScopes.push_back(PreallocatedFunctionScope.get()); - } else { - FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics())); + if (FunctionScopes.size() == 1) { + // Use the "top" function scope rather than having to allocate + // memory for a new scope. + FunctionScopes.back()->Clear(); + FunctionScopes.push_back(FunctionScopes.back()); + if (LangOpts.OpenMP) + pushOpenMPFunctionRegion(); + return; } + + FunctionScopes.push_back(new FunctionScopeInfo(getDiagnostics())); if (LangOpts.OpenMP) pushOpenMPFunctionRegion(); } @@ -1366,15 +1370,15 @@ void Sema::RecordParsingTemplateParameterDepth(unsigned Depth) { if (LambdaScopeInfo *const LSI = getCurLambda()) { LSI->AutoTemplateParameterDepth = Depth; return; - } - llvm_unreachable( + } + llvm_unreachable( "Remove assertion if intentionally called in a non-lambda context."); } void Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, const Decl *D, const BlockExpr *blkExpr) { - assert(!FunctionScopes.empty() && "mismatched push/pop!"); FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); + assert(!FunctionScopes.empty() && "mismatched push/pop!"); if (LangOpts.OpenMP) popOpenMPFunctionRegion(Scope); @@ -1386,8 +1390,7 @@ void Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, for (const auto &PUD : Scope->PossiblyUnreachableDiags) Diag(PUD.Loc, PUD.PD); - // Delete the scope unless its our preallocated scope. - if (Scope != PreallocatedFunctionScope.get()) + if (FunctionScopes.back() != Scope) delete Scope; } @@ -1408,21 +1411,6 @@ bool Sema::hasAnyUnrecoverableErrorsInThisFunction() const { return getCurFunction()->ErrorTrap.hasUnrecoverableErrorOccurred(); } -void Sema::setFunctionHasBranchIntoScope() { - if (!FunctionScopes.empty()) - FunctionScopes.back()->setHasBranchIntoScope(); -} - -void Sema::setFunctionHasBranchProtectedScope() { - if (!FunctionScopes.empty()) - FunctionScopes.back()->setHasBranchProtectedScope(); -} - -void Sema::setFunctionHasIndirectGoto() { - if (!FunctionScopes.empty()) - FunctionScopes.back()->setHasIndirectGoto(); -} - BlockScopeInfo *Sema::getCurBlock() { if (FunctionScopes.empty()) return nullptr; |