]> granicus.if.org Git - clang/commitdiff
Issue AnalysisBasedWarnings as part of calling Sema::PopBlockOrFunctionScope(). ...
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 01:51:48 +0000 (01:51 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Feb 2011 01:51:48 +0000 (01:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126287 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/AnalysisBasedWarnings.h
include/clang/Sema/Sema.h
lib/Sema/AnalysisBasedWarnings.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp

index 0a6656e97e1bf2fc5fd50d8b3e6f08c52c381009..192be4db2f6e21f4ba9718c1cc72014ea1df5d77 100644 (file)
@@ -47,16 +47,13 @@ private:
   enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
   llvm::DenseMap<const FunctionDecl*, VisitFlag> 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
index 835e8d3e6857bfd35a9dd7e05abccb47ba91ccf6..9e46c2c49a7eabbcce65d9867eddf1f2135ae00b 100644 (file)
@@ -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();
index 63f561d6ab190ce3c0e7c393f9b8549ebee1deb6..7a1aceb4c686c0deb034431cd8e0753b32554620 100644 (file)
@@ -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<NoReturnAttr>();
   }
   else if (isa<BlockDecl>(D)) {
+    QualType BlockTy = blkExpr->getType();
     if (const FunctionType *FT =
           BlockTy->getPointeeType()->getAs<FunctionType>()) {
       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<BlockDecl>(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<BlockDecl>(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());
-}
index 78d49b74158245acfdad060235a551514ba690ad..1920f1e6fc8fd426942c6f7e237b1a8a02e404f1 100644 (file)
@@ -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;
 }
index c57efe32bc32d8779825f607ce0149d955cbf657..75e7c6f2d9c77ce69e397389811ef40016917f06 100644 (file)
@@ -5552,6 +5552,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
     FD = dyn_cast_or_null<FunctionDecl>(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<FunctionTemplateDecl>(dcl)) {
       // Since the body is valid, issue any analysis-based warnings that are
       // enabled.
-      QualType ResultType;
-      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(dcl)) {
-        AnalysisWarnings.IssueWarnings(WP, FD);
-      } else {
-        ObjCMethodDecl *MD = cast<ObjCMethodDecl>(dcl);
-        AnalysisWarnings.IssueWarnings(WP, MD);
-      }
+      ActivePolicy = &WP;
     }
 
     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
index 7f6ebd7fa9dc84ec3d0da920d781e4068e75d80b..ac747910dc747dfdff0dd5e841eca7fb67c54aa2 100644 (file)
@@ -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);
 }