clang API Documentation

AnalysisBasedWarnings.h
Go to the documentation of this file.
00001 //=- AnalysisBasedWarnings.h - Sema warnings based on libAnalysis -*- C++ -*-=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines AnalysisBasedWarnings, a worker object used by Sema
00011 // that issues warnings based on dataflow-analysis.
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
00015 #define LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
00016 
00017 #include "llvm/ADT/DenseMap.h"
00018 
00019 namespace clang {
00020 
00021 class BlockExpr;
00022 class Decl;
00023 class FunctionDecl;
00024 class ObjCMethodDecl;
00025 class QualType;
00026 class Sema;
00027 namespace sema {
00028   class FunctionScopeInfo;
00029 }
00030 
00031 namespace sema {
00032 
00033 class AnalysisBasedWarnings {
00034 public:
00035   class Policy {
00036     friend class AnalysisBasedWarnings;
00037     // The warnings to run.
00038     unsigned enableCheckFallThrough : 1;
00039     unsigned enableCheckUnreachable : 1;
00040     unsigned enableThreadSafetyAnalysis : 1;
00041     unsigned enableConsumedAnalysis : 1;
00042   public:
00043     Policy();
00044     void disableCheckFallThrough() { enableCheckFallThrough = 0; }
00045   };
00046 
00047 private:
00048   Sema &S;
00049   Policy DefaultPolicy;
00050 
00051   enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
00052   llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
00053 
00054   /// \name Statistics
00055   /// @{
00056 
00057   /// \brief Number of function CFGs built and analyzed.
00058   unsigned NumFunctionsAnalyzed;
00059 
00060   /// \brief Number of functions for which the CFG could not be successfully
00061   /// built.
00062   unsigned NumFunctionsWithBadCFGs;
00063 
00064   /// \brief Total number of blocks across all CFGs.
00065   unsigned NumCFGBlocks;
00066 
00067   /// \brief Largest number of CFG blocks for a single function analyzed.
00068   unsigned MaxCFGBlocksPerFunction;
00069 
00070   /// \brief Total number of CFGs with variables analyzed for uninitialized
00071   /// uses.
00072   unsigned NumUninitAnalysisFunctions;
00073 
00074   /// \brief Total number of variables analyzed for uninitialized uses.
00075   unsigned NumUninitAnalysisVariables;
00076 
00077   /// \brief Max number of variables analyzed for uninitialized uses in a single
00078   /// function.
00079   unsigned MaxUninitAnalysisVariablesPerFunction;
00080 
00081   /// \brief Total number of block visits during uninitialized use analysis.
00082   unsigned NumUninitAnalysisBlockVisits;
00083 
00084   /// \brief Max number of block visits during uninitialized use analysis of
00085   /// a single function.
00086   unsigned MaxUninitAnalysisBlockVisitsPerFunction;
00087 
00088   /// @}
00089 
00090 public:
00091   AnalysisBasedWarnings(Sema &s);
00092 
00093   void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
00094                      const Decl *D, const BlockExpr *blkExpr);
00095 
00096   Policy getDefaultPolicy() { return DefaultPolicy; }
00097 
00098   void PrintStats() const;
00099 };
00100 
00101 }} // end namespace clang::sema
00102 
00103 #endif