Bug 1324328 - Remove MozChecker and some unused code; r=mystor
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 18 Dec 2016 20:58:56 -0500
changeset 327512 20134b5c4194fc6ed826e1f22dc2e4afd3b68cdc
parent 327511 0da90da58ab7c914e79ab184c834b5f38d5b06f3
child 327513 70a3d7e03d550eab7b5d9478c7192c0ae7b535e5
push id31135
push userkwierso@gmail.com
push dateThu, 29 Dec 2016 20:04:00 +0000
treeherdermozilla-central@79ef93672445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmystor
bugs1324328
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1324328 - Remove MozChecker and some unused code; r=mystor
build/clang-plugin/CustomMatchers.h
build/clang-plugin/CustomTypeAnnotation.cpp
build/clang-plugin/CustomTypeAnnotation.h
build/clang-plugin/ExplicitOperatorBoolChecker.cpp
build/clang-plugin/MozCheckAction.cpp
build/clang-plugin/MozChecker.cpp
build/clang-plugin/MozChecker.h
build/clang-plugin/MustOverrideChecker.cpp
build/clang-plugin/OverrideBaseCallChecker.cpp
build/clang-plugin/Utils.h
build/clang-plugin/moz.build
--- a/build/clang-plugin/CustomMatchers.h
+++ b/build/clang-plugin/CustomMatchers.h
@@ -1,44 +1,43 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CustomMatchers_h__
 #define CustomMatchers_h__
 
-#include "MozChecker.h"
 #include "MemMoveAnnotation.h"
 #include "Utils.h"
 
 namespace clang {
 namespace ast_matchers {
 
 /// This matcher will match any function declaration that is declared as a heap
 /// allocator.
 AST_MATCHER(FunctionDecl, heapAllocator) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_heap_allocator");
+  return hasCustomAnnotation(&Node, "moz_heap_allocator");
 }
 
 /// This matcher will match any declaration that is marked as not accepting
 /// arithmetic expressions in its arguments.
 AST_MATCHER(Decl, noArithmeticExprInArgs) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_no_arith_expr_in_arg");
+  return hasCustomAnnotation(&Node, "moz_no_arith_expr_in_arg");
 }
 
 /// This matcher will match any C++ class that is marked as having a trivial
 /// constructor and destructor.
 AST_MATCHER(CXXRecordDecl, hasTrivialCtorDtor) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_trivial_ctor_dtor");
