Bug 1615826 - Reformat `clang-plugin` to LLVM standard. r=froydnj
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Mon, 17 Feb 2020 18:30:50 +0000
changeset 514334 026489b7bda6781b49a5b6bf7f4604894e3458dd
parent 514333 545bb13ac456a02e0c785188b1a3b11f18b6d47d
child 514335 df278a39cb4157526c81b6c113b69fa8c67b3817
push id37132
push userrmaries@mozilla.com
push dateTue, 18 Feb 2020 04:10:21 +0000
treeherdermozilla-central@5df075b6a6bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1615826
milestone75.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 1615826 - Reformat `clang-plugin` to LLVM standard. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D63000
build/clang-plugin/CanRunScriptChecker.cpp
build/clang-plugin/CustomAttributes.cpp
build/clang-plugin/CustomAttributes.h
build/clang-plugin/CustomMatchers.h
build/clang-plugin/DanglingOnTemporaryChecker.cpp
build/clang-plugin/DiagnosticsMatcher.h
build/clang-plugin/ExplicitOperatorBoolChecker.cpp
build/clang-plugin/FopenUsageChecker.h
build/clang-plugin/KungFuDeathGripChecker.cpp
build/clang-plugin/MustReturnFromCallerChecker.cpp
build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.cpp
build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.h
build/clang-plugin/ParamTraitsEnumChecker.cpp
build/clang-plugin/ParamTraitsEnumChecker.h
build/clang-plugin/ScopeChecker.cpp
build/clang-plugin/TrivialDtorChecker.cpp
build/clang-plugin/Utils.h
--- a/build/clang-plugin/CanRunScriptChecker.cpp
+++ b/build/clang-plugin/CanRunScriptChecker.cpp
@@ -50,40 +50,37 @@
 
 #include "CanRunScriptChecker.h"
 #include "CustomMatchers.h"
 #include "clang/Lex/Lexer.h"
 
 void CanRunScriptChecker::registerMatchers(MatchFinder *AstMatcher) {
   auto Refcounted = qualType(hasDeclaration(cxxRecordDecl(isRefCounted())));
   auto StackSmartPtr =
-    ignoreTrivials(
-      declRefExpr(to(varDecl(hasAutomaticStorageDuration())),
-                  hasType(isSmartPtrToRefCounted())));
+      ignoreTrivials(declRefExpr(to(varDecl(hasAutomaticStorageDuration())),
+                                 hasType(isSmartPtrToRefCounted())));
   auto ConstMemberOfThisSmartPtr =
-    memberExpr(hasType(isSmartPtrToRefCounted()),
-               hasType(isConstQualified()),
-               hasObjectExpression(cxxThisExpr()));
+      memberExpr(hasType(isSmartPtrToRefCounted()), hasType(isConstQualified()),
+                 hasObjectExpression(cxxThisExpr()));
   // A smartptr can be known-live for three reasons:
   // 1) It's declared on the stack.
   // 2) It's a const member of "this".  We know "this" is alive (recursively)
   //    and const members can't change their value hence can't drop their
   //    reference until "this" gets destroyed.
   // 3) It's an immediate temporary being constructed at the point where the
   //    call is happening.
   auto KnownLiveSmartPtr = anyOf(
-    StackSmartPtr,
-    ConstMemberOfThisSmartPtr,
-    ignoreTrivials(cxxConstructExpr(hasType(isSmartPtrToRefCounted()))));
+      StackSmartPtr, ConstMemberOfThisSmartPtr,
+      ignoreTrivials(cxxConstructExpr(hasType(isSmartPtrToRefCounted()))));
 
   auto MozKnownLiveCall =
-    ignoreTrivials(callExpr(callee(functionDecl(hasName("MOZ_KnownLive")))));
+      ignoreTrivials(callExpr(callee(functionDecl(hasName("MOZ_KnownLive")))));
 
-  // Params of the calling function are presumed live, because it itself should be
-  // MOZ_CAN_RUN_SCRIPT.  Note that this is subject to
+  // Params of the calling function are presumed live, because it itself should
+  // be MOZ_CAN_RUN_SCRIPT.  Note that this is subject to
   // https://bugzilla.mozilla.org/show_bug.cgi?id=1537656 a the moment.
   auto KnownLiveParam = anyOf(
       // "this" is OK
       cxxThisExpr(),
       // A parameter of the calling function is OK.
       declRefExpr(to(parmVarDecl())));
 
   // A matcher that matches various things that are known to be live directly,
@@ -103,25 +100,22 @@ void CanRunScriptChecker::registerMatche
   auto KnownLiveSimple = anyOf(
       // Things that are just known live.
       KnownLiveBase,
       // Method calls on a live things that are smart ptrs.  Note that we don't
       // want to allow general method calls on live things, because those can
       // return non-live objects (e.g. consider "live_pointer->foo()" as an
       // example).  For purposes of this analysis we are assuming the method
       // calls on smart ptrs all just return the pointer inside,
-      cxxMemberCallExpr(on(
-          allOf(hasType(isSmartPtrToRefCounted()),
-                KnownLiveBase))),
+      cxxMemberCallExpr(
+          on(allOf(hasType(isSmartPtrToRefCounted()), KnownLiveBase))),
       // operator* or operator-> on a thing that is already known to be live.
-      cxxOperatorCallExpr(
-          anyOf(hasOverloadedOperatorName("*"),
-                hasOverloadedOperatorName("->")),
-          hasAnyArgument(KnownLiveBase),
-          argumentCountIs(1)),
+      cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("*"),
+                                hasOverloadedOperatorName("->")),
+                          hasAnyArgument(KnownLiveBase), argumentCountIs(1)),
       // A dereference on a thing that is known to be live.  This is _not_
       // caught by the "operator* or operator->" clause above, because
       // cxxOperatorCallExpr() only catches cases when a class defines
       // operator*.  The default (built-in) operator* matches unaryOperator()
       // instead.),
       unaryOperator(
           unaryDereferenceOperator(),
           hasUnaryOperand(
@@ -134,57 +128,46 @@ void CanRunScriptChecker::registerMatche
               ignoreTrivials(KnownLiveBase))),
       // Taking a pointer to a live reference.  We explicitly want to exclude
       // things that are not of type reference-to-refcounted or type refcounted,
       // because if someone takes a pointer to a pointer to refcounted or a
       // pointer to a smart ptr and passes those in to a callee that definitely
       // does not guarantee liveness; in fact the callee could modify those
       // things!  In practice they would be the wrong type anyway, though, so
       // it's hard to add a test for this.
