r188230 - Remove Sema includes from Analysis code to fix layering

Reid Kleckner reid at kleckner.net
Mon Aug 12 16:49:39 PDT 2013


Author: rnk
Date: Mon Aug 12 18:49:39 2013
New Revision: 188230

URL: http://llvm.org/viewvc/llvm-project?rev=188230&view=rev
Log:
Remove Sema includes from Analysis code to fix layering

This moves a header-only class from Sema to Analysis and puts the option
check in Sema.

Patch by Chris Wailes!

Removed:
    cfe/trunk/include/clang/Sema/ConsumedWarningsHandler.h
Modified:
    cfe/trunk/include/clang/Analysis/Analyses/Consumed.h
    cfe/trunk/lib/Analysis/Consumed.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/include/clang/Analysis/Analyses/Consumed.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/Consumed.h?rev=188230&r1=188229&r2=188230&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/Consumed.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/Consumed.h Mon Aug 12 18:49:39 2013
@@ -21,12 +21,79 @@
 #include "clang/Analysis/AnalysisContext.h"
 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Sema/ConsumedWarningsHandler.h"
-#include "clang/Sema/Sema.h"
 
 namespace clang {
 namespace consumed {
-  
+
+  typedef SmallVector<PartialDiagnosticAt, 1> OptionalNotes;
+  typedef std::pair<PartialDiagnosticAt, OptionalNotes> DelayedDiag;
+  typedef std::list<DelayedDiag> DiagList;
+
+  class ConsumedWarningsHandlerBase {
+
+  public:
+
+    virtual ~ConsumedWarningsHandlerBase();
+
+    /// \brief Emit the warnings and notes left by the analysis.
+    virtual void emitDiagnostics() {}
+
+    /// Warn about unnecessary-test errors.
+    /// \param VariableName -- The name of the variable that holds the unique
+    /// value.
+    ///
+    /// \param Loc -- The SourceLocation of the unnecessary test.
+    virtual void warnUnnecessaryTest(StringRef VariableName,
+                                     StringRef VariableState,
+                                     SourceLocation Loc) {}
+
+    /// Warn about use-while-consumed errors.
+    /// \param MethodName -- The name of the method that was incorrectly
+    /// invoked.
+    ///
+    /// \param VariableName -- The name of the variable that holds the unique
+    /// value.
+    ///
+    /// \param Loc -- The SourceLocation of the method invocation.
+    virtual void warnUseOfTempWhileConsumed(StringRef MethodName,
+                                            SourceLocation Loc) {}
+
+    /// Warn about use-in-unknown-state errors.
+    /// \param MethodName -- The name of the method that was incorrectly
+    /// invoked.
+    ///
+    /// \param VariableName -- The name of the variable that holds the unique
+    /// value.
+    ///
+    /// \param Loc -- The SourceLocation of the method invocation.
+    virtual void warnUseOfTempInUnknownState(StringRef MethodName,
+                                             SourceLocation Loc) {}
+
+    /// Warn about use-while-consumed errors.
+    /// \param MethodName -- The name of the method that was incorrectly
+    /// invoked.
+    ///
+    /// \param VariableName -- The name of the variable that holds the unique
+    /// value.
+    ///
+    /// \param Loc -- The SourceLocation of the method invocation.
+    virtual void warnUseWhileConsumed(StringRef MethodName,
+                                      StringRef VariableName,
+                                      SourceLocation Loc) {}
+
+    /// Warn about use-in-unknown-state errors.
+    /// \param MethodName -- The name of the method that was incorrectly
+    /// invoked.
+    ///
+    /// \param VariableName -- The name of the variable that holds the unique
+    /// value.
+    ///
+    /// \param Loc -- The SourceLocation of the method invocation.
+    virtual void warnUseInUnknownState(StringRef MethodName,
+                                       StringRef VariableName,
+                                       SourceLocation Loc) {}
+  };
+
   enum ConsumedState {
     // No state information for the given variable.
     CS_None,
@@ -99,8 +166,6 @@ namespace consumed {
     typedef llvm::DenseMap<const CXXRecordDecl *, bool> CacheMapType;
     typedef std::pair<const CXXRecordDecl *, bool> CachePairType;
     
-    Sema &S;
-    
     ConsumedBlockInfo BlockInfo;
     ConsumedStateMap *CurrStates;
     
@@ -112,13 +177,10 @@ namespace consumed {
   public:
     
     ConsumedWarningsHandlerBase &WarningsHandler;
-    
-    ConsumedAnalyzer(Sema &S, ConsumedWarningsHandlerBase &WarningsHandler)
-        : S(S), WarningsHandler(WarningsHandler) {}
-    
-    /// \brief Get a constant reference to the Sema object.
-    const Sema & getSema(void);
-    
+
+    ConsumedAnalyzer(ConsumedWarningsHandlerBase &WarningsHandler)
+        : WarningsHandler(WarningsHandler) {}
+
     /// \brief Check to see if the type is a consumable type.
     bool isConsumableType(QualType Type);
     
@@ -131,7 +193,6 @@ namespace consumed {
     void run(AnalysisDeclContext &AC);
   };
   
-  unsigned checkEnabled(DiagnosticsEngine &D);
   /// \brief Check to see if a function tests an object's validity.
   bool isTestingFunction(const CXXMethodDecl *MethodDecl);
   

Removed: cfe/trunk/include/clang/Sema/ConsumedWarningsHandler.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ConsumedWarningsHandler.h?rev=188229&view=auto
==============================================================================
--- cfe/trunk/include/clang/Sema/ConsumedWarningsHandler.h (original)
+++ cfe/trunk/include/clang/Sema/ConsumedWarningsHandler.h (removed)
@@ -1,98 +0,0 @@
-//===- ConsumedWarningsHandler.h -------------------------------*- C++ --*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// A handler class for warnings issued by the consumed analysis.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_CONSUMED_WARNING_HANDLER_H
-#define LLVM_CLANG_CONSUMED_WARNING_HANDLER_H
-
-#include <list>
-#include <utility>
-
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Sema/Sema.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-
-namespace clang {
-namespace consumed {
-
-  typedef SmallVector<PartialDiagnosticAt, 1> OptionalNotes;
-  typedef std::pair<PartialDiagnosticAt, OptionalNotes> DelayedDiag;
-  typedef std::list<DelayedDiag> DiagList;
-
-  class ConsumedWarningsHandlerBase {
-    
-  public:
-    
-    virtual ~ConsumedWarningsHandlerBase();
-    
-    /// \brief Emit the warnings and notes left by the analysis.
-    virtual void emitDiagnostics() {}
-    
-    /// Warn about unnecessary-test errors.
-    /// \param VariableName -- The name of the variable that holds the unique
-    /// value.
-    ///
-    /// \param Loc -- The SourceLocation of the unnecessary test.
-    virtual void warnUnnecessaryTest(StringRef VariableName,
-                                     StringRef VariableState,
-                                     SourceLocation Loc) {}
-    
-    /// Warn about use-while-consumed errors.
-    /// \param MethodName -- The name of the method that was incorrectly
-    /// invoked.
-    /// 
-    /// \param VariableName -- The name of the variable that holds the unique
-    /// value.
-    ///
-    /// \param Loc -- The SourceLocation of the method invocation.
-    virtual void warnUseOfTempWhileConsumed(StringRef MethodName,
-                                            SourceLocation Loc) {}
-    
-    /// Warn about use-in-unknown-state errors.
-    /// \param MethodName -- The name of the method that was incorrectly
-    /// invoked.
-    ///
-    /// \param VariableName -- The name of the variable that holds the unique
-    /// value.
-    ///
-    /// \param Loc -- The SourceLocation of the method invocation.
-    virtual void warnUseOfTempInUnknownState(StringRef MethodName,
-                                             SourceLocation Loc) {}
-    
-    /// Warn about use-while-consumed errors.
-    /// \param MethodName -- The name of the method that was incorrectly
-    /// invoked.
-    ///
-    /// \param VariableName -- The name of the variable that holds the unique
-    /// value.
-    ///
-    /// \param Loc -- The SourceLocation of the method invocation.
-    virtual void warnUseWhileConsumed(StringRef MethodName,
-                                      StringRef VariableName,
-                                      SourceLocation Loc) {}
-    
-    /// Warn about use-in-unknown-state errors.
-    /// \param MethodName -- The name of the method that was incorrectly
-    /// invoked.
-    ///
-    /// \param VariableName -- The name of the variable that holds the unique
-    /// value.
-    ///
-    /// \param Loc -- The SourceLocation of the method invocation.
-    virtual void warnUseInUnknownState(StringRef MethodName,
-                                       StringRef VariableName,
-                                       SourceLocation Loc) {}
-  };
-}} // end clang::consumed
-
-#endif

Modified: cfe/trunk/lib/Analysis/Consumed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=188230&r1=188229&r2=188230&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Consumed.cpp (original)
+++ cfe/trunk/lib/Analysis/Consumed.cpp Mon Aug 12 18:49:39 2013
@@ -26,8 +26,6 @@
 #include "clang/Analysis/Analyses/Consumed.h"
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Sema/ConsumedWarningsHandler.h"
-#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/raw_ostream.h"
@@ -100,7 +98,8 @@ class ConsumedStmtVisitor : public Const
   typedef llvm::DenseMap<const Stmt *, PropagationInfo> MapType;
   typedef std::pair<const Stmt *, PropagationInfo> PairType;
   typedef MapType::iterator InfoEntry;
-  
+
+  AnalysisDeclContext &AC;
   ConsumedAnalyzer &Analyzer;
   ConsumedStateMap *StateMap;
   MapType PropagationMap;
@@ -124,10 +123,11 @@ public:
   void VisitMemberExpr(const MemberExpr *MExpr);
   void VisitUnaryOperator(const UnaryOperator *UOp);
   void VisitVarDecl(const VarDecl *Var);
-  
-  ConsumedStmtVisitor(ConsumedAnalyzer &Analyzer, ConsumedStateMap *StateMap) :
-    Analyzer(Analyzer), StateMap(StateMap) {}
-  
+
+  ConsumedStmtVisitor(AnalysisDeclContext &AC, ConsumedAnalyzer &Analyzer,
+                      ConsumedStateMap *StateMap)
+      : AC(AC), Analyzer(Analyzer), StateMap(StateMap) {}
+
   void reset() {
     PropagationMap.clear();
   }
@@ -227,8 +227,8 @@ void ConsumedStmtVisitor::VisitCastExpr(
 
 void ConsumedStmtVisitor::VisitCXXConstructExpr(const CXXConstructExpr *Call) {
   CXXConstructorDecl *Constructor = Call->getConstructor();
-  
-  ASTContext &CurrContext = Analyzer.getSema().getASTContext();
+
+  ASTContext &CurrContext = AC.getASTContext();
   QualType ThisType = Constructor->getThisType(CurrContext)->getPointeeType();
   
   if (Analyzer.isConsumableType(ThisType)) {
@@ -636,10 +636,6 @@ void ConsumedStateMap::setState(const Va
   Map[Var] = State;
 }
 
-const Sema & ConsumedAnalyzer::getSema() {
-  return S;
-}
-
 
 bool ConsumedAnalyzer::isConsumableType(QualType Type) {
   const CXXRecordDecl *RD =
@@ -737,9 +733,9 @@ void ConsumedAnalyzer::run(AnalysisDeclC
     
     if (CurrStates == NULL)
       CurrStates = BlockInfo.getInfo(CurrBlock);
-    
-    ConsumedStmtVisitor Visitor(*this, CurrStates);
-    
+
+    ConsumedStmtVisitor Visitor(AC, *this, CurrStates);
+
     // Visit all of the basic block's statements.
     for (CFGBlock::const_iterator BI = CurrBlock->begin(),
          BE = CurrBlock->end(); BI != BE; ++BI) {
@@ -789,12 +785,6 @@ void ConsumedAnalyzer::run(AnalysisDeclC
   WarningsHandler.emitDiagnostics();
 }
 
-unsigned checkEnabled(DiagnosticsEngine &D) {
-  return (unsigned)
-    (D.getDiagnosticLevel(diag::warn_use_while_consumed, SourceLocation()) !=
-     DiagnosticsEngine::Ignored);
-}
-
 bool isTestingFunction(const CXXMethodDecl *Method) {
   return Method->hasAttr<TestsUnconsumedAttr>();
 }

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=188230&r1=188229&r2=188230&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Aug 12 18:49:39 2013
@@ -1557,8 +1557,10 @@ clang::sema::AnalysisBasedWarnings::Anal
   DefaultPolicy.enableThreadSafetyAnalysis = (unsigned)
     (D.getDiagnosticLevel(diag::warn_double_lock, SourceLocation()) !=
      DiagnosticsEngine::Ignored);
-  DefaultPolicy.enableConsumedAnalysis = consumed::checkEnabled(D);
-
+  DefaultPolicy.enableConsumedAnalysis =
+      (unsigned)(D.getDiagnosticLevel(diag::warn_use_while_consumed,
+                                      SourceLocation()) !=
+                 DiagnosticsEngine::Ignored);
 }
 
 static void flushDiagnostics(Sema &S, sema::FunctionScopeInfo *fscope) {
@@ -1727,7 +1729,7 @@ AnalysisBasedWarnings::IssueWarnings(sem
   // Check for violations of consumed properties.
   if (P.enableConsumedAnalysis) {
     consumed::ConsumedWarningsHandler WarningHandler(S);
-    consumed::ConsumedAnalyzer Analyzer(S, WarningHandler);
+    consumed::ConsumedAnalyzer Analyzer(WarningHandler);
     Analyzer.run(AC);
   }
 





More information about the cfe-commits mailing list