From 3ed6fc08a9cd293d012fa49ab2a615e618d7c3fa Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Feb 2011 01:51:48 +0000 Subject: [PATCH] Issue AnalysisBasedWarnings as part of calling Sema::PopBlockOrFunctionScope(). No real functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126287 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/AnalysisBasedWarnings.h | 7 ++---- include/clang/Sema/Sema.h | 3 ++- lib/Sema/AnalysisBasedWarnings.cpp | 27 ++++------------------ lib/Sema/Sema.cpp | 10 ++++++-- lib/Sema/SemaDecl.cpp | 11 +++------ lib/Sema/SemaExpr.cpp | 8 ++----- 6 files changed, 21 insertions(+), 45 deletions(-) diff --git a/include/clang/Sema/AnalysisBasedWarnings.h b/include/clang/Sema/AnalysisBasedWarnings.h index 0a6656e97e..192be4db2f 100644 --- a/include/clang/Sema/AnalysisBasedWarnings.h +++ b/include/clang/Sema/AnalysisBasedWarnings.h @@ -47,16 +47,13 @@ private: enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 }; llvm::DenseMap VisitedFD; - void IssueWarnings(Policy P, const Decl *D, QualType BlockTy); public: AnalysisBasedWarnings(Sema &s); - Policy getDefaultPolicy() { return DefaultPolicy; } + void IssueWarnings(Policy P, const Decl *D, const BlockExpr *blkExpr); - void IssueWarnings(Policy P, const BlockExpr *E); - void IssueWarnings(Policy P, const FunctionDecl *D); - void IssueWarnings(Policy P, const ObjCMethodDecl *D); + Policy getDefaultPolicy() { return DefaultPolicy; } }; }} // end namespace clang::sema diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 835e8d3e68..9e46c2c49a 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -688,7 +688,8 @@ public: void PushFunctionScope(); void PushBlockScope(Scope *BlockScope, BlockDecl *Block); - void PopFunctionOrBlockScope(); + void PopFunctionOrBlockScope(const sema::AnalysisBasedWarnings::Policy *WP =0, + const Decl *D = 0, const BlockExpr *blkExpr = 0); sema::FunctionScopeInfo *getCurFunction() const { return FunctionScopes.back(); diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 63f561d6ab..7a1aceb4c6 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -289,7 +289,7 @@ struct CheckFallThroughDiagnostics { /// of a noreturn function. We assume that functions and blocks not marked /// noreturn will return. static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body, - QualType BlockTy, + const BlockExpr *blkExpr, const CheckFallThroughDiagnostics& CD, AnalysisContext &AC) { @@ -306,6 +306,7 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body, HasNoReturn = MD->hasAttr(); } else if (isa(D)) { + QualType BlockTy = blkExpr->getType(); if (const FunctionType *FT = BlockTy->getPointeeType()->getAs()) { if (FT->getResultType()->isVoidType()) @@ -479,9 +480,7 @@ clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s) : S(s) { void clang::sema:: AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, - const Decl *D, QualType BlockTy) { - - assert(BlockTy.isNull() || isa(D)); + const Decl *D, const BlockExpr *blkExpr) { // We avoid doing analysis-based warnings when there are errors for // two reasons: @@ -517,7 +516,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, const CheckFallThroughDiagnostics &CD = (isa(D) ? CheckFallThroughDiagnostics::MakeForBlock() : CheckFallThroughDiagnostics::MakeForFunction(D)); - CheckFallThroughForBody(S, D, Body, BlockTy, CD, AC); + CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC); } // Warning: check for unreachable code @@ -550,21 +549,3 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, } } } - -void clang::sema:: -AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, - const BlockExpr *E) { - return IssueWarnings(P, E->getBlockDecl(), E->getType()); -} - -void clang::sema:: -AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, - const ObjCMethodDecl *D) { - return IssueWarnings(P, D, QualType()); -} - -void clang::sema:: -AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, - const FunctionDecl *D) { - return IssueWarnings(P, D, QualType()); -} diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 78d49b7415..1920f1e6fc 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -631,9 +631,15 @@ void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) { BlockScope, Block)); } -void Sema::PopFunctionOrBlockScope() { - FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); +void Sema::PopFunctionOrBlockScope(const AnalysisBasedWarnings::Policy *WP, + const Decl *D, const BlockExpr *blkExpr) { + FunctionScopeInfo *Scope = FunctionScopes.pop_back_val(); assert(!FunctionScopes.empty() && "mismatched push/pop!"); + + // Issue any analysis-based warnings. + if (WP && D) + AnalysisWarnings.IssueWarnings(*WP, D, blkExpr); + if (FunctionScopes.back() != Scope) delete Scope; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c57efe32bc..75e7c6f2d9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -5552,6 +5552,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, FD = dyn_cast_or_null(dcl); sema::AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy(); + sema::AnalysisBasedWarnings::Policy *ActivePolicy = 0; if (FD) { FD->setBody(Body); @@ -5620,13 +5621,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, else if (!isa(dcl)) { // Since the body is valid, issue any analysis-based warnings that are // enabled. - QualType ResultType; - if (const FunctionDecl *FD = dyn_cast(dcl)) { - AnalysisWarnings.IssueWarnings(WP, FD); - } else { - ObjCMethodDecl *MD = cast(dcl); - AnalysisWarnings.IssueWarnings(WP, MD); - } + ActivePolicy = ℘ } assert(ExprTemporaries.empty() && "Leftover temporaries in function"); @@ -5635,7 +5630,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, if (!IsInstantiation) PopDeclContext(); - PopFunctionOrBlockScope(); + PopFunctionOrBlockScope(ActivePolicy, dcl); // If any errors have occurred, clear out any temporaries that may have // been leftover. This ensures that these temporaries won't be picked up for diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7f6ebd7fa9..ac747910dc 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8890,12 +8890,8 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, BlockExpr *Result = new (Context) BlockExpr(BSI->TheDecl, BlockTy); - // Issue any analysis-based warnings. - const sema::AnalysisBasedWarnings::Policy &WP = - AnalysisWarnings.getDefaultPolicy(); - AnalysisWarnings.IssueWarnings(WP, Result); - - PopFunctionOrBlockScope(); + const AnalysisBasedWarnings::Policy &WP = AnalysisWarnings.getDefaultPolicy(); + PopFunctionOrBlockScope(&WP, Result->getBlockDecl(), Result); return Owned(Result); } -- 2.40.0