-      unaryOperator(
-          hasOperatorName("&"),
-          hasUnaryOperand(allOf(
-              anyOf(
-                  hasType(references(Refcounted)),
-                  hasType(Refcounted)),
-              ignoreTrivials(KnownLiveBase))))
-      );
+      unaryOperator(hasOperatorName("&"),
+                    hasUnaryOperand(allOf(anyOf(hasType(references(Refcounted)),
+                                                hasType(Refcounted)),
+                                          ignoreTrivials(KnownLiveBase)))));
 
   auto KnownLive = anyOf(
       // Anything above, of course.
       KnownLiveSimple,
       // Conditional operators where both arms are live.
-      conditionalOperator(
-          hasFalseExpression(ignoreTrivials(KnownLiveSimple)),
-          hasTrueExpression(ignoreTrivials(KnownLiveSimple)))
+      conditionalOperator(hasFalseExpression(ignoreTrivials(KnownLiveSimple)),
+                          hasTrueExpression(ignoreTrivials(KnownLiveSimple)))
       // We're not handling cases like a dereference of a conditional operator,
       // mostly because handling a dereference in general is so ugly.  I
       // _really_ wish I could just write a recursive matcher here easily.
-      );
+  );
 
-  auto InvalidArg =
-      ignoreTrivialsConditional(
-        // We want to consider things if there is anything refcounted involved,
-        // including in any of the trivials that we otherwise strip off.
-        anyOf(
-          hasType(Refcounted),
-          hasType(pointsTo(Refcounted)),
-          hasType(references(Refcounted)),
-          hasType(isSmartPtrToRefCounted())
-        ),
-        // We want to find any expression,
-        expr(
+  auto InvalidArg = ignoreTrivialsConditional(
+      // We want to consider things if there is anything refcounted involved,
+      // including in any of the trivials that we otherwise strip off.
+      anyOf(hasType(Refcounted), hasType(pointsTo(Refcounted)),
+            hasType(references(Refcounted)), hasType(isSmartPtrToRefCounted())),
+      // We want to find any expression,
+      expr(
           // which is not known live,
           unless(KnownLive),
           // and which is not a default arg with value nullptr, since those are
           // always safe,
           unless(cxxDefaultArgExpr(isNullDefaultArg())),
           // and which is not a literal nullptr,
-          unless(cxxNullPtrLiteralExpr()),
-          expr().bind("invalidArg")));
+          unless(cxxNullPtrLiteralExpr()), expr().bind("invalidArg")));
 
   // A matcher which will mark the first invalid argument it finds invalid, but
   // will always match, even if it finds no invalid arguments, so it doesn't
   // preclude other matchers from running and maybe finding invalid args.
   auto OptionalInvalidExplicitArg = anyOf(
       // We want to find any argument which is invalid.
       hasAnyArgument(InvalidArg),
 
@@ -198,21 +181,17 @@ void CanRunScriptChecker::registerMatche
   AstMatcher->addMatcher(
       expr(
           anyOf(
               // We want to match a method call expression,
               cxxMemberCallExpr(
                   // which optionally has an invalid arg,
                   OptionalInvalidExplicitArg,
                   // or which optionally has an invalid this argument,
-                  anyOf(
-                    on(InvalidArg),
-                    anything()
-                  ),
-                  expr().bind("callExpr")),
+                  anyOf(on(InvalidArg), anything()), expr().bind("callExpr")),
               // or a regular call expression,
               callExpr(
                   // which optionally has an invalid arg.
                   OptionalInvalidExplicitArg, expr().bind("callExpr")),
               // or a construct expression,
               cxxConstructExpr(
                   // which optionally has an invalid arg.
                   OptionalInvalidExplicitArg, expr().bind("constructExpr"))),
@@ -233,20 +212,19 @@ void CanRunScriptChecker::onStartOfTrans
 
 namespace {
 /// This class is a callback used internally to match function declarations with
 /// the MOZ_CAN_RUN_SCRIPT annotation, adding these functions to the
 /// can-run-script function set and making sure the functions they override (if
 /// any) also have the annotation.
 class FuncSetCallback : public MatchFinder::MatchCallback {
 public:
-  FuncSetCallback(CanRunScriptChecker& Checker,
+  FuncSetCallback(CanRunScriptChecker &Checker,
                   std::unordered_set<const FunctionDecl *> &FuncSet)
-      : CanRunScriptFuncs(FuncSet),
-        Checker(Checker) {}
+      : CanRunScriptFuncs(FuncSet), Checker(Checker) {}
 
   void run(const MatchFinder::MatchResult &Result) override;
 
 private:
   /// This method checks the methods overriden by the given parameter.
   void checkOverriddenMethods(const CXXMethodDecl *Method);
 
   std::unordered_set<const FunctionDecl *> &CanRunScriptFuncs;
@@ -272,42 +250,39 @@ void FuncSetCallback::run(const MatchFin
 }
 
 void FuncSetCallback::checkOverriddenMethods(const CXXMethodDecl *Method) {
   for (auto OverriddenMethod : Method->overridden_methods()) {
     if (!hasCustomAttribute<moz_can_run_script>(OverriddenMethod)) {
       const char *ErrorNonCanRunScriptOverridden =
           "functions marked as MOZ_CAN_RUN_SCRIPT cannot override functions "
           "that are not marked MOZ_CAN_RUN_SCRIPT";
-      const char* NoteNonCanRunScriptOverridden =
+      const char *NoteNonCanRunScriptOverridden =
           "overridden function declared here";
 
       Checker.diag(Method->getLocation(), ErrorNonCanRunScriptOverridden,
                    DiagnosticIDs::Error);
       Checker.diag(OverriddenMethod->getLocation(),
-                   NoteNonCanRunScriptOverridden,
-                   DiagnosticIDs::Note);
+                   NoteNonCanRunScriptOverridden, DiagnosticIDs::Note);
     }
   }
 }
 } // namespace
 
 void CanRunScriptChecker::buildFuncSet(ASTContext *Context) {
   // We create a match finder.
   MatchFinder Finder;
   // We create the callback which will be called when we find a function with
   // a MOZ_CAN_RUN_SCRIPT annotation.
   FuncSetCallback Callback(*this, CanRunScriptFuncs);
   // We add the matcher to the finder, linking it to our callback.
   Finder.addMatcher(
       functionDecl(hasCanRunScriptAnnotation()).bind("canRunScriptFunction"),
       &Callback);
-  Finder.addMatcher(
-      lambdaExpr().bind("lambda"),
-      &Callback);
+  Finder.addMatcher(lambdaExpr().bind("lambda"), &Callback);
   // We start the analysis, given the ASTContext our main checker is in.
   Finder.matchAST(*Context);
 }
 
 void CanRunScriptChecker::check(const MatchFinder::MatchResult &Result) {
 
   // If the set of functions which can run script is not yet built, then build
   // it.
@@ -322,17 +297,17 @@ void CanRunScriptChecker::check(const Ma
       "argument).  '%0' is neither.";
 
   const char *ErrorNonCanRunScriptParent =
       "functions marked as MOZ_CAN_RUN_SCRIPT can only be called from "
       "functions also marked as MOZ_CAN_RUN_SCRIPT";
   const char *NoteNonCanRunScriptParent = "caller function declared here";
 
   const Expr *InvalidArg;
-  if (const CXXDefaultArgExpr* defaultArg =
+  if (const CXXDefaultArgExpr *defaultArg =
           Result.Nodes.getNodeAs<CXXDefaultArgExpr>("invalidArg")) {
     InvalidArg = defaultArg->getExpr();
   } else {
     InvalidArg = Result.Nodes.getNodeAs<Expr>("invalidArg");
   }
 
   const CallExpr *Call = Result.Nodes.getNodeAs<CallExpr>("callExpr");
   // If we don't find the FunctionDecl linked to this call or if it's not marked
@@ -378,21 +353,19 @@ void CanRunScriptChecker::check(const Ma
   } else {
     // If we have neither a Call nor a Construct, we have nothing do to here.
     return;
   }
 
   // If we have an invalid argument in the call, we emit the diagnostic to
   // signal it.
   if (InvalidArg) {
-    const std::string invalidArgText =
-        Lexer::getSourceText(
-            CharSourceRange::getTokenRange(InvalidArg->getSourceRange()),
-            Result.Context->getSourceManager(),
-            Result.Context->getLangOpts());
+    const std::string invalidArgText = Lexer::getSourceText(
+        CharSourceRange::getTokenRange(InvalidArg->getSourceRange()),
+        Result.Context->getSourceManager(), Result.Context->getLangOpts());
     diag(InvalidArg->getExprLoc(), ErrorInvalidArg, DiagnosticIDs::Error)
         << InvalidArg->getSourceRange() << invalidArgText;
   }
 
   // If the parent function is not marked as MOZ_CAN_RUN_SCRIPT, we emit an
   // error and a not indicating it.
   if (ParentFunction) {
     assert(!hasCustomAttribute<moz_can_run_script>(ParentFunction) &&
--- a/build/clang-plugin/CustomAttributes.cpp
+++ b/build/clang-plugin/CustomAttributes.cpp
@@ -1,16 +1,16 @@
 /* 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 <algorithm>
 #include "CustomAttributes.h"
 #include "plugin.h"
 #include "clang/Frontend/FrontendPluginRegistry.h"
+#include <algorithm>
 
 /* Having annotations in the AST unexpectedly impacts codegen.
  * Ideally, we'd avoid having annotations at all, by using an API such as
  * the one from https://reviews.llvm.org/D31338, and storing the attributes
  * data separately from the AST on our own. Unfortunately, there is no such
  * API currently in clang, so we must do without.
  * We can do something similar, though, where we go through the AST before
  * running the checks, create a mapping of AST nodes to attributes, and
@@ -21,102 +21,97 @@
  * annotations attached (aka, hasn't been seen during our first pass),
  * so that those don't go unnoticed. (-Werror should then take care of
  * making that an error)
  */
 
 using namespace clang;
 using namespace llvm;
 
-static DenseMap<const Decl*, CustomAttributesSet> AttributesCache;
+static DenseMap<const Decl *, CustomAttributesSet> AttributesCache;
 
-static CustomAttributesSet CacheAttributes(const Decl* D)
-{
+static CustomAttributesSet CacheAttributes(const Decl *D) {
   CustomAttributesSet attrs = {};
   for (auto Attr : D->specific_attrs<AnnotateAttr>()) {
     auto annotation = Attr->getAnnotation();
-#define ATTR(a) \
-    if (annotation == #a) { \
-      attrs.has_ ## a = true; \
-    } else
+#define ATTR(a)                                                                \
+  if (annotation == #a) {                                                      \
+    attrs.has_##a = true;                                                      \
+  } else
 #include "CustomAttributes.inc"
 #undef ATTR
     {}
   }
-  const_cast<Decl*>(D)->dropAttr<AnnotateAttr>();
+  const_cast<Decl *>(D)->dropAttr<AnnotateAttr>();
   AttributesCache.insert(std::make_pair(D, attrs));
   return attrs;
 }
 
-static void Report(const Decl* D, const char* message)
-{
-  ASTContext& Context = D->getASTContext();
-  DiagnosticsEngine& Diag = Context.getDiagnostics();
-  unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(
-    DiagnosticIDs::Warning, message);
+static void Report(const Decl *D, const char *message) {
+  ASTContext &Context = D->getASTContext();
+  DiagnosticsEngine &Diag = Context.getDiagnostics();
+  unsigned ID =
+      Diag.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Warning, message);
   Diag.Report(D->getBeginLoc(), ID);
 }
 
-CustomAttributesSet GetAttributes(const Decl* D)
-{
+CustomAttributesSet GetAttributes(const Decl *D) {
   CustomAttributesSet attrs = {};
   if (D->hasAttr<AnnotateAttr>()) {
     Report(D, "Declaration has unhandled annotations.");
     attrs = CacheAttributes(D);
   } else {
     auto attributes = AttributesCache.find(D);
     if (attributes != AttributesCache.end()) {
       attrs = attributes->second;
     }
   }
   return attrs;
 }
 
-bool hasCustomAttribute(const clang::Decl* D, CustomAttributes A)
-{
+bool hasCustomAttribute(const clang::Decl *D, CustomAttributes A) {
   CustomAttributesSet attrs = GetAttributes(D);
   switch (A) {
-#define ATTR(a) case a: return attrs.has_ ## a;
+#define ATTR(a)                                                                \
+  case a:                                                                      \
+    return attrs.has_##a;
 #include "CustomAttributes.inc"
 #undef ATTR
   }
   return false;
 }
 
-class CustomAttributesMatcher : public ast_matchers::MatchFinder::MatchCallback {
+class CustomAttributesMatcher
+    : public ast_matchers::MatchFinder::MatchCallback {
 public:
-  virtual void
-  run(const ast_matchers::MatchFinder::MatchResult &Result) final
-  {
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) final {
     if (auto D = Result.Nodes.getNodeAs<Decl>("decl")) {
       CacheAttributes(D);
     } else if (auto L = Result.Nodes.getNodeAs<LambdaExpr>("lambda")) {
       CacheAttributes(L->getCallOperator());
       CacheAttributes(L->getLambdaClass());
     }
   }
 };
 
 class CustomAttributesAction : public PluginASTAction {
 public:
   ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI,
                                    StringRef FileName) override {
-    auto& Context = CI.getASTContext();
+    auto &Context = CI.getASTContext();
     auto AstMatcher = new (Context.Allocate<MatchFinder>()) MatchFinder();
-    auto Matcher = new (Context.Allocate<CustomAttributesMatcher>()) CustomAttributesMatcher();
+    auto Matcher = new (Context.Allocate<CustomAttributesMatcher>())
+        CustomAttributesMatcher();
     AstMatcher->addMatcher(decl().bind("decl"), Matcher);
     AstMatcher->addMatcher(lambdaExpr().bind("lambda"), Matcher);
     return AstMatcher->newASTConsumer();
   }
 
   bool ParseArgs(const CompilerInstance &CI,
                  const std::vector<std::string> &Args) override {
     return true;
   }
 
-  ActionType getActionType() override {
-    return AddBeforeMainAction;
-  }
+  ActionType getActionType() override { return AddBeforeMainAction; }
 };
 
-static FrontendPluginRegistry::Add<CustomAttributesAction> X(
-  "moz-custom-attributes",
-  "prepare custom attributes for moz-check");
+static FrontendPluginRegistry::Add<CustomAttributesAction>
+    X("moz-custom-attributes", "prepare custom attributes for moz-check");
--- a/build/clang-plugin/CustomAttributes.h
+++ b/build/clang-plugin/CustomAttributes.h
@@ -10,31 +10,29 @@
 
 enum CustomAttributes {
 #define ATTR(a) a,
 #include "CustomAttributes.inc"
 #undef ATTR
 };
 
 struct CustomAttributesSet {
-#define ATTR(a) bool has_ ## a: 1;
+#define ATTR(a) bool has_##a : 1;
 #include "CustomAttributes.inc"
 #undef ATTR
 };
 
-template<CustomAttributes A>
-bool hasCustomAttribute(const clang::Decl* D) {
+template <CustomAttributes A> bool hasCustomAttribute(const clang::Decl *D) {
   return false;
 }
 
-extern CustomAttributesSet GetAttributes(const clang::Decl* D);
+extern CustomAttributesSet GetAttributes(const clang::Decl *D);
 
-#define ATTR(name) \
-  template<> \
-  inline bool hasCustomAttribute<name>(const clang::Decl* D) { \
-    return GetAttributes(D).has_ ## name; \
+#define ATTR(name)                                                             \
+  template <> inline bool hasCustomAttribute<name>(const clang::Decl *D) {     \
+    return GetAttributes(D).has_##name;                                        \
   }
 #include "CustomAttributes.inc"
 #undef ATTR
 
-extern bool hasCustomAttribute(const clang::Decl* D, CustomAttributes A);
+extern bool hasCustomAttribute(const clang::Decl *D, CustomAttributes A);
 
 #endif /* CustomAttributes_h__ */
--- a/build/clang-plugin/CustomMatchers.h
+++ b/build/clang-plugin/CustomMatchers.h
@@ -219,28 +219,27 @@ AST_MATCHER(CXXConstructorDecl, isIntere
       // We don't want deleted constructors.
       !Declaration->isDeleted();
 }
 
 AST_MATCHER_P(Expr, ignoreTrivials, internal::Matcher<Expr>, InnerMatcher) {
   return InnerMatcher.matches(*IgnoreTrivials(&Node), Finder, Builder);
 }
 
-// Takes two matchers: the first one is a condition; the second is a matcher to be
-// applied once we are done unwrapping trivials.  While the condition does not match
-// and we're looking at a trivial, will keep unwrapping the trivial and trying again.
-// Once the condition matches, we will go ahead and unwrap all trivials and apply the
-// inner matcher to the result.
+// Takes two matchers: the first one is a condition; the second is a matcher to
+// be applied once we are done unwrapping trivials.  While the condition does
+// not match and we're looking at a trivial, will keep unwrapping the trivial
+// and trying again. Once the condition matches, we will go ahead and unwrap all
+// trivials and apply the inner matcher to the result.
 //
-// The expected use here is if we want to condition a match on some typecheck but
-// apply the match to only non-trivials, because there are trivials (e.g. casts) that
-// can change types.
-AST_MATCHER_P2(Expr, ignoreTrivialsConditional,
-               internal::Matcher<Expr>, Condition,
-               internal::Matcher<Expr>, InnerMatcher) {
+// The expected use here is if we want to condition a match on some typecheck
+// but apply the match to only non-trivials, because there are trivials (e.g.
+// casts) that can change types.
+AST_MATCHER_P2(Expr, ignoreTrivialsConditional, internal::Matcher<Expr>,
+               Condition, internal::Matcher<Expr>, InnerMatcher) {
   const Expr *node = &Node;
   while (true) {
     if (Condition.matches(*node, Finder, Builder)) {
       return InnerMatcher.matches(*IgnoreTrivials(node), Finder, Builder);
     }
     const Expr *newNode = MaybeSkipOneTrivial(node);
     if (newNode == node) {
       return false;
@@ -313,27 +312,27 @@ AST_MATCHER(QualType, isSmartPtrToRefCou
   }
 
   D = D->getCanonicalDecl();
 
   return D && hasCustomAttribute<moz_is_smartptr_to_refcounted>(D);
 }
 
 AST_MATCHER(ClassTemplateSpecializationDecl, isSmartPtrToRefCountedDecl) {
-  auto *D = dyn_cast_or_null<CXXRecordDecl>(Node.getSpecializedTemplate()->getTemplatedDecl());
+  auto *D = dyn_cast_or_null<CXXRecordDecl>(
+      Node.getSpecializedTemplate()->getTemplatedDecl());
   if (!D) {
     return false;
   }
 
   D = D->getCanonicalDecl();
 
   return D && hasCustomAttribute<moz_is_smartptr_to_refcounted>(D);
 }
 
-
 AST_MATCHER(CXXRecordDecl, hasBaseClasses) {
   const CXXRecordDecl *Decl = Node.getCanonicalDecl();
 
   // Must have definition and should inherit other classes
   return Decl && Decl->hasDefinition() && Decl->getNumBases();
 }
 
 AST_MATCHER(CXXMethodDecl, isRequiredBaseMethod) {
@@ -343,17 +342,18 @@ AST_MATCHER(CXXMethodDecl, isRequiredBas
 
 AST_MATCHER(CXXMethodDecl, isNonVirtual) {
   const CXXMethodDecl *Decl = Node.getCanonicalDecl();
   return Decl && !Decl->isVirtual();
 }
 
 AST_MATCHER(FunctionDecl, isMozMustReturnFromCaller) {
   const FunctionDecl *Decl = Node.getCanonicalDecl();
-  return Decl && hasCustomAttribute<moz_must_return_from_caller_if_this_is_arg>(Decl);
+  return Decl &&
+         hasCustomAttribute<moz_must_return_from_caller_if_this_is_arg>(Decl);
 }
 
 /// This matcher will select default args which have nullptr as the value.
 AST_MATCHER(CXXDefaultArgExpr, isNullDefaultArg) {
   const Expr *Expr = Node.getExpr();
   return Expr && Expr->isNullPointerConstant(Finder->getASTContext(),
                                              Expr::NPC_NeverValueDependent);
 }
--- a/build/clang-plugin/DanglingOnTemporaryChecker.cpp
+++ b/build/clang-plugin/DanglingOnTemporaryChecker.cpp
@@ -37,45 +37,45 @@ void DanglingOnTemporaryChecker::registe
 
           decl().bind("invalidMethodPointer")),
       this);
 
   //////////////////
   // Main checker //
   //////////////////
 
-  auto hasParentCall = hasParent(expr(
-      anyOf(cxxOperatorCallExpr(
-                // If we're in a lamda, we may have an operator call expression
-                // ancestor in the AST, but the temporary we're matching
-                // against is not going to have the same lifetime as the
-                // constructor call.
-                unless(has(expr(ignoreTrivials(lambdaExpr())))),
-                expr().bind("parentOperatorCallExpr")),
-            callExpr(
-                // If we're in a lamda, we may have a call expression
-                // ancestor in the AST, but the temporary we're matching
-                // against is not going to have the same lifetime as the
-                // function call.
-                unless(has(expr(ignoreTrivials(lambdaExpr())))),
-                expr().bind("parentCallExpr")),
-            objcMessageExpr(
-                // If we're in a lamda, we may have an objc message expression
-                // ancestor in the AST, but the temporary we're matching
-                // against is not going to have the same lifetime as the
-                // function call.
-                unless(has(expr(ignoreTrivials(lambdaExpr())))),
-                expr().bind("parentObjCMessageExpr")),
-            cxxConstructExpr(
-                // If we're in a lamda, we may have a construct expression
-                // ancestor in the AST, but the temporary we're matching
-                // against is not going to have the same lifetime as the
-                // constructor call.
-                unless(has(expr(ignoreTrivials(lambdaExpr())))),
-                expr().bind("parentConstructExpr")))));
+  auto hasParentCall = hasParent(
+      expr(anyOf(cxxOperatorCallExpr(
+                     // If we're in a lamda, we may have an operator call
+                     // expression ancestor in the AST, but the temporary we're
+                     // matching against is not going to have the same lifetime
+                     // as the constructor call.
+                     unless(has(expr(ignoreTrivials(lambdaExpr())))),
+                     expr().bind("parentOperatorCallExpr")),
+                 callExpr(
+                     // If we're in a lamda, we may have a call expression
+                     // ancestor in the AST, but the temporary we're matching
+                     // against is not going to have the same lifetime as the
+                     // function call.
+                     unless(has(expr(ignoreTrivials(lambdaExpr())))),
+                     expr().bind("parentCallExpr")),
+                 objcMessageExpr(
+                     // If we're in a lamda, we may have an objc message
+                     // expression ancestor in the AST, but the temporary we're
+                     // matching against is not going to have the same lifetime
+                     // as the function call.
+                     unless(has(expr(ignoreTrivials(lambdaExpr())))),
+                     expr().bind("parentObjCMessageExpr")),
+                 cxxConstructExpr(
+                     // If we're in a lamda, we may have a construct expression
+                     // ancestor in the AST, but the temporary we're matching
+                     // against is not going to have the same lifetime as the
+                     // constructor call.
+                     unless(has(expr(ignoreTrivials(lambdaExpr())))),
+                     expr().bind("parentConstructExpr")))));
 
   AstMatcher->addMatcher(
       // This is a matcher on a method call,
       cxxMemberCallExpr(
           // which is in first party code,
           isFirstParty(),
 
           // and which is performed on a temporary,
--- a/build/clang-plugin/DiagnosticsMatcher.h
+++ b/build/clang-plugin/DiagnosticsMatcher.h
@@ -9,15 +9,15 @@
 
 class DiagnosticsMatcher {
 public:
   DiagnosticsMatcher(CompilerInstance &CI);
 
   ASTConsumerPtr makeASTConsumer() { return AstMatcher.newASTConsumer(); }
 
 private:
-#define CHECK(cls, name) cls cls##_ { name };
+#define CHECK(cls, name) cls cls##_{name};
 #include "Checks.inc"
 #undef CHECK
   MatchFinder AstMatcher;
 };
 
 #endif
--- a/build/clang-plugin/ExplicitOperatorBoolChecker.cpp
+++ b/build/clang-plugin/ExplicitOperatorBoolChecker.cpp
@@ -16,18 +16,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->isExplicit() &&
-      !hasCustomAttribute<moz_implicit>(Method) &&
+  if (!Method->isExplicit() && !hasCustomAttribute<moz_implicit>(Method) &&
       !ASTIsInSystemHeader(Method->getASTContext(), *Method) &&
       isInterestingDeclForImplicitConversion(Method)) {
     diag(Method->getBeginLoc(), "bad implicit conversion operator for %0",
          DiagnosticIDs::Error)
         << Clazz;
     diag(Method->getBeginLoc(), "consider adding the explicit keyword to %0",
          DiagnosticIDs::Note)
         << "'operator bool'";
--- a/build/clang-plugin/FopenUsageChecker.h
+++ b/build/clang-plugin/FopenUsageChecker.h
@@ -4,16 +4,15 @@
 
 #ifndef FopenUsageChecker_h__
 #define FopenUsageChecker_h__
 
 #include "plugin.h"
 
 class FopenUsageChecker : public BaseCheck {
 public:
-  FopenUsageChecker(StringRef CheckName,
-                     ContextType *Context = nullptr)
-    : BaseCheck(CheckName, Context) {}
-  void registerMatchers(MatchFinder* AstMatcher) override;
+  FopenUsageChecker(StringRef CheckName, ContextType *Context = nullptr)
+      : BaseCheck(CheckName, Context) {}
+  void registerMatchers(MatchFinder *AstMatcher) override;
   void check(const MatchFinder::MatchResult &Result) override;
 };
 
 #endif
--- a/build/clang-plugin/KungFuDeathGripChecker.cpp
+++ b/build/clang-plugin/KungFuDeathGripChecker.cpp
@@ -1,18 +1,17 @@
 /* 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 "KungFuDeathGripChecker.h"
 #include "CustomMatchers.h"
 
 void KungFuDeathGripChecker::registerMatchers(MatchFinder *AstMatcher) {
-  AstMatcher->addMatcher(varDecl(allOf(hasType(isRefPtr()),
-                                       hasLocalStorage(),
+  AstMatcher->addMatcher(varDecl(allOf(hasType(isRefPtr()), hasLocalStorage(),
                                        hasInitializer(anything())))
                              .bind("decl"),
                          this);
 }
 
 void KungFuDeathGripChecker::check(const MatchFinder::MatchResult &Result) {
   const char *Error = "Unused \"kungFuDeathGrip\" %0 objects constructed from "
                       "%1 are prohibited";
--- a/build/clang-plugin/MustReturnFromCallerChecker.cpp
+++ b/build/clang-plugin/MustReturnFromCallerChecker.cpp
@@ -4,20 +4,20 @@
 
 #include "MustReturnFromCallerChecker.h"
 #include "CustomMatchers.h"
 
 void MustReturnFromCallerChecker::registerMatchers(MatchFinder *AstMatcher) {
   // Look for a call to a MOZ_MUST_RETURN_FROM_CALLER member
   AstMatcher->addMatcher(
       cxxMemberCallExpr(
-              on(declRefExpr(to(parmVarDecl()))),
-              callee(functionDecl(isMozMustReturnFromCaller())),
-              anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
-                    hasAncestor(functionDecl().bind("containing-func"))))
+          on(declRefExpr(to(parmVarDecl()))),
+          callee(functionDecl(isMozMustReturnFromCaller())),
+          anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
+                hasAncestor(functionDecl().bind("containing-func"))))
           .bind("call"),
       this);
 }
 
 void MustReturnFromCallerChecker::check(
     const MatchFinder::MatchResult &Result) {
   const auto *ContainingLambda =
       Result.Nodes.getNodeAs<LambdaExpr>("containing-lambda");
--- a/build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.cpp
+++ b/build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.cpp
@@ -1,25 +1,24 @@
 /* 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 "NoUsingNamespaceMozillaJavaChecker.h"
 #include "CustomMatchers.h"
 
-void NoUsingNamespaceMozillaJavaChecker::registerMatchers(MatchFinder *AstMatcher) {
+void NoUsingNamespaceMozillaJavaChecker::registerMatchers(
+    MatchFinder *AstMatcher) {
   AstMatcher->addMatcher(
       usingDirectiveDecl(isUsingNamespaceMozillaJava()).bind("directive"),
       this);
 }
 
 void NoUsingNamespaceMozillaJavaChecker::check(
     const MatchFinder::MatchResult &Result) {
   const UsingDirectiveDecl *Directive =
       Result.Nodes.getNodeAs<UsingDirectiveDecl>("directive");
   const NamespaceDecl *Namespace = Directive->getNominatedNamespace();
 
-  diag(Directive->getUsingLoc(),
-       "using namespace %0 is forbidden",
+  diag(Directive->getUsingLoc(), "using namespace %0 is forbidden",
        DiagnosticIDs::Error)
       << Namespace->getQualifiedNameAsString();
 }
-
--- a/build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.h
+++ b/build/clang-plugin/NoUsingNamespaceMozillaJavaChecker.h
@@ -5,16 +5,15 @@
 #ifndef NoUsingNamespaceMozillaJavaChecker_h__
 #define NoUsingNamespaceMozillaJavaChecker_h__
 
 #include "plugin.h"
 
 class NoUsingNamespaceMozillaJavaChecker : public BaseCheck {
 public:
   NoUsingNamespaceMozillaJavaChecker(StringRef CheckName,
-                                 ContextType *Context = nullptr)
+                                     ContextType *Context = nullptr)
       : BaseCheck(CheckName, Context) {}
   void registerMatchers(MatchFinder *AstMatcher) override;
   void check(const MatchFinder::MatchResult &Result) override;
 };
 
 #endif
-
--- a/build/clang-plugin/ParamTraitsEnumChecker.cpp
+++ b/build/clang-plugin/ParamTraitsEnumChecker.cpp
@@ -1,26 +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 "ParamTraitsEnumChecker.h"
 #include "CustomMatchers.h"
 
-void ParamTraitsEnumChecker::registerMatchers(MatchFinder* AstMatcher) {
+void ParamTraitsEnumChecker::registerMatchers(MatchFinder *AstMatcher) {
   AstMatcher->addMatcher(
-    classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"), this);
+      classTemplateSpecializationDecl(hasName("ParamTraits")).bind("decl"),
+      this);
 }
 
 void ParamTraitsEnumChecker::check(const MatchFinder::MatchResult &Result) {
   const ClassTemplateSpecializationDecl *Decl =
-    Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl");
+      Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("decl");
 
-  for (auto& Inner : Decl->decls()) {
-    if (auto* Def = dyn_cast<TypedefDecl>(Inner)) {
+  for (auto &Inner : Decl->decls()) {
+    if (auto *Def = dyn_cast<TypedefDecl>(Inner)) {
       QualType UnderlyingType = Def->getUnderlyingType();
       QualType CanonicalType = UnderlyingType.getCanonicalType();
 
       const clang::Type *TypePtr = CanonicalType.getTypePtrOrNull();
       if (!TypePtr) {
         return;
       }
 
--- a/build/clang-plugin/ParamTraitsEnumChecker.h
+++ b/build/clang-plugin/ParamTraitsEnumChecker.h
@@ -4,16 +4,15 @@
 
 #ifndef ParamTraitsEnumChecker_h__
 #define ParamTraitsEnumChecker_h__
 
 #include "plugin.h"
 
 class ParamTraitsEnumChecker : public BaseCheck {
 public:
-  ParamTraitsEnumChecker(StringRef CheckName,
-                         ContextType *Context = nullptr)
-    : BaseCheck(CheckName, Context) {}
-  void registerMatchers(MatchFinder* AstMatcher) override;
+  ParamTraitsEnumChecker(StringRef CheckName, ContextType *Context = nullptr)
+      : BaseCheck(CheckName, Context) {}
+  void registerMatchers(MatchFinder *AstMatcher) override;
   void check(const MatchFinder::MatchResult &Result) override;
 };
 
 #endif
--- a/build/clang-plugin/ScopeChecker.cpp
+++ b/build/clang-plugin/ScopeChecker.cpp
@@ -5,18 +5,19 @@
 #include "ScopeChecker.h"
 #include "CustomMatchers.h"
 
 void ScopeChecker::registerMatchers(MatchFinder *AstMatcher) {
   AstMatcher->addMatcher(varDecl().bind("node"), this);
   AstMatcher->addMatcher(cxxNewExpr().bind("node"), this);
   AstMatcher->addMatcher(
       materializeTemporaryExpr(
-          unless(hasDescendant(cxxConstructExpr(allowsTemporary())))
-      ).bind("node"), this);
+          unless(hasDescendant(cxxConstructExpr(allowsTemporary()))))
+          .bind("node"),
+      this);
   AstMatcher->addMatcher(
       callExpr(callee(functionDecl(heapAllocator()))).bind("node"), this);
 }
 
 // These enum variants determine whether an allocation has occured in the code.
 enum AllocationVariety {
   AV_None,
   AV_Global,
@@ -34,18 +35,17 @@ AutomaticTemporaryMap AutomaticTemporari
 
 void ScopeChecker::check(const MatchFinder::MatchResult &Result) {
   // There are a variety of different reasons why something could be allocated
   AllocationVariety Variety = AV_None;
   SourceLocation Loc;
   QualType T;
   bool IsStaticLocal = false;
 
-  if (const ParmVarDecl *D =
-          Result.Nodes.getNodeAs<ParmVarDecl>("node")) {
+  if (const ParmVarDecl *D = Result.Nodes.getNodeAs<ParmVarDecl>("node")) {
     if (D->hasUnparsedDefaultArg() || D->hasUninstantiatedDefaultArg()) {
       return;
     }
     if (const Expr *Default = D->getDefaultArg()) {
       if (const MaterializeTemporaryExpr *E =
               dyn_cast<MaterializeTemporaryExpr>(Default)) {
         // We have just found a ParmVarDecl which has, as its default argument,
         // a MaterializeTemporaryExpr. We mark that MaterializeTemporaryExpr as
--- a/build/clang-plugin/TrivialDtorChecker.cpp
+++ b/build/clang-plugin/TrivialDtorChecker.cpp
@@ -1,18 +1,17 @@
 /* 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 "TrivialDtorChecker.h"
 #include "CustomMatchers.h"
 
 void TrivialDtorChecker::registerMatchers(MatchFinder *AstMatcher) {
-  AstMatcher->addMatcher(cxxRecordDecl(hasTrivialDtor()).bind("node"),
-                         this);
+  AstMatcher->addMatcher(cxxRecordDecl(hasTrivialDtor()).bind("node"), this);
 }
 
 void TrivialDtorChecker::check(const MatchFinder::MatchResult &Result) {
   const char *Error = "class %0 must have a trivial destructor";
   const CXXRecordDecl *Node = Result.Nodes.getNodeAs<CXXRecordDecl>("node");
 
   if (!Node->hasDefinition()) {
     return;
--- a/build/clang-plugin/Utils.h
+++ b/build/clang-plugin/Utils.h
@@ -288,47 +288,47 @@ inline bool typeIsRefPtr(QualType Q) {
   }
   return false;
 }
 
 // The method defined in clang for ignoring implicit nodes doesn't work with
 // some AST trees. To get around this, we define our own implementation of
 // IgnoreTrivials.
 inline const Stmt *MaybeSkipOneTrivial(const Stmt *s) {
-    if (!s) {
-      return nullptr;
-    }
-    if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) {
-      return ewc->getSubExpr();
-    }
-    if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) {
-      // With clang 10 and up `getTemporary` has been replaced with the more
-      // versatile `getSubExpr`.
+  if (!s) {
+    return nullptr;
+  }
+  if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) {
+    return ewc->getSubExpr();
+  }
+  if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) {
+    // With clang 10 and up `getTemporary` has been replaced with the more
+    // versatile `getSubExpr`.
 #if CLANG_VERSION_FULL >= 1000
-      return mte->getSubExpr();
+    return mte->getSubExpr();
 #else
-      return mte->GetTemporaryExpr();
+    return mte->GetTemporaryExpr();
 #endif
-    }
-    if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) {
-      return bte->getSubExpr();
-    }
-    if (auto *ce = dyn_cast<CastExpr>(s)) {
-      s = ce->getSubExpr();
-    }
-    if (auto *pe = dyn_cast<ParenExpr>(s)) {
-      s = pe->getSubExpr();
-    }
-    // Not a trivial.
-    return s;
+  }
+  if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) {
+    return bte->getSubExpr();
+  }
+  if (auto *ce = dyn_cast<CastExpr>(s)) {
+    s = ce->getSubExpr();
+  }
+  if (auto *pe = dyn_cast<ParenExpr>(s)) {
+    s = pe->getSubExpr();
+  }
+  // Not a trivial.
+  return s;
 }
 
 inline const Stmt *IgnoreTrivials(const Stmt *s) {
   while (true) {
-    const Stmt* newS = MaybeSkipOneTrivial(s);
+    const Stmt *newS = MaybeSkipOneTrivial(s);
     if (newS == s) {
       return newS;
     }
     s = newS;
   }
 
   // Unreachable
   return nullptr;