+  return hasCustomAnnotation(&Node, "moz_trivial_ctor_dtor");
 }
 
 /// This matcher will match any function declaration that is marked to prohibit
 /// calling AddRef or Release on its return value.
 AST_MATCHER(FunctionDecl, hasNoAddRefReleaseOnReturnAttr) {
-  return MozChecker::hasCustomAnnotation(&Node,
+  return hasCustomAnnotation(&Node,
                                          "moz_no_addref_release_on_return");
 }
 
 /// This matcher will match all arithmetic binary operators.
 AST_MATCHER(BinaryOperator, binaryArithmeticOperator) {
   BinaryOperatorKind OpCode = Node.getOpcode();
   return OpCode == BO_Mul || OpCode == BO_Div || OpCode == BO_Rem ||
          OpCode == BO_Add || OpCode == BO_Sub || OpCode == BO_Shl ||
@@ -116,32 +115,32 @@ AST_MATCHER(MemberExpr, isAddRefOrReleas
 /// This matcher will select classes which are refcounted.
 AST_MATCHER(CXXRecordDecl, hasRefCntMember) {
   return isClassRefCounted(&Node) && getClassRefCntMember(&Node);
 }
 
 AST_MATCHER(QualType, hasVTable) { return typeHasVTable(Node); }
 
 AST_MATCHER(CXXRecordDecl, hasNeedsNoVTableTypeAttr) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_needs_no_vtable_type");
+  return hasCustomAnnotation(&Node, "moz_needs_no_vtable_type");
 }
 
 /// This matcher will select classes which are non-memmovable
 AST_MATCHER(QualType, isNonMemMovable) {
   return NonMemMovable.hasEffectiveAnnotation(Node);
 }
 
 /// This matcher will select classes which require a memmovable template arg
 AST_MATCHER(CXXRecordDecl, needsMemMovableTemplateArg) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_needs_memmovable_type");
+  return hasCustomAnnotation(&Node, "moz_needs_memmovable_type");
 }
 
 /// This matcher will select classes which require all members to be memmovable
 AST_MATCHER(CXXRecordDecl, needsMemMovableMembers) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_needs_memmovable_members");
+  return hasCustomAnnotation(&Node, "moz_needs_memmovable_members");
 }
 
 AST_MATCHER(CXXConstructorDecl, isInterestingImplicitCtor) {
   const CXXConstructorDecl *Declaration = Node.getCanonicalDecl();
   return
       // Skip constructors in system headers
       !ASTIsInSystemHeader(Declaration->getASTContext(), *Declaration) &&
       // Skip ignored namespaces and paths
@@ -154,25 +153,25 @@ AST_MATCHER(CXXConstructorDecl, isIntere
       !Declaration->isCopyOrMoveConstructor() &&
       // We don't want deleted constructors.
       !Declaration->isDeleted();
 }
 
 // We can't call this "isImplicit" since it clashes with an existing matcher in
 // clang.
 AST_MATCHER(CXXConstructorDecl, isMarkedImplicit) {
-  return MozChecker::hasCustomAnnotation(&Node, "moz_implicit");
+  return hasCustomAnnotation(&Node, "moz_implicit");
 }
 
 AST_MATCHER(CXXRecordDecl, isConcreteClass) { return !Node.isAbstract(); }
 
 AST_MATCHER(QualType, autoNonAutoableType) {
   if (const AutoType *T = Node->getContainedAutoType()) {
     if (const CXXRecordDecl *Rec = T->getAsCXXRecordDecl()) {
-      return MozChecker::hasCustomAnnotation(Rec, "moz_non_autoable");
+      return hasCustomAnnotation(Rec, "moz_non_autoable");
     }
   }
   return false;
 }
 
 AST_MATCHER(CXXConstructorDecl, isExplicitMoveConstructor) {
   return Node.isExplicit() && Node.isMoveConstructor();
 }
@@ -220,17 +219,17 @@ AST_MATCHER(CXXRecordDecl, hasBaseClasse
 
   // Must have definition and should inherit other classes
   return Decl && Decl->hasDefinition() && Decl->getNumBases();
 }
 
 AST_MATCHER(CXXMethodDecl, isRequiredBaseMethod) {
   const CXXMethodDecl *Decl = Node.getCanonicalDecl();
   return Decl
-      && MozChecker::hasCustomAnnotation(Decl, "moz_required_base_method");
+      && hasCustomAnnotation(Decl, "moz_required_base_method");
 }
 
 AST_MATCHER(CXXMethodDecl, isNonVirtual) {
   const CXXMethodDecl *Decl = Node.getCanonicalDecl();
   return Decl && !Decl->isVirtual();
 }
 }
 }
--- a/build/clang-plugin/CustomTypeAnnotation.cpp
+++ b/build/clang-plugin/CustomTypeAnnotation.cpp
@@ -1,79 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CustomTypeAnnotation.h"
-#include "MozChecker.h"
 
 CustomTypeAnnotation StackClass =
     CustomTypeAnnotation("moz_stack_class", "stack");
 CustomTypeAnnotation GlobalClass =
     CustomTypeAnnotation("moz_global_class", "global");
 CustomTypeAnnotation NonHeapClass =
     CustomTypeAnnotation("moz_nonheap_class", "non-heap");
 CustomTypeAnnotation HeapClass =
     CustomTypeAnnotation("moz_heap_class", "heap");
 CustomTypeAnnotation NonTemporaryClass =
     CustomTypeAnnotation("moz_non_temporary_class", "non-temporary");
 CustomTypeAnnotation NonParam =
     CustomTypeAnnotation("moz_non_param", "non-param");
 
-void CustomTypeAnnotation::dumpAnnotationReason(DiagnosticsEngine &Diag,
-                                                QualType T,
-                                                SourceLocation Loc) {
-  unsigned InheritsID = Diag.getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Note,
-      "%1 is a %0 type because it inherits from a %0 type %2");
-  unsigned MemberID = Diag.getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Note, "%1 is a %0 type because member %2 is a %0 type %3");
-  unsigned ArrayID = Diag.getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Note,
-      "%1 is a %0 type because it is an array of %0 type %2");
-  unsigned TemplID = Diag.getDiagnosticIDs()->getCustomDiagID(
-      DiagnosticIDs::Note,
-      "%1 is a %0 type because it has a template argument %0 type %2");
-
-  AnnotationReason Reason = directAnnotationReason(T);
-  for (;;) {
-    switch (Reason.Kind) {
-    case RK_ArrayElement:
-      Diag.Report(Loc, ArrayID) << Pretty << T << Reason.Type;
-      break;
-    case RK_BaseClass: {
-      const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
-      assert(Declaration && "This type should be a C++ class");
-
-      Diag.Report(Declaration->getLocation(), InheritsID) << Pretty << T
-                                                   << Reason.Type;
-      break;
-    }
-    case RK_Field:
-      Diag.Report(Reason.Field->getLocation(), MemberID)
-          << Pretty << T << Reason.Field << Reason.Type;
-      break;
-    case RK_TemplateInherited: {
-      const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
-      assert(Declaration && "This type should be a C++ class");
-
-      Diag.Report(Declaration->getLocation(), TemplID) << Pretty << T
-                                                   << Reason.Type;
-      break;
-    }
-    default:
-      // FIXME (bug 1203263): note the original annotation.
-      return;
-    }
-
-    T = Reason.Type;
-    Reason = directAnnotationReason(T);
-  }
-}
-
 void CustomTypeAnnotation::dumpAnnotationReason(BaseCheck &Check,
                                                 QualType T,
                                                 SourceLocation Loc) {
   const char* Inherits =
       "%1 is a %0 type because it inherits from a %0 type %2";
   const char* Member =
       "%1 is a %0 type because member %2 is a %0 type %3";
   const char* Array =
@@ -118,17 +66,17 @@ void CustomTypeAnnotation::dumpAnnotatio
 }
 
 bool CustomTypeAnnotation::hasLiteralAnnotation(QualType T) const {
 #if CLANG_VERSION_FULL >= 306
   if (const TagDecl *D = T->getAsTagDecl()) {
 #else
   if (const CXXRecordDecl *D = T->getAsCXXRecordDecl()) {
 #endif
-    return hasFakeAnnotation(D) || MozChecker::hasCustomAnnotation(D, Spelling);
+    return hasFakeAnnotation(D) || hasCustomAnnotation(D, Spelling);
   }
   return false;
 }
 
 CustomTypeAnnotation::AnnotationReason
 CustomTypeAnnotation::directAnnotationReason(QualType T) {
   if (hasLiteralAnnotation(T)) {
     AnnotationReason Reason = {T, RK_Direct, nullptr};
@@ -171,17 +119,17 @@ CustomTypeAnnotation::directAnnotationRe
           AnnotationReason Reason = {Field->getType(), RK_Field, Field};
           Cache[Key] = Reason;
           return Reason;
         }
       }
 
       // Recurse into template arguments if the annotation
       // MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS is present
-      if (MozChecker::hasCustomAnnotation(
+      if (hasCustomAnnotation(
               Declaration, "moz_inherit_type_annotations_from_template_args")) {
         const ClassTemplateSpecializationDecl *Spec =
             dyn_cast<ClassTemplateSpecializationDecl>(Declaration);
         if (Spec) {
           const TemplateArgumentList &Args = Spec->getTemplateArgs();
 
           AnnotationReason Reason = tmplArgAnnotationReason(Args.asArray());
           if (Reason.Kind != RK_None) {
--- a/build/clang-plugin/CustomTypeAnnotation.h
+++ b/build/clang-plugin/CustomTypeAnnotation.h
@@ -34,18 +34,16 @@ public:
       : Spelling(Spelling), Pretty(Pretty){};
 
   virtual ~CustomTypeAnnotation() {}
 
   // Checks if this custom annotation "effectively affects" the given type.
   bool hasEffectiveAnnotation(QualType T) {
     return directAnnotationReason(T).valid();
   }
-  void dumpAnnotationReason(DiagnosticsEngine &Diag, QualType T,
-                            SourceLocation Loc);
   void dumpAnnotationReason(BaseCheck &Check, QualType T,
                             SourceLocation Loc);
 
   void reportErrorIfPresent(BaseCheck &Check, QualType T,
                             SourceLocation Loc, const char* Error,
                             const char* Note) {
     if (hasEffectiveAnnotation(T)) {
       Check.diag(Loc, Error, DiagnosticIDs::Error) << T;
--- a/build/clang-plugin/ExplicitOperatorBoolChecker.cpp
+++ b/build/clang-plugin/ExplicitOperatorBoolChecker.cpp
@@ -17,17 +17,17 @@ void ExplicitOperatorBoolChecker::regist
 
 void ExplicitOperatorBoolChecker::check(
     const MatchFinder::MatchResult &Result) {
   const CXXConversionDecl *Method =
       Result.Nodes.getNodeAs<CXXConversionDecl>("node");
   const CXXRecordDecl *Clazz = Method->getParent();
 
   if (!Method->isExplicitSpecified() &&
-      !MozChecker::hasCustomAnnotation(Method, "moz_implicit") &&
+      !hasCustomAnnotation(Method, "moz_implicit") &&
       !ASTIsInSystemHeader(Method->getASTContext(), *Method) &&
       isInterestingDeclForImplicitConversion(Method)) {
     diag(Method->getLocStart(), "bad implicit conversion operator for %0",
          DiagnosticIDs::Error) << Clazz;
     diag(Method->getLocStart(), "consider adding the explicit keyword to %0",
          DiagnosticIDs::Note) << "'operator bool'";
   }
 }
--- a/build/clang-plugin/MozCheckAction.cpp
+++ b/build/clang-plugin/MozCheckAction.cpp
@@ -1,32 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "MozChecker.h"
+#include "DiagnosticsMatcher.h"
 
 class MozCheckAction : public PluginASTAction {
 public:
   ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI,
                                    StringRef FileName) override {
-#if CLANG_VERSION_FULL >= 306
-    std::unique_ptr<MozChecker> Checker(llvm::make_unique<MozChecker>(CI));
-    ASTConsumerPtr Other(Checker->getOtherConsumer());
-
-    std::vector<ASTConsumerPtr> Consumers;
-    Consumers.push_back(std::move(Checker));
-    Consumers.push_back(std::move(Other));
-    return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
-#else
-    MozChecker *Checker = new MozChecker(CI);
-
-    ASTConsumer *Consumers[] = {Checker, Checker->getOtherConsumer()};
-    return new MultiplexConsumer(Consumers);
-#endif
+    void* Buffer = CI.getASTContext().Allocate<DiagnosticsMatcher>();
+    auto Matcher = new(Buffer) DiagnosticsMatcher(CI);
+    return Matcher->makeASTConsumer();
   }
 
   bool ParseArgs(const CompilerInstance &CI,
                  const std::vector<std::string> &Args) override {
     return true;
   }
 };
 
deleted file mode 100644
--- a/build/clang-plugin/MozChecker.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "MozChecker.h"
-#include "CustomTypeAnnotation.h"
-#include "Utils.h"
-
-bool MozChecker::hasCustomAnnotation(const Decl *D, const char *Spelling) {
-  iterator_range<specific_attr_iterator<AnnotateAttr>> Attrs =
-      D->specific_attrs<AnnotateAttr>();
-
-  for (AnnotateAttr *Attr : Attrs) {
-    if (Attr->getAnnotation() == Spelling) {
-      return true;
-    }
-  }
-
-  return false;
-}
deleted file mode 100644
--- a/build/clang-plugin/MozChecker.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef MozChecker_h__
-#define MozChecker_h__
-
-#include "DiagnosticsMatcher.h"
-
-class MozChecker : public ASTConsumer, public RecursiveASTVisitor<MozChecker> {
-  DiagnosticsMatcher Matcher;
-
-public:
-  MozChecker(CompilerInstance &CI) :
-    Matcher(CI) {}
-  virtual ~MozChecker() {}
-
-  ASTConsumerPtr getOtherConsumer() { return Matcher.makeASTConsumer(); }
-
-  static bool hasCustomAnnotation(const Decl *D, const char *Spelling);
-};
-
-#endif
--- a/build/clang-plugin/MustOverrideChecker.cpp
+++ b/build/clang-plugin/MustOverrideChecker.cpp
@@ -30,17 +30,17 @@ void MustOverrideChecker::check(
     // do any checking here. For complete correctness, we should visit
     // template instantiations, but this case is likely to be rare, so we will
     // ignore it until it becomes important.
     if (!Parent) {
       continue;
     }
     Parent = Parent->getDefinition();
     for (const auto& M : Parent->methods()) {
-      if (MozChecker::hasCustomAnnotation(M, "moz_must_override"))
+      if (hasCustomAnnotation(M, "moz_must_override"))
         MustOverrides.push_back(M);
     }
   }
 
   for (auto& O : MustOverrides) {
     bool Overridden = false;
     for (const auto& M : D->methods()) {
       // The way that Clang checks if a method M overrides its parent method
--- a/build/clang-plugin/OverrideBaseCallChecker.cpp
+++ b/build/clang-plugin/OverrideBaseCallChecker.cpp
@@ -7,17 +7,17 @@
 
 void OverrideBaseCallChecker::registerMatchers(MatchFinder* AstMatcher) {
   AstMatcher->addMatcher(cxxRecordDecl(hasBaseClasses()).bind("class"),
       this);
 }
 
 bool OverrideBaseCallChecker::isRequiredBaseMethod(
     const CXXMethodDecl *Method) {
-  return MozChecker::hasCustomAnnotation(Method, "moz_required_base_method");
+  return hasCustomAnnotation(Method, "moz_required_base_method");
 }
 
 void OverrideBaseCallChecker::evaluateExpression(
     const Stmt *StmtExpr, std::list<const CXXMethodDecl*> &MethodList) {
   // Continue while we have methods in our list
   if (!MethodList.size()) {
     return;
   }
--- a/build/clang-plugin/Utils.h
+++ b/build/clang-plugin/Utils.h
@@ -347,21 +347,34 @@ inline const FieldDecl *getBaseRefCntMem
 
 inline const FieldDecl *getBaseRefCntMember(QualType T) {
   while (const clang::ArrayType *ArrTy = T->getAsArrayTypeUnsafe())
     T = ArrTy->getElementType();
   CXXRecordDecl *Clazz = T->getAsCXXRecordDecl();
   return Clazz ? getBaseRefCntMember(Clazz) : 0;
 }
 
+inline bool hasCustomAnnotation(const Decl *D, const char *Spelling) {
+  iterator_range<specific_attr_iterator<AnnotateAttr>> Attrs =
+      D->specific_attrs<AnnotateAttr>();
+
+  for (AnnotateAttr *Attr : Attrs) {
+    if (Attr->getAnnotation() == Spelling) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 inline bool isPlacementNew(const CXXNewExpr *Expression) {
   // Regular new expressions aren't placement new
   if (Expression->getNumPlacementArgs() == 0)
     return false;
   const FunctionDecl *Declaration = Expression->getOperatorNew();
-  if (Declaration && MozChecker::hasCustomAnnotation(Declaration,
+  if (Declaration && hasCustomAnnotation(Declaration,
                  "moz_heap_allocator")) {
     return false;
   }
   return true;
 }
 
 #endif
--- a/build/clang-plugin/moz.build
+++ b/build/clang-plugin/moz.build
@@ -10,17 +10,16 @@ UNIFIED_SOURCES += [
     'ArithmeticArgChecker.cpp',
     'AssertAssignmentChecker.cpp',
     'CustomTypeAnnotation.cpp',
     'DiagnosticsMatcher.cpp',
     'ExplicitImplicitChecker.cpp',
     'ExplicitOperatorBoolChecker.cpp',
     'KungFuDeathGripChecker.cpp',
     'MozCheckAction.cpp',
-    'MozChecker.cpp',
     'MustOverrideChecker.cpp',
     'MustUseChecker.cpp',
     'NaNExprChecker.cpp',
     'NeedsNoVTableTypeChecker.cpp',
     'NoAddRefReleaseOnReturnChecker.cpp',
     'NoAutoTypeChecker.cpp',
     'NoDuplicateRefCntMemberChecker.cpp',
     'NoExplicitMoveConstructorChecker.cpp',