Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:59

0001 //=- AnalysisBasedWarnings.h - Sema warnings based on libAnalysis -*- C++ -*-=//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines AnalysisBasedWarnings, a worker object used by Sema
0010 // that issues warnings based on dataflow-analysis.
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
0014 #define LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
0015 
0016 #include "clang/AST/Decl.h"
0017 #include "llvm/ADT/DenseMap.h"
0018 #include <memory>
0019 
0020 namespace clang {
0021 
0022 class Decl;
0023 class FunctionDecl;
0024 class QualType;
0025 class Sema;
0026 namespace sema {
0027   class FunctionScopeInfo;
0028 }
0029 
0030 namespace sema {
0031 
0032 class AnalysisBasedWarnings {
0033 public:
0034   class Policy {
0035     friend class AnalysisBasedWarnings;
0036     // The warnings to run.
0037     LLVM_PREFERRED_TYPE(bool)
0038     unsigned enableCheckFallThrough : 1;
0039     LLVM_PREFERRED_TYPE(bool)
0040     unsigned enableCheckUnreachable : 1;
0041     LLVM_PREFERRED_TYPE(bool)
0042     unsigned enableThreadSafetyAnalysis : 1;
0043     LLVM_PREFERRED_TYPE(bool)
0044     unsigned enableConsumedAnalysis : 1;
0045   public:
0046     Policy();
0047     void disableCheckFallThrough() { enableCheckFallThrough = 0; }
0048   };
0049 
0050 private:
0051   Sema &S;
0052   Policy DefaultPolicy;
0053 
0054   class InterProceduralData;
0055   std::unique_ptr<InterProceduralData> IPData;
0056 
0057   enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
0058   llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
0059 
0060   /// \name Statistics
0061   /// @{
0062 
0063   /// Number of function CFGs built and analyzed.
0064   unsigned NumFunctionsAnalyzed;
0065 
0066   /// Number of functions for which the CFG could not be successfully
0067   /// built.
0068   unsigned NumFunctionsWithBadCFGs;
0069 
0070   /// Total number of blocks across all CFGs.
0071   unsigned NumCFGBlocks;
0072 
0073   /// Largest number of CFG blocks for a single function analyzed.
0074   unsigned MaxCFGBlocksPerFunction;
0075 
0076   /// Total number of CFGs with variables analyzed for uninitialized
0077   /// uses.
0078   unsigned NumUninitAnalysisFunctions;
0079 
0080   /// Total number of variables analyzed for uninitialized uses.
0081   unsigned NumUninitAnalysisVariables;
0082 
0083   /// Max number of variables analyzed for uninitialized uses in a single
0084   /// function.
0085   unsigned MaxUninitAnalysisVariablesPerFunction;
0086 
0087   /// Total number of block visits during uninitialized use analysis.
0088   unsigned NumUninitAnalysisBlockVisits;
0089 
0090   /// Max number of block visits during uninitialized use analysis of
0091   /// a single function.
0092   unsigned MaxUninitAnalysisBlockVisitsPerFunction;
0093 
0094   /// @}
0095 
0096 public:
0097   AnalysisBasedWarnings(Sema &s);
0098   ~AnalysisBasedWarnings();
0099 
0100   void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
0101                      const Decl *D, QualType BlockType);
0102 
0103   // Issue warnings that require whole-translation-unit analysis.
0104   void IssueWarnings(TranslationUnitDecl *D);
0105 
0106   Policy getDefaultPolicy() { return DefaultPolicy; }
0107 
0108   void PrintStats() const;
0109 };
0110 
0111 } // namespace sema
0112 } // namespace clang
0113 
0114 #endif