--- a/build/clang-plugin/ArithmeticArgChecker.cpp
+++ b/build/clang-plugin/ArithmeticArgChecker.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 "ArithmeticArgChecker.h"
#include "CustomMatchers.h"
-void ArithmeticArgChecker::registerMatchers(MatchFinder* AstMatcher) {
+void ArithmeticArgChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
callExpr(allOf(hasDeclaration(noArithmeticExprInArgs()),
anyOf(hasDescendant(
binaryOperator(
allOf(binaryArithmeticOperator(),
hasLHS(hasDescendant(declRefExpr())),
hasRHS(hasDescendant(declRefExpr()))))
.bind("node")),
@@ -40,19 +40,21 @@ void ArithmeticArgChecker::registerMatch
hasType(builtinType()),
anyOf(hasDescendant(declRefExpr()),
declRefExpr())))))
.bind("node")))))
.bind("call"),
this);
}
-void ArithmeticArgChecker::check(
- const MatchFinder::MatchResult &Result) {
- const char* Error = "cannot pass an arithmetic expression of built-in types to %0";
+void ArithmeticArgChecker::check(const MatchFinder::MatchResult &Result) {
+ const char *Error =
+ "cannot pass an arithmetic expression of built-in types to %0";
const Expr *Expression = Result.Nodes.getNodeAs<Expr>("node");
if (const CallExpr *Call = Result.Nodes.getNodeAs<CallExpr>("call")) {
- diag(Expression->getLocStart(), Error, DiagnosticIDs::Error) << Call->getDirectCallee();
+ diag(Expression->getLocStart(), Error, DiagnosticIDs::Error)
+ << Call->getDirectCallee();
} else if (const CXXConstructExpr *Ctr =
Result.Nodes.getNodeAs<CXXConstructExpr>("call")) {
- diag(Expression->getLocStart(), Error, DiagnosticIDs::Error) << Ctr->getConstructor();
+ diag(Expression->getLocStart(), Error, DiagnosticIDs::Error)
+ << Ctr->getConstructor();
}
}
--- a/build/clang-plugin/ArithmeticArgChecker.h
+++ b/build/clang-plugin/ArithmeticArgChecker.h
@@ -4,16 +4,15 @@
#ifndef ArithmeticArgChecker_h__
#define ArithmeticArgChecker_h__
#include "plugin.h"
class ArithmeticArgChecker : public BaseCheck {
public:
- ArithmeticArgChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ ArithmeticArgChecker(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/AssertAssignmentChecker.cpp
+++ b/build/clang-plugin/AssertAssignmentChecker.cpp
@@ -1,23 +1,20 @@
/* 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 "AssertAssignmentChecker.h"
#include "CustomMatchers.h"
-void AssertAssignmentChecker::registerMatchers(MatchFinder* AstMatcher) {
+void AssertAssignmentChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
- callExpr(isAssertAssignmentTestFunc()).bind("funcCall"),
- this);
+ callExpr(isAssertAssignmentTestFunc()).bind("funcCall"), this);
}
-void AssertAssignmentChecker::check(
- const MatchFinder::MatchResult &Result) {
+void AssertAssignmentChecker::check(const MatchFinder::MatchResult &Result) {
const CallExpr *FuncCall = Result.Nodes.getNodeAs<CallExpr>("funcCall");
if (FuncCall && hasSideEffectAssignment(FuncCall)) {
- diag(FuncCall->getLocStart(),
- "Forbidden assignment in assert expression",
+ diag(FuncCall->getLocStart(), "Forbidden assignment in assert expression",
DiagnosticIDs::Error);
}
}
--- a/build/clang-plugin/AssertAssignmentChecker.h
+++ b/build/clang-plugin/AssertAssignmentChecker.h
@@ -4,16 +4,15 @@
#ifndef AssertAssignmentChecker_h__
#define AssertAssignmentChecker_h__
#include "plugin.h"
class AssertAssignmentChecker : public BaseCheck {
public:
- AssertAssignmentChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ AssertAssignmentChecker(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/BaseCheck.h
+++ b/build/clang-plugin/BaseCheck.h
@@ -5,30 +5,30 @@
#ifndef BaseCheck_h__
#define BaseCheck_h__
class MozContext {};
typedef MozContext ContextType;
class BaseCheck : public MatchFinder::MatchCallback {
public:
- BaseCheck(StringRef CheckName, ContextType* Context) {}
+ BaseCheck(StringRef CheckName, ContextType *Context) {}
virtual void registerMatchers(MatchFinder *Finder) {}
- virtual void registerPPCallbacks(CompilerInstance& CI) {}
+ virtual void registerPPCallbacks(CompilerInstance &CI) {}
virtual void check(const MatchFinder::MatchResult &Result) {}
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
DiagnosticIDs::Level Level = DiagnosticIDs::Warning) {
DiagnosticsEngine &Diag = Context->getDiagnostics();
unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(Level, Description);
return Diag.Report(Loc, ID);
}
private:
void run(const MatchFinder::MatchResult &Result) override {
Context = Result.Context;
check(Result);
}
private:
- ASTContext* Context;
+ ASTContext *Context;
};
#endif
--- a/build/clang-plugin/CanRunScriptChecker.cpp
+++ b/build/clang-plugin/CanRunScriptChecker.cpp
@@ -1,204 +1,195 @@
/* 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 "CanRunScriptChecker.h"
#include "CustomMatchers.h"
-void CanRunScriptChecker::registerMatchers(MatchFinder* AstMatcher) {
+void CanRunScriptChecker::registerMatchers(MatchFinder *AstMatcher) {
auto InvalidArg =
// We want to find any expression,
ignoreTrivials(expr(
// which has a refcounted pointer type,
hasType(pointerType(
pointee(hasDeclaration(cxxRecordDecl(isRefCounted()))))),
// and which is not this,
unless(cxxThisExpr()),
// and which is not a method call on a smart ptr,
unless(cxxMemberCallExpr(on(hasType(isSmartPtrToRefCounted())))),
// and which is not a parameter of the parent function,
unless(declRefExpr(to(parmVarDecl()))),
// and which is not a MOZ_KnownLive wrapped value.
- unless(callExpr(callee(
- functionDecl(hasName("MOZ_KnownLive"))))),
+ unless(callExpr(callee(functionDecl(hasName("MOZ_KnownLive"))))),
expr().bind("invalidArg")));
- auto OptionalInvalidExplicitArg =
- anyOf(
- // We want to find any argument which is invalid.
- hasAnyArgument(InvalidArg),
+ auto OptionalInvalidExplicitArg = anyOf(
+ // We want to find any argument which is invalid.
+ hasAnyArgument(InvalidArg),
- // This makes this matcher optional.
- anything());
+ // This makes this matcher optional.
+ anything());
// Please not that the hasCanRunScriptAnnotation() matchers are not present
// directly in the cxxMemberCallExpr, callExpr and constructExpr matchers
// because we check that the corresponding functions can run script later in
// the checker code.
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 implicit this argument,
anyOf(
// which derefs into an invalid arg,
on(cxxOperatorCallExpr(
- anyOf(
- hasAnyArgument(InvalidArg),
- anything()))),
+ anyOf(hasAnyArgument(InvalidArg), anything()))),
// or is an invalid arg.
on(InvalidArg),
anything()),
expr().bind("callExpr")),
// or a regular call expression,
callExpr(
// which optionally has an invalid arg.
- OptionalInvalidExplicitArg,
- expr().bind("callExpr")),
+ OptionalInvalidExplicitArg, expr().bind("callExpr")),
// or a construct expression,
cxxConstructExpr(
// which optionally has an invalid arg.
- OptionalInvalidExplicitArg,
- expr().bind("constructExpr"))),
+ OptionalInvalidExplicitArg, expr().bind("constructExpr"))),
anyOf(
// We want to match the parent function.
forFunction(functionDecl().bind("nonCanRunScriptParentFunction")),
// ... optionally.
anything())),
this);
}
void CanRunScriptChecker::onStartOfTranslationUnit() {
IsFuncSetBuilt = false;
CanRunScriptFuncs.clear();
}
namespace {
- /// This class is a callback used internally to match function declarations
- /// with the MOZ_CAN_RUN_SCRIPT annotation, adding these functions and all
- /// the methods they override to the can-run-script function set.
- class FuncSetCallback : public MatchFinder::MatchCallback {
- public:
- FuncSetCallback(std::unordered_set<const FunctionDecl*> &FuncSet)
+/// This class is a callback used internally to match function declarations
+/// with the MOZ_CAN_RUN_SCRIPT annotation, adding these functions and all
+/// the methods they override to the can-run-script function set.
+class FuncSetCallback : public MatchFinder::MatchCallback {
+public:
+ FuncSetCallback(std::unordered_set<const FunctionDecl *> &FuncSet)
: CanRunScriptFuncs(FuncSet) {}
- void run(const MatchFinder::MatchResult &Result) override;
+ void run(const MatchFinder::MatchResult &Result) override;
- private:
- /// This method recursively adds all the methods overriden by the given
- /// paremeter.
- void addAllOverriddenMethodsRecursively(const CXXMethodDecl* Method);
+private:
+ /// This method recursively adds all the methods overriden by the given
+ /// paremeter.
+ void addAllOverriddenMethodsRecursively(const CXXMethodDecl *Method);
- std::unordered_set<const FunctionDecl*> &CanRunScriptFuncs;
- };
+ std::unordered_set<const FunctionDecl *> &CanRunScriptFuncs;
+};
- void FuncSetCallback::run(const MatchFinder::MatchResult &Result) {
- const FunctionDecl* Func =
+void FuncSetCallback::run(const MatchFinder::MatchResult &Result) {
+ const FunctionDecl *Func =
Result.Nodes.getNodeAs<FunctionDecl>("canRunScriptFunction");
- CanRunScriptFuncs.insert(Func);
+ CanRunScriptFuncs.insert(Func);
- // If this is a method, we check the methods it overrides.
- if (auto* Method = dyn_cast<CXXMethodDecl>(Func)) {
- addAllOverriddenMethodsRecursively(Method);
- }
+ // If this is a method, we check the methods it overrides.
+ if (auto *Method = dyn_cast<CXXMethodDecl>(Func)) {
+ addAllOverriddenMethodsRecursively(Method);
}
+}
- void FuncSetCallback::addAllOverriddenMethodsRecursively(
- const CXXMethodDecl* Method) {
- for (auto OverriddenMethod : Method->overridden_methods()) {
- CanRunScriptFuncs.insert(OverriddenMethod);
+void FuncSetCallback::addAllOverriddenMethodsRecursively(
+ const CXXMethodDecl *Method) {
+ for (auto OverriddenMethod : Method->overridden_methods()) {
+ CanRunScriptFuncs.insert(OverriddenMethod);
- // If this is not the definition, we also add the definition (if it
- // exists) to the set.
- if (!OverriddenMethod->isThisDeclarationADefinition()) {
- if (auto Def = OverriddenMethod->getDefinition()) {
- CanRunScriptFuncs.insert(Def);
- }
+ // If this is not the definition, we also add the definition (if it
+ // exists) to the set.
+ if (!OverriddenMethod->isThisDeclarationADefinition()) {
+ if (auto Def = OverriddenMethod->getDefinition()) {
+ CanRunScriptFuncs.insert(Def);
}
+ }
- addAllOverriddenMethodsRecursively(OverriddenMethod);
- }
+ addAllOverriddenMethodsRecursively(OverriddenMethod);
}
+}
} // 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(CanRunScriptFuncs);
// We add the matcher to the finder, linking it to our callback.
- Finder.addMatcher(functionDecl(hasCanRunScriptAnnotation())
- .bind("canRunScriptFunction"),
- &Callback);
+ Finder.addMatcher(
+ functionDecl(hasCanRunScriptAnnotation()).bind("canRunScriptFunction"),
+ &Callback);
// We start the analysis, given the ASTContext our main checker is in.
Finder.matchAST(*Context);
}
-void CanRunScriptChecker::check(
- const MatchFinder::MatchResult &Result) {
+void CanRunScriptChecker::check(const MatchFinder::MatchResult &Result) {
// If the set of functions which can run script is not yet built, then build
// it.
if (!IsFuncSetBuilt) {
buildFuncSet(Result.Context);
IsFuncSetBuilt = true;
}
- const char* ErrorInvalidArg =
+ const char *ErrorInvalidArg =
"arguments must all be strong refs or parent parameters when calling a "
"function marked as MOZ_CAN_RUN_SCRIPT (including the implicit object "
"argument)";
- const char* ErrorNonCanRunScriptParent =
+ 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 =
- "parent function declared here";
+ const char *NoteNonCanRunScriptParent = "parent function declared here";
- const Expr* InvalidArg = Result.Nodes.getNodeAs<Expr>("invalidArg");
+ const Expr *InvalidArg = Result.Nodes.getNodeAs<Expr>("invalidArg");
- const CallExpr* Call = Result.Nodes.getNodeAs<CallExpr>("callExpr");
+ 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
// as can-run-script, consider that we didn't find a match.
if (Call && (!Call->getDirectCallee() ||
- !CanRunScriptFuncs.count(Call->getDirectCallee()))) {
+ !CanRunScriptFuncs.count(Call->getDirectCallee()))) {
Call = nullptr;
}
- const CXXConstructExpr* Construct =
+ const CXXConstructExpr *Construct =
Result.Nodes.getNodeAs<CXXConstructExpr>("constructExpr");
// If we don't find the CXXConstructorDecl linked to this construct expression
// or if it's not marked as can-run-script, consider that we didn't find a
// match.
if (Construct && (!Construct->getConstructor() ||
- !CanRunScriptFuncs.count(Construct->getConstructor()))) {
+ !CanRunScriptFuncs.count(Construct->getConstructor()))) {
Construct = nullptr;
}
- const FunctionDecl* ParentFunction =
+ const FunctionDecl *ParentFunction =
Result.Nodes.getNodeAs<FunctionDecl>("nonCanRunScriptParentFunction");
// If the parent function can run script, consider that we didn't find a match
// because we only care about parent functions which can't run script.
if (ParentFunction && CanRunScriptFuncs.count(ParentFunction)) {
ParentFunction = nullptr;
}
-
// Get the call range from either the CallExpr or the ConstructExpr.
SourceRange CallRange;
if (Call) {
CallRange = Call->getSourceRange();
} else if (Construct) {
CallRange = Construct->getSourceRange();
} else {
// If we have neither a Call nor a Construct, we have nothing do to here.
--- a/build/clang-plugin/CanRunScriptChecker.h
+++ b/build/clang-plugin/CanRunScriptChecker.h
@@ -5,28 +5,27 @@
#ifndef CanRunScriptChecker_h__
#define CanRunScriptChecker_h__
#include "plugin.h"
#include <unordered_set>
class CanRunScriptChecker : public BaseCheck {
public:
- CanRunScriptChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ CanRunScriptChecker(StringRef CheckName, ContextType *Context = nullptr)
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
// Simply initialize the can-run-script function set at the beginning of each
// translation unit.
void onStartOfTranslationUnit() override;
private:
/// Runs the inner matcher on the AST to find all the can-run-script
/// functions using custom rules (not only the annotation).
void buildFuncSet(ASTContext *Context);
bool IsFuncSetBuilt;
- std::unordered_set<const FunctionDecl*> CanRunScriptFuncs;
+ std::unordered_set<const FunctionDecl *> CanRunScriptFuncs;
};
#endif
--- a/build/clang-plugin/CustomMatchers.h
+++ b/build/clang-plugin/CustomMatchers.h
@@ -34,17 +34,17 @@ AST_MATCHER(CXXMethodDecl, isLValueRefQu
return Node.getRefQualifier() == RQ_LValue;
}
/// This matcher will match rvalue-ref-qualified methods.
AST_MATCHER(CXXMethodDecl, isRValueRefQualified) {
return Node.getRefQualifier() == RQ_RValue;
}
-AST_POLYMORPHIC_MATCHER(isFirstParty, \
+AST_POLYMORPHIC_MATCHER(isFirstParty,
AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt)) {
return !inThirdPartyPath(&Node, &Finder->getASTContext()) &&
!ASTIsInSystemHeader(Finder->getASTContext(), Node);
}
/// This matcher will match temporary expressions.
/// We need this matcher for compatibility with clang 3.* (clang 4 and above
/// insert a MaterializeTemporaryExpr everywhere).
@@ -299,33 +299,33 @@ AST_MATCHER(FunctionDecl, isMozMustRetur
/// matches 'return *this'
/// but does match 'return > 0'
AST_MATCHER_P(Stmt, forFunction, internal::Matcher<FunctionDecl>,
InnerMatcher) {
const auto &Parents = Finder->getASTContext().getParents(Node);
llvm::SmallVector<ast_type_traits::DynTypedNode, 8> Stack(Parents.begin(),
Parents.end());
- while(!Stack.empty()) {
+ while (!Stack.empty()) {
const auto &CurNode = Stack.back();
Stack.pop_back();
- if(const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) {
- if(InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) {
+ if (const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) {
+ if (InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) {
return true;
}
- } else if(const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) {
- if(InnerMatcher.matches(*LambdaExprNode->getCallOperator(),
- Finder, Builder)) {
+ } else if (const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) {
+ if (InnerMatcher.matches(*LambdaExprNode->getCallOperator(), Finder,
+ Builder)) {
return true;
}
} else {
- for(const auto &Parent: Finder->getASTContext().getParents(CurNode))
+ for (const auto &Parent : Finder->getASTContext().getParents(CurNode))
Stack.push_back(Parent);
}
}
return false;
}
#endif
-}
-}
+} // namespace ast_matchers
+} // namespace clang
#endif
--- a/build/clang-plugin/CustomTypeAnnotation.cpp
+++ b/build/clang-plugin/CustomTypeAnnotation.cpp
@@ -6,67 +6,62 @@
#include "Utils.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 HeapClass = CustomTypeAnnotation("moz_heap_class", "heap");
CustomTypeAnnotation NonTemporaryClass =
CustomTypeAnnotation("moz_non_temporary_class", "non-temporary");
-void CustomTypeAnnotation::dumpAnnotationReason(BaseCheck &Check,
- QualType T,
+void CustomTypeAnnotation::dumpAnnotationReason(BaseCheck &Check, QualType T,
SourceLocation Loc) {
- const char* Inherits =
+ 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 =
- "%1 is a %0 type because it is an array of %0 type %2";
- const char* Templ =
+ const char *Member = "%1 is a %0 type because member %2 is a %0 type %3";
+ const char *Array = "%1 is a %0 type because it is an array of %0 type %2";
+ const char *Templ =
"%1 is a %0 type because it has a template argument %0 type %2";
- const char* Implicit =
- "%1 is a %0 type because %2";
+ const char *Implicit = "%1 is a %0 type because %2";
AnnotationReason Reason = directAnnotationReason(T);
for (;;) {
switch (Reason.Kind) {
case RK_ArrayElement:
Check.diag(Loc, Array, DiagnosticIDs::Note) << Pretty << T << Reason.Type;
break;
case RK_BaseClass: {
const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
assert(Declaration && "This type should be a C++ class");
Check.diag(Declaration->getLocation(), Inherits, DiagnosticIDs::Note)
- << Pretty << T << Reason.Type;
+ << Pretty << T << Reason.Type;
break;
}
case RK_Field:
Check.diag(Reason.Field->getLocation(), Member, DiagnosticIDs::Note)
<< Pretty << T << Reason.Field << Reason.Type;
break;
case RK_TemplateInherited: {
const CXXRecordDecl *Declaration = T->getAsCXXRecordDecl();
assert(Declaration && "This type should be a C++ class");
Check.diag(Declaration->getLocation(), Templ, DiagnosticIDs::Note)
- << Pretty << T << Reason.Type;
+ << Pretty << T << Reason.Type;
break;
}
case RK_Implicit: {
const TagDecl *Declaration = T->getAsTagDecl();
assert(Declaration && "This type should be a TagDecl");
Check.diag(Declaration->getLocation(), Implicit, DiagnosticIDs::Note)
- << Pretty << T << Reason.ImplicitReason;
+ << Pretty << T << Reason.ImplicitReason;
return;
}
default:
// FIXME (bug 1203263): note the original annotation.
return;
}
T = Reason.Type;
--- a/build/clang-plugin/CustomTypeAnnotation.h
+++ b/build/clang-plugin/CustomTypeAnnotation.h
@@ -36,22 +36,20 @@ 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(BaseCheck &Check, 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) {
+ void reportErrorIfPresent(BaseCheck &Check, QualType T, SourceLocation Loc,
+ const char *Error, const char *Note) {
if (hasEffectiveAnnotation(T)) {
Check.diag(Loc, Error, DiagnosticIDs::Error) << T;
Check.diag(Loc, Note, DiagnosticIDs::Note);
dumpAnnotationReason(Check, T, Loc);
}
}
private:
--- a/build/clang-plugin/DanglingOnTemporaryChecker.cpp
+++ b/build/clang-plugin/DanglingOnTemporaryChecker.cpp
@@ -37,78 +37,73 @@ 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,
- on(allOf(
- unless(hasType(pointerType())),
- isTemporary(),
- // but which is not `this`.
- unless(cxxThisExpr()))),
+ on(allOf(unless(hasType(pointerType())), isTemporary(),
+ // but which is not `this`.
+ unless(cxxThisExpr()))),
// and which is marked as no dangling on temporaries.
callee(cxxMethodDecl(noDanglingOnTemporaries())),
expr().bind("memberCallExpr"),
// We optionally match a parent call expression or a parent construct
// expression because using a temporary inside a call is fine as long
// as the pointer doesn't escape the function call.
anyOf(
// This is the case where the call is the direct parent, so we
// know that the member call expression is the argument.
allOf(hasParentCall, expr().bind("parentCallArg")),
// This is the case where the call is not the direct parent, so we
// get its child to know in which argument tree we are.
- hasAncestor(expr(
- hasParentCall,
- expr().bind("parentCallArg"))),
+ hasAncestor(expr(hasParentCall, expr().bind("parentCallArg"))),
// To make it optional.
anything())),
this);
}
void DanglingOnTemporaryChecker::check(const MatchFinder::MatchResult &Result) {
///////////////////////////////////////
// Quick annotation conflict checker //
@@ -158,51 +153,50 @@ void DanglingOnTemporaryChecker::check(c
Result.Nodes.getNodeAs<CXXMemberCallExpr>("memberCallExpr");
const CallExpr *ParentCallExpr =
Result.Nodes.getNodeAs<CallExpr>("parentCallExpr");
const CXXConstructExpr *ParentConstructExpr =
Result.Nodes.getNodeAs<CXXConstructExpr>("parentConstructExpr");
const CXXOperatorCallExpr *ParentOperatorCallExpr =
Result.Nodes.getNodeAs<CXXOperatorCallExpr>("parentOperatorCallExpr");
- const Expr *ParentCallArg =
- Result.Nodes.getNodeAs<Expr>("parentCallArg");
+ const Expr *ParentCallArg = Result.Nodes.getNodeAs<Expr>("parentCallArg");
// Just in case.
if (!MemberCall) {
return;
}
// If we have a parent call, we check whether or not we escape the function
// being called.
if (ParentOperatorCallExpr || ParentCallExpr || ParentConstructExpr) {
// Just in case.
if (!ParentCallArg) {
return;
}
// No default constructor so we can't construct it using if/else.
- auto FunctionEscapeData
- = ParentOperatorCallExpr
+ auto FunctionEscapeData =
+ ParentOperatorCallExpr
? escapesFunction(ParentCallArg, ParentOperatorCallExpr)
- : ParentCallExpr
- ? escapesFunction(ParentCallArg, ParentCallExpr)
- : escapesFunction(ParentCallArg, ParentConstructExpr);
+ : ParentCallExpr
+ ? escapesFunction(ParentCallArg, ParentCallExpr)
+ : escapesFunction(ParentCallArg, ParentConstructExpr);
// If there was an error in the escapesFunction call.
if (std::error_code ec = FunctionEscapeData.getError()) {
// FIXME: For now we ignore the variadic case and just consider that the
// argument doesn't escape the function. Same for the case where we can't
// find the function declaration or if the function is builtin.
if (static_cast<EscapesFunctionError>(ec.value()) ==
- EscapesFunctionError::FunctionIsVariadic ||
+ EscapesFunctionError::FunctionIsVariadic ||
static_cast<EscapesFunctionError>(ec.value()) ==
- EscapesFunctionError::FunctionDeclNotFound ||
+ EscapesFunctionError::FunctionDeclNotFound ||
static_cast<EscapesFunctionError>(ec.value()) ==
- EscapesFunctionError::FunctionIsBuiltin) {
+ EscapesFunctionError::FunctionIsBuiltin) {
return;
}
// We emit the internal checker error and return.
diag(MemberCall->getExprLoc(),
std::string(ec.category().name()) + " error: " + ec.message(),
DiagnosticIDs::Error);
return;
@@ -253,10 +247,10 @@ void DanglingOnTemporaryChecker::check(c
diag(EscapeDecl->getLocation(), EscapeDeclNote, DiagnosticIDs::Note)
<< EscapeDeclRange;
} else {
// We emit the error diagnostic indicating that we are calling the method
// temporary.
diag(MemberCall->getExprLoc(), Error, DiagnosticIDs::Error)
<< MemberCall->getMethodDecl()->getName()
<< MemberCall->getSourceRange();
- }
+ }
}
--- a/build/clang-plugin/DiagnosticsMatcher.cpp
+++ b/build/clang-plugin/DiagnosticsMatcher.cpp
@@ -1,17 +1,18 @@
/* 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 "DiagnosticsMatcher.h"
-DiagnosticsMatcher::DiagnosticsMatcher(CompilerInstance& CI) :
-#define CHECK(cls, name) cls ## _(name),
+DiagnosticsMatcher::DiagnosticsMatcher(CompilerInstance &CI)
+ :
+#define CHECK(cls, name) cls##_(name),
#include "Checks.inc"
#undef CHECK
- AstMatcher()
-{
-#define CHECK(cls, name) cls ## _.registerMatchers(&AstMatcher); \
- cls ## _.registerPPCallbacks(CI);
+ AstMatcher() {
+#define CHECK(cls, name) \
+ cls##_.registerMatchers(&AstMatcher); \
+ cls##_.registerPPCallbacks(CI);
#include "Checks.inc"
#undef CHECK
}
--- a/build/clang-plugin/DiagnosticsMatcher.h
+++ b/build/clang-plugin/DiagnosticsMatcher.h
@@ -4,20 +4,20 @@
#ifndef DiagnosticsMatcher_h__
#define DiagnosticsMatcher_h__
#include "ChecksIncludes.inc"
class DiagnosticsMatcher {
public:
- DiagnosticsMatcher(CompilerInstance& CI);
+ DiagnosticsMatcher(CompilerInstance &CI);
ASTConsumerPtr makeASTConsumer() { return AstMatcher.newASTConsumer(); }
private:
-#define CHECK(cls, name) cls cls ## _;
+#define CHECK(cls, name) cls cls##_;
#include "Checks.inc"
#undef CHECK
MatchFinder AstMatcher;
};
#endif
--- a/build/clang-plugin/ExplicitImplicitChecker.cpp
+++ b/build/clang-plugin/ExplicitImplicitChecker.cpp
@@ -1,31 +1,33 @@
/* 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 "ExplicitImplicitChecker.h"
#include "CustomMatchers.h"
-void ExplicitImplicitChecker::registerMatchers(MatchFinder* AstMatcher) {
- AstMatcher->addMatcher(cxxConstructorDecl(isInterestingImplicitCtor(),
- ofClass(allOf(isConcreteClass(),
- decl().bind("class"))),
- unless(isMarkedImplicit()))
- .bind("ctor"),
- this);
+void ExplicitImplicitChecker::registerMatchers(MatchFinder *AstMatcher) {
+ AstMatcher->addMatcher(
+ cxxConstructorDecl(
+ isInterestingImplicitCtor(),
+ ofClass(allOf(isConcreteClass(), decl().bind("class"))),
+ unless(isMarkedImplicit()))
+ .bind("ctor"),
+ this);
}
-void ExplicitImplicitChecker::check(
- const MatchFinder::MatchResult &Result) {
+void ExplicitImplicitChecker::check(const MatchFinder::MatchResult &Result) {
// We've already checked everything in the matcher, so we just have to report
// the error.
const CXXConstructorDecl *Ctor =
Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
const CXXRecordDecl *Declaration =
Result.Nodes.getNodeAs<CXXRecordDecl>("class");
diag(Ctor->getLocation(), "bad implicit conversion constructor for %0",
- DiagnosticIDs::Error) << Declaration->getDeclName();
- diag(Ctor->getLocation(), "consider adding the explicit keyword to the constructor",
+ DiagnosticIDs::Error)
+ << Declaration->getDeclName();
+ diag(Ctor->getLocation(),
+ "consider adding the explicit keyword to the constructor",
DiagnosticIDs::Note);
}
--- a/build/clang-plugin/ExplicitImplicitChecker.h
+++ b/build/clang-plugin/ExplicitImplicitChecker.h
@@ -4,16 +4,15 @@
#ifndef ExplicitImplicitChecker_h__
#define ExplicitImplicitChecker_h__
#include "plugin.h"
class ExplicitImplicitChecker : public BaseCheck {
public:
- ExplicitImplicitChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ ExplicitImplicitChecker(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/ExplicitOperatorBoolChecker.cpp
+++ b/build/clang-plugin/ExplicitOperatorBoolChecker.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 "ExplicitOperatorBoolChecker.h"
#include "CustomMatchers.h"
-void ExplicitOperatorBoolChecker::registerMatchers(MatchFinder* AstMatcher) {
+void ExplicitOperatorBoolChecker::registerMatchers(MatchFinder *AstMatcher) {
// Older clang versions such as the ones used on the infra recognize these
// conversions as 'operator _Bool', but newer clang versions recognize these
// as 'operator bool'.
AstMatcher->addMatcher(
cxxMethodDecl(anyOf(hasName("operator bool"), hasName("operator _Bool")))
.bind("node"),
this);
}
@@ -21,13 +21,15 @@ void ExplicitOperatorBoolChecker::check(
Result.Nodes.getNodeAs<CXXConversionDecl>("node");
const CXXRecordDecl *Clazz = Method->getParent();
if (!Method->isExplicitSpecified() &&
!hasCustomAnnotation(Method, "moz_implicit") &&
!ASTIsInSystemHeader(Method->getASTContext(), *Method) &&
isInterestingDeclForImplicitConversion(Method)) {
diag(Method->getLocStart(), "bad implicit conversion operator for %0",
- DiagnosticIDs::Error) << Clazz;
+ DiagnosticIDs::Error)
+ << Clazz;
diag(Method->getLocStart(), "consider adding the explicit keyword to %0",
- DiagnosticIDs::Note) << "'operator bool'";
+ DiagnosticIDs::Note)
+ << "'operator bool'";
}
}
--- a/build/clang-plugin/ExplicitOperatorBoolChecker.h
+++ b/build/clang-plugin/ExplicitOperatorBoolChecker.h
@@ -6,14 +6,14 @@
#define ExplicitOperatorBoolChecker_h__
#include "plugin.h"
class ExplicitOperatorBoolChecker : public BaseCheck {
public:
ExplicitOperatorBoolChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : 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,26 +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 "KungFuDeathGripChecker.h"
#include "CustomMatchers.h"
-void KungFuDeathGripChecker::registerMatchers(MatchFinder* AstMatcher) {
- AstMatcher->addMatcher(varDecl(hasType(isRefPtr())).bind("decl"),
- this);
+void KungFuDeathGripChecker::registerMatchers(MatchFinder *AstMatcher) {
+ AstMatcher->addMatcher(varDecl(hasType(isRefPtr())).bind("decl"), this);
}
-void KungFuDeathGripChecker::check(
- const MatchFinder::MatchResult &Result) {
- const char* Error =
- "Unused \"kungFuDeathGrip\" %0 objects constructed from %1 are prohibited";
- const char* Note =
- "Please switch all accesses to this %0 to go through '%1', or explicitly pass '%1' to `mozilla::Unused`";
+void KungFuDeathGripChecker::check(const MatchFinder::MatchResult &Result) {
+ const char *Error = "Unused \"kungFuDeathGrip\" %0 objects constructed from "
+ "%1 are prohibited";
+ const char *Note = "Please switch all accesses to this %0 to go through "
+ "'%1', or explicitly pass '%1' to `mozilla::Unused`";
const VarDecl *D = Result.Nodes.getNodeAs<VarDecl>("decl");
if (D->isReferenced() || !D->hasLocalStorage() || !D->hasInit()) {
return;
}
// Not interested in parameters.
if (isa<ImplicitParamDecl>(D) || isa<ParmVarDecl>(D)) {
@@ -59,40 +57,43 @@ void KungFuDeathGripChecker::check(
}
// These types are assigned into nsCOMPtr and RefPtr for their side effects,
// and not as a kungFuDeathGrip. We don't want to consider RefPtr and nsCOMPtr
// types which are initialized with these types as errors.
const TagDecl *TD = E->getType()->getAsTagDecl();
if (TD && TD->getIdentifier()) {
static const char *IgnoreTypes[] = {
- "already_AddRefed",
- "nsGetServiceByCID",
- "nsGetServiceByCIDWithError",
- "nsGetServiceByContractID",
- "nsGetServiceByContractIDWithError",
- "nsCreateInstanceByCID",
- "nsCreateInstanceByContractID",
- "nsCreateInstanceFromFactory",
+ "already_AddRefed",
+ "nsGetServiceByCID",
+ "nsGetServiceByCIDWithError",
+ "nsGetServiceByContractID",
+ "nsGetServiceByContractIDWithError",
+ "nsCreateInstanceByCID",
+ "nsCreateInstanceByContractID",
+ "nsCreateInstanceFromFactory",
};
- for (uint32_t i = 0; i < sizeof(IgnoreTypes) / sizeof(IgnoreTypes[0]); ++i) {
+ for (uint32_t i = 0; i < sizeof(IgnoreTypes) / sizeof(IgnoreTypes[0]);
+ ++i) {
if (TD->getName() == IgnoreTypes[i]) {
return;
}
}
}
// Report the error
const char *ErrThing;
const char *NoteThing;
if (isa<MemberExpr>(E)) {
- ErrThing = "members";
+ ErrThing = "members";
NoteThing = "member";
} else {
ErrThing = "temporary values";
NoteThing = "value";
}
// We cannot provide the note if we don't have an initializer
- diag(D->getLocStart(), Error, DiagnosticIDs::Error) << D->getType() << ErrThing;
- diag(E->getLocStart(), Note, DiagnosticIDs::Note) << NoteThing << getNameChecked(D);
+ diag(D->getLocStart(), Error, DiagnosticIDs::Error)
+ << D->getType() << ErrThing;
+ diag(E->getLocStart(), Note, DiagnosticIDs::Note)
+ << NoteThing << getNameChecked(D);
}
--- a/build/clang-plugin/KungFuDeathGripChecker.h
+++ b/build/clang-plugin/KungFuDeathGripChecker.h
@@ -4,16 +4,15 @@
#ifndef KungFuDeathGripChecker_h__
#define KungFuDeathGripChecker_h__
#include "plugin.h"
class KungFuDeathGripChecker : public BaseCheck {
public:
- KungFuDeathGripChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ KungFuDeathGripChecker(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/MemMoveAnnotation.h
+++ b/build/clang-plugin/MemMoveAnnotation.h
@@ -1,17 +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/. */
#ifndef MemMoveAnnotation_h__
#define MemMoveAnnotation_h__
+#include "CustomMatchers.h"
#include "CustomTypeAnnotation.h"
-#include "CustomMatchers.h"
#include "Utils.h"
class MemMoveAnnotation final : public CustomTypeAnnotation {
public:
MemMoveAnnotation()
: CustomTypeAnnotation("moz_non_memmovable", "non-memmove()able") {}
virtual ~MemMoveAnnotation() {}
@@ -19,40 +19,29 @@ public:
protected:
std::string getImplicitReason(const TagDecl *D) const override {
// Annotate everything in ::std, with a few exceptions; see bug
// 1201314 for discussion.
if (getDeclarationNamespace(D) == "std") {
// This doesn't check that it's really ::std::pair and not
// ::std::something_else::pair, but should be good enough.
StringRef Name = getNameChecked(D);
- if (Name == "pair" ||
- Name == "atomic" ||
+ if (Name == "pair" || Name == "atomic" ||
// libstdc++ specific names
- Name == "__atomic_base" ||
- Name == "atomic_bool" ||
+ Name == "__atomic_base" || Name == "atomic_bool" ||
// MSVCRT specific names
- Name == "_Atomic_impl" ||
- Name == "_Atomic_base" ||
- Name == "_Atomic_bool" ||
- Name == "_Atomic_char" ||
- Name == "_Atomic_schar" ||
- Name == "_Atomic_uchar" ||
- Name == "_Atomic_char16_t" ||
- Name == "_Atomic_char32_t" ||
- Name == "_Atomic_wchar_t" ||
- Name == "_Atomic_short" ||
- Name == "_Atomic_ushort" ||
- Name == "_Atomic_int" ||
- Name == "_Atomic_uint" ||
- Name == "_Atomic_long" ||
- Name == "_Atomic_ulong" ||
- Name == "_Atomic_llong" ||
- Name == "_Atomic_ullong" ||
- Name == "_Atomic_address") {
+ Name == "_Atomic_impl" || Name == "_Atomic_base" ||
+ Name == "_Atomic_bool" || Name == "_Atomic_char" ||
+ Name == "_Atomic_schar" || Name == "_Atomic_uchar" ||
+ Name == "_Atomic_char16_t" || Name == "_Atomic_char32_t" ||
+ Name == "_Atomic_wchar_t" || Name == "_Atomic_short" ||
+ Name == "_Atomic_ushort" || Name == "_Atomic_int" ||
+ Name == "_Atomic_uint" || Name == "_Atomic_long" ||
+ Name == "_Atomic_ulong" || Name == "_Atomic_llong" ||
+ Name == "_Atomic_ullong" || Name == "_Atomic_address") {
return "";
}
return "it is an stl-provided type not guaranteed to be memmove-able";
}
return "";
}
};
--- a/build/clang-plugin/MozCheckAction.cpp
+++ b/build/clang-plugin/MozCheckAction.cpp
@@ -1,22 +1,22 @@
/* 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 "DiagnosticsMatcher.h"
#include "plugin.h"
-#include "DiagnosticsMatcher.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
class MozCheckAction : public PluginASTAction {
public:
ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI,
StringRef FileName) override {
- void* Buffer = CI.getASTContext().Allocate<DiagnosticsMatcher>();
- auto Matcher = new(Buffer) DiagnosticsMatcher(CI);
+ 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;
}
};
--- a/build/clang-plugin/MozillaTidyModule.cpp
+++ b/build/clang-plugin/MozillaTidyModule.cpp
@@ -19,18 +19,18 @@ public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
#define CHECK(cls, name) CheckFactories.registerCheck<cls>("mozilla-" name);
#include "Checks.inc"
#undef CHECK
}
};
// Register the MozillaTidyModule using this statically initialized variable.
-static ClangTidyModuleRegistry::Add<MozillaModule> X("mozilla-module",
- "Adds Mozilla lint checks.");
+static ClangTidyModuleRegistry::Add<MozillaModule>
+ X("mozilla-module", "Adds Mozilla lint checks.");
} // namespace tidy
} // namespace clang
// This anchor is used to force the linker to link in the generated object file
// and thus register the MozillaModule.
volatile int MozillaModuleAnchorSource = 0;
--- a/build/clang-plugin/MustOverrideChecker.cpp
+++ b/build/clang-plugin/MustOverrideChecker.cpp
@@ -1,62 +1,60 @@
/* 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 "MustOverrideChecker.h"
#include "CustomMatchers.h"
-void MustOverrideChecker::registerMatchers(MatchFinder* AstMatcher) {
+void MustOverrideChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(cxxRecordDecl(isDefinition()).bind("class"), this);
}
-void MustOverrideChecker::registerPPCallbacks(CompilerInstance& CI) {
+void MustOverrideChecker::registerPPCallbacks(CompilerInstance &CI) {
this->CI = &CI;
}
-void MustOverrideChecker::check(
- const MatchFinder::MatchResult &Result) {
+void MustOverrideChecker::check(const MatchFinder::MatchResult &Result) {
auto D = Result.Nodes.getNodeAs<CXXRecordDecl>("class");
// Look through all of our immediate bases to find methods that need to be
// overridden
typedef std::vector<CXXMethodDecl *> OverridesVector;
OverridesVector MustOverrides;
- for (const auto& Base : D->bases()) {
+ for (const auto &Base : D->bases()) {
// The base is either a class (CXXRecordDecl) or it's a templated class...
CXXRecordDecl *Parent = Base.getType()
.getDesugaredType(D->getASTContext())
->getAsCXXRecordDecl();
// The parent might not be resolved to a type yet. In this case, we can't
// 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()) {
+ for (const auto &M : Parent->methods()) {
if (hasCustomAnnotation(M, "moz_must_override"))
MustOverrides.push_back(M);
}
}
- for (auto& O : MustOverrides) {
+ for (auto &O : MustOverrides) {
bool Overridden = false;
- for (const auto& M : D->methods()) {
+ for (const auto &M : D->methods()) {
// The way that Clang checks if a method M overrides its parent method
// is if the method has the same name but would not overload.
if (getNameChecked(M) == getNameChecked(O) &&
!CI->getSema().IsOverload(M, O, false)) {
Overridden = true;
break;
}
}
if (!Overridden) {
- diag(D->getLocation(), "%0 must override %1",
- DiagnosticIDs::Error) << D->getDeclName()
- << O->getDeclName();
+ diag(D->getLocation(), "%0 must override %1", DiagnosticIDs::Error)
+ << D->getDeclName() << O->getDeclName();
diag(O->getLocation(), "function to override is here",
DiagnosticIDs::Note);
}
}
}
--- a/build/clang-plugin/MustOverrideChecker.h
+++ b/build/clang-plugin/MustOverrideChecker.h
@@ -4,20 +4,19 @@
#ifndef MustOverrideChecker_h__
#define MustOverrideChecker_h__
#include "plugin.h"
class MustOverrideChecker : public BaseCheck {
public:
- MustOverrideChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context), CI(nullptr) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
- void registerPPCallbacks(CompilerInstance& CI) override;
+ MustOverrideChecker(StringRef CheckName, ContextType *Context = nullptr)
+ : BaseCheck(CheckName, Context), CI(nullptr) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
+ void registerPPCallbacks(CompilerInstance &CI) override;
void check(const MatchFinder::MatchResult &Result) override;
private:
- const CompilerInstance* CI;
+ const CompilerInstance *CI;
};
#endif
--- a/build/clang-plugin/MustReturnFromCallerChecker.cpp
+++ b/build/clang-plugin/MustReturnFromCallerChecker.cpp
@@ -1,45 +1,47 @@
/* 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 "MustReturnFromCallerChecker.h"
#include "CustomMatchers.h"
-void MustReturnFromCallerChecker::registerMatchers(MatchFinder* AstMatcher) {
+void MustReturnFromCallerChecker::registerMatchers(MatchFinder *AstMatcher) {
// Look for a call to a MOZ_MUST_RETURN_FROM_CALLER function
- AstMatcher->addMatcher(callExpr(callee(functionDecl(isMozMustReturnFromCaller())),
- anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
- hasAncestor(functionDecl().bind("containing-func")))).bind("call"),
- this);
+ AstMatcher->addMatcher(
+ callExpr(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 MatchFinder::MatchResult &Result) {
const auto *ContainingLambda =
- Result.Nodes.getNodeAs<LambdaExpr>("containing-lambda");
+ Result.Nodes.getNodeAs<LambdaExpr>("containing-lambda");
const auto *ContainingFunc =
- Result.Nodes.getNodeAs<FunctionDecl>("containing-func");
+ Result.Nodes.getNodeAs<FunctionDecl>("containing-func");
const auto *Call = Result.Nodes.getNodeAs<CallExpr>("call");
Stmt *Body = nullptr;
if (ContainingLambda) {
Body = ContainingLambda->getBody();
} else if (ContainingFunc) {
Body = ContainingFunc->getBody();
} else {
return;
}
assert(Body && "Should have a body by this point");
// Generate the CFG for the enclosing function or decl.
CFG::BuildOptions Options;
std::unique_ptr<CFG> TheCFG =
- CFG::buildCFG(nullptr, Body, Result.Context, Options);
+ CFG::buildCFG(nullptr, Body, Result.Context, Options);
if (!TheCFG) {
return;
}
// Determine which block in the CFG we want to look at the successors of.
StmtToBlockMap BlockMap(TheCFG.get(), Result.Context);
size_t CallIndex;
const auto *Block = BlockMap.blockContainingStmt(Call, &CallIndex);
@@ -47,20 +49,19 @@ void MustReturnFromCallerChecker::check(
if (!immediatelyReturns(Block, Result.Context, CallIndex + 1)) {
diag(Call->getLocStart(),
"You must immediately return after calling this function",
DiagnosticIDs::Error);
}
}
-bool
-MustReturnFromCallerChecker::immediatelyReturns(RecurseGuard<const CFGBlock *> Block,
- ASTContext *TheContext,
- size_t FromIdx) {
+bool MustReturnFromCallerChecker::immediatelyReturns(
+ RecurseGuard<const CFGBlock *> Block, ASTContext *TheContext,
+ size_t FromIdx) {
if (Block.isRepeat()) {
return false;
}
for (size_t I = FromIdx; I < Block->size(); ++I) {
Optional<CFGStmt> S = (*Block)[I].getAs<CFGStmt>();
if (!S) {
continue;
@@ -68,27 +69,27 @@ MustReturnFromCallerChecker::immediately
auto AfterTrivials = IgnoreTrivials(S->getStmt());
// If we are looking at a ConstructExpr, a DeclRefExpr or a MemberExpr it's
// OK to use them after a call to a MOZ_MUST_RETURN_FROM_CALLER function.
// It is also, of course, OK to look at a ReturnStmt.
if (isa<ReturnStmt>(AfterTrivials) ||
isa<CXXConstructExpr>(AfterTrivials) ||
- isa<DeclRefExpr>(AfterTrivials) ||
- isa<MemberExpr>(AfterTrivials)) {
+ isa<DeclRefExpr>(AfterTrivials) || isa<MemberExpr>(AfterTrivials)) {
continue;
}
// It's also OK to call any function or method which is annotated with
// MOZ_MAY_CALL_AFTER_MUST_RETURN. We consider all CXXConversionDecls
// to be MOZ_MAY_CALL_AFTER_MUST_RETURN (like operator T*()).
if (auto CE = dyn_cast<CallExpr>(AfterTrivials)) {
auto Callee = CE->getDirectCallee();
- if (Callee && hasCustomAnnotation(Callee, "moz_may_call_after_must_return")) {
+ if (Callee &&
+ hasCustomAnnotation(Callee, "moz_may_call_after_must_return")) {
continue;
}
if (Callee && isa<CXXConversionDecl>(Callee)) {
continue;
}
}
--- a/build/clang-plugin/MustReturnFromCallerChecker.h
+++ b/build/clang-plugin/MustReturnFromCallerChecker.h
@@ -1,26 +1,26 @@
/* 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 MustReturnFromCallerChecker_h__
#define MustReturnFromCallerChecker_h__
-#include "plugin.h"
-#include "Utils.h"
#include "RecurseGuard.h"
#include "StmtToBlockMap.h"
+#include "Utils.h"
+#include "plugin.h"
class MustReturnFromCallerChecker : public BaseCheck {
public:
MustReturnFromCallerChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
+
private:
bool immediatelyReturns(RecurseGuard<const CFGBlock *> Block,
- ASTContext *TheContext,
- size_t FromIdx);
+ ASTContext *TheContext, size_t FromIdx);
};
#endif
--- a/build/clang-plugin/MustUseChecker.cpp
+++ b/build/clang-plugin/MustUseChecker.cpp
@@ -4,33 +4,33 @@
#include "MustUseChecker.h"
#include "CustomMatchers.h"
#include "CustomTypeAnnotation.h"
CustomTypeAnnotation MustUse =
CustomTypeAnnotation("moz_must_use_type", "must-use");
-void MustUseChecker::registerMatchers(MatchFinder* AstMatcher) {
+void MustUseChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(switchCase().bind("switchcase"), this);
AstMatcher->addMatcher(compoundStmt().bind("compound"), this);
AstMatcher->addMatcher(ifStmt().bind("if"), this);
AstMatcher->addMatcher(whileStmt().bind("while"), this);
AstMatcher->addMatcher(doStmt().bind("do"), this);
AstMatcher->addMatcher(forStmt().bind("for"), this);
- AstMatcher->addMatcher(binaryOperator(binaryCommaOperator()).bind("bin"), this);
+ AstMatcher->addMatcher(binaryOperator(binaryCommaOperator()).bind("bin"),
+ this);
}
-void MustUseChecker::check(
- const MatchFinder::MatchResult &Result) {
+void MustUseChecker::check(const MatchFinder::MatchResult &Result) {
if (auto SC = Result.Nodes.getNodeAs<SwitchCase>("switchcase")) {
handleUnusedExprResult(SC->getSubStmt());
}
if (auto C = Result.Nodes.getNodeAs<CompoundStmt>("compound")) {
- for (const auto& S : C->body()) {
+ for (const auto &S : C->body()) {
handleUnusedExprResult(S);
}
}
if (auto IF = Result.Nodes.getNodeAs<IfStmt>("if")) {
handleUnusedExprResult(IF->getThen());
handleUnusedExprResult(IF->getElse());
}
if (auto W = Result.Nodes.getNodeAs<WhileStmt>("while")) {
@@ -51,13 +51,14 @@ void MustUseChecker::check(
void MustUseChecker::handleUnusedExprResult(const Stmt *Statement) {
const Expr *E = dyn_cast_or_null<Expr>(Statement);
if (E) {
E = E->IgnoreImplicit(); // Ignore ExprWithCleanup etc. implicit wrappers
QualType T = E->getType();
if (MustUse.hasEffectiveAnnotation(T) && !isIgnoredExprForMustUse(E)) {
diag(E->getLocStart(), "Unused value of must-use type %0",
- DiagnosticIDs::Error) << T;
+ DiagnosticIDs::Error)
+ << T;
MustUse.dumpAnnotationReason(*this, T, E->getLocStart());
}
}
}
--- a/build/clang-plugin/MustUseChecker.h
+++ b/build/clang-plugin/MustUseChecker.h
@@ -4,19 +4,18 @@
#ifndef MustUseChecker_h__
#define MustUseChecker_h__
#include "plugin.h"
class MustUseChecker : public BaseCheck {
public:
- MustUseChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ MustUseChecker(StringRef CheckName, ContextType *Context = nullptr)
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
private:
void handleUnusedExprResult(const Stmt *Statement);
};
#endif
--- a/build/clang-plugin/NaNExprChecker.cpp
+++ b/build/clang-plugin/NaNExprChecker.cpp
@@ -1,56 +1,56 @@
/* 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 "NaNExprChecker.h"
#include "CustomMatchers.h"
-void NaNExprChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NaNExprChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
binaryOperator(
allOf(binaryEqualityOperator(),
hasLHS(hasIgnoringParenImpCasts(
declRefExpr(hasType(qualType((isFloat())))).bind("lhs"))),
hasRHS(hasIgnoringParenImpCasts(
declRefExpr(hasType(qualType((isFloat())))).bind("rhs"))),
unless(anyOf(isInSystemHeader(), isInWhitelistForNaNExpr()))))
.bind("node"),
this);
}
-void NaNExprChecker::check(
- const MatchFinder::MatchResult &Result) {
+void NaNExprChecker::check(const MatchFinder::MatchResult &Result) {
if (!Result.Context->getLangOpts().CPlusPlus) {
// mozilla::IsNaN is not usable in C, so there is no point in issuing these
// warnings.
return;
}
- const BinaryOperator *Expression = Result.Nodes.getNodeAs<BinaryOperator>(
- "node");
+ const BinaryOperator *Expression =
+ Result.Nodes.getNodeAs<BinaryOperator>("node");
const DeclRefExpr *LHS = Result.Nodes.getNodeAs<DeclRefExpr>("lhs");
const DeclRefExpr *RHS = Result.Nodes.getNodeAs<DeclRefExpr>("rhs");
- const ImplicitCastExpr *LHSExpr = dyn_cast<ImplicitCastExpr>(
- Expression->getLHS());
- const ImplicitCastExpr *RHSExpr = dyn_cast<ImplicitCastExpr>(
- Expression->getRHS());
+ const ImplicitCastExpr *LHSExpr =
+ dyn_cast<ImplicitCastExpr>(Expression->getLHS());
+ const ImplicitCastExpr *RHSExpr =
+ dyn_cast<ImplicitCastExpr>(Expression->getRHS());
// The AST subtree that we are looking for will look like this:
// -BinaryOperator ==/!=
// |-ImplicitCastExpr LValueToRValue
// | |-DeclRefExpr
// |-ImplicitCastExpr LValueToRValue
// |-DeclRefExpr
// The check below ensures that we are dealing with the correct AST subtree
// shape, and
// also that both of the found DeclRefExpr's point to the same declaration.
if (LHS->getFoundDecl() == RHS->getFoundDecl() && LHSExpr && RHSExpr &&
std::distance(LHSExpr->child_begin(), LHSExpr->child_end()) == 1 &&
std::distance(RHSExpr->child_begin(), RHSExpr->child_end()) == 1 &&
*LHSExpr->child_begin() == LHS && *RHSExpr->child_begin() == RHS) {
- diag(Expression->getLocStart(), "comparing a floating point value to itself for "
- "NaN checking can lead to incorrect results",
+ diag(Expression->getLocStart(),
+ "comparing a floating point value to itself for "
+ "NaN checking can lead to incorrect results",
DiagnosticIDs::Error);
diag(Expression->getLocStart(), "consider using mozilla::IsNaN instead",
DiagnosticIDs::Note);
}
}
--- a/build/clang-plugin/NaNExprChecker.h
+++ b/build/clang-plugin/NaNExprChecker.h
@@ -4,16 +4,15 @@
#ifndef NaNExprChecker_h__
#define NaNExprChecker_h__
#include "plugin.h"
class NaNExprChecker : public BaseCheck {
public:
- NaNExprChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ NaNExprChecker(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/NeedsNoVTableTypeChecker.cpp
+++ b/build/clang-plugin/NeedsNoVTableTypeChecker.cpp
@@ -1,40 +1,39 @@
/* 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 "NeedsNoVTableTypeChecker.h"
#include "CustomMatchers.h"
-void NeedsNoVTableTypeChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NeedsNoVTableTypeChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
classTemplateSpecializationDecl(
allOf(hasAnyTemplateArgument(refersToType(hasVTable())),
hasNeedsNoVTableTypeAttr()))
.bind("node"),
this);
}
-void NeedsNoVTableTypeChecker::check(
- const MatchFinder::MatchResult &Result) {
+void NeedsNoVTableTypeChecker::check(const MatchFinder::MatchResult &Result) {
const ClassTemplateSpecializationDecl *Specialization =
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("node");
// Get the offending template argument
QualType Offender;
const TemplateArgumentList &Args =
Specialization->getTemplateInstantiationArgs();
for (unsigned i = 0; i < Args.size(); ++i) {
Offender = Args[i].getAsType();
if (typeHasVTable(Offender)) {
break;
}
}
diag(Specialization->getLocStart(),
"%0 cannot be instantiated because %1 has a VTable",
- DiagnosticIDs::Error) << Specialization
- << Offender;
+ DiagnosticIDs::Error)
+ << Specialization << Offender;
diag(Specialization->getPointOfInstantiation(),
- "bad instantiation of %0 requested here",
- DiagnosticIDs::Note) << Specialization;
+ "bad instantiation of %0 requested here", DiagnosticIDs::Note)
+ << Specialization;
}
--- a/build/clang-plugin/NeedsNoVTableTypeChecker.h
+++ b/build/clang-plugin/NeedsNoVTableTypeChecker.h
@@ -4,16 +4,15 @@
#ifndef NeedsNoVTableTypeChecker_h__
#define NeedsNoVTableTypeChecker_h__
#include "plugin.h"
class NeedsNoVTableTypeChecker : public BaseCheck {
public:
- NeedsNoVTableTypeChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ NeedsNoVTableTypeChecker(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/NoAddRefReleaseOnReturnChecker.cpp
+++ b/build/clang-plugin/NoAddRefReleaseOnReturnChecker.cpp
@@ -1,32 +1,32 @@
/* 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 "NoAddRefReleaseOnReturnChecker.h"
#include "CustomMatchers.h"
-void NoAddRefReleaseOnReturnChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NoAddRefReleaseOnReturnChecker::registerMatchers(MatchFinder *AstMatcher) {
// Look for all of the calls to AddRef() or Release()
- AstMatcher->addMatcher(memberExpr(isAddRefOrRelease(), hasParent(callExpr())).bind("member"),
- this);
+ AstMatcher->addMatcher(
+ memberExpr(isAddRefOrRelease(), hasParent(callExpr())).bind("member"),
+ this);
}
void NoAddRefReleaseOnReturnChecker::check(
const MatchFinder::MatchResult &Result) {
const MemberExpr *Member = Result.Nodes.getNodeAs<MemberExpr>("member");
const Expr *Base = IgnoreTrivials(Member->getBase());
// Check if the call to AddRef() or Release() was made on the result of a call
// to a MOZ_NO_ADDREF_RELEASE_ON_RETURN function or method.
if (auto *Call = dyn_cast<CallExpr>(Base)) {
if (auto *Callee = Call->getDirectCallee()) {
if (hasCustomAnnotation(Callee, "moz_no_addref_release_on_return")) {
diag(Call->getLocStart(),
"%1 cannot be called on the return value of %0",
DiagnosticIDs::Error)
- << Callee
- << dyn_cast<CXXMethodDecl>(Member->getMemberDecl());
+ << Callee << dyn_cast<CXXMethodDecl>(Member->getMemberDecl());
}
}
}
}
--- a/build/clang-plugin/NoAddRefReleaseOnReturnChecker.h
+++ b/build/clang-plugin/NoAddRefReleaseOnReturnChecker.h
@@ -6,14 +6,14 @@
#define NoAddRefReleaseOnReturnChecker_h__
#include "plugin.h"
class NoAddRefReleaseOnReturnChecker : public BaseCheck {
public:
NoAddRefReleaseOnReturnChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/NoAutoTypeChecker.cpp
+++ b/build/clang-plugin/NoAutoTypeChecker.cpp
@@ -1,23 +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 "NoAutoTypeChecker.h"
#include "CustomMatchers.h"
-void NoAutoTypeChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NoAutoTypeChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(varDecl(hasType(autoNonAutoableType())).bind("node"),
this);
}
-void NoAutoTypeChecker::check(
- const MatchFinder::MatchResult &Result) {
+void NoAutoTypeChecker::check(const MatchFinder::MatchResult &Result) {
const VarDecl *D = Result.Nodes.getNodeAs<VarDecl>("node");
- diag(D->getLocation(),
- "Cannot use auto to declare a variable of type %0",
- DiagnosticIDs::Error) << D->getType();
- diag(D->getLocation(),
- "Please write out this type explicitly",
+ diag(D->getLocation(), "Cannot use auto to declare a variable of type %0",
+ DiagnosticIDs::Error)
+ << D->getType();
+ diag(D->getLocation(), "Please write out this type explicitly",
DiagnosticIDs::Note);
}
--- a/build/clang-plugin/NoAutoTypeChecker.h
+++ b/build/clang-plugin/NoAutoTypeChecker.h
@@ -4,16 +4,15 @@
#ifndef NoAutoTypeChecker_h__
#define NoAutoTypeChecker_h__
#include "plugin.h"
class NoAutoTypeChecker : public BaseCheck {
public:
- NoAutoTypeChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ NoAutoTypeChecker(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/NoDuplicateRefCntMemberChecker.cpp
+++ b/build/clang-plugin/NoDuplicateRefCntMemberChecker.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 "NoDuplicateRefCntMemberChecker.h"
#include "CustomMatchers.h"
-void NoDuplicateRefCntMemberChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NoDuplicateRefCntMemberChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(cxxRecordDecl().bind("decl"), this);
}
void NoDuplicateRefCntMemberChecker::check(
const MatchFinder::MatchResult &Result) {
const CXXRecordDecl *D = Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
const FieldDecl *RefCntMember = getClassRefCntMember(D);
const FieldDecl *FoundRefCntBase = nullptr;
@@ -29,40 +29,37 @@ void NoDuplicateRefCntMemberChecker::che
// warn for those which do
for (auto &Base : D->bases()) {
// Determine if this base class has an mRefCnt member
const FieldDecl *BaseRefCntMember = getBaseRefCntMember(Base.getType());
if (BaseRefCntMember) {
if (RefCntMember) {
// We have an mRefCnt, and superclass has an mRefCnt
- const char* Error =
- "Refcounted record %0 has multiple mRefCnt members";
- const char* Note1 =
- "Superclass %0 also has an mRefCnt member";
- const char* Note2 =
+ const char *Error = "Refcounted record %0 has multiple mRefCnt members";
+ const char *Note1 = "Superclass %0 also has an mRefCnt member";
+ const char *Note2 =
"Consider using the _INHERITED macros for AddRef and Release here";
diag(D->getLocStart(), Error, DiagnosticIDs::Error) << D;
diag(BaseRefCntMember->getLocStart(), Note1, DiagnosticIDs::Note)
- << BaseRefCntMember->getParent();
+ << BaseRefCntMember->getParent();
diag(RefCntMember->getLocStart(), Note2, DiagnosticIDs::Note);
}
if (FoundRefCntBase) {
- const char* Error =
- "Refcounted record %0 has multiple superclasses with mRefCnt members";
- const char* Note =
- "Superclass %0 has an mRefCnt member";
+ const char *Error = "Refcounted record %0 has multiple superclasses "
+ "with mRefCnt members";
+ const char *Note = "Superclass %0 has an mRefCnt member";
// superclass has mRefCnt, and another superclass also has an mRefCnt
diag(D->getLocStart(), Error, DiagnosticIDs::Error) << D;
diag(BaseRefCntMember->getLocStart(), Note, DiagnosticIDs::Note)
- << BaseRefCntMember->getParent();
+ << BaseRefCntMember->getParent();
diag(FoundRefCntBase->getLocStart(), Note, DiagnosticIDs::Note)
- << FoundRefCntBase->getParent();
+ << FoundRefCntBase->getParent();
}
// Record that we've found a base with a mRefCnt member
FoundRefCntBase = BaseRefCntMember;
}
}
}
--- a/build/clang-plugin/NoDuplicateRefCntMemberChecker.h
+++ b/build/clang-plugin/NoDuplicateRefCntMemberChecker.h
@@ -6,14 +6,14 @@
#define NoDuplicateRefCntMemberChecker_h__
#include "plugin.h"
class NoDuplicateRefCntMemberChecker : public BaseCheck {
public:
NoDuplicateRefCntMemberChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/NoExplicitMoveConstructorChecker.cpp
+++ b/build/clang-plugin/NoExplicitMoveConstructorChecker.cpp
@@ -1,19 +1,19 @@
/* 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 "NoExplicitMoveConstructorChecker.h"
#include "CustomMatchers.h"
-void NoExplicitMoveConstructorChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NoExplicitMoveConstructorChecker::registerMatchers(
+ MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
- cxxConstructorDecl(isExplicitMoveConstructor()).bind("node"),
- this);
+ cxxConstructorDecl(isExplicitMoveConstructor()).bind("node"), this);
}
void NoExplicitMoveConstructorChecker::check(
const MatchFinder::MatchResult &Result) {
// Everything we needed to know was checked in the matcher - we just report
// the error here
const CXXConstructorDecl *D =
Result.Nodes.getNodeAs<CXXConstructorDecl>("node");
--- a/build/clang-plugin/NoExplicitMoveConstructorChecker.h
+++ b/build/clang-plugin/NoExplicitMoveConstructorChecker.h
@@ -6,14 +6,14 @@
#define NoExplicitMoveConstructorChecker_h__
#include "plugin.h"
class NoExplicitMoveConstructorChecker : public BaseCheck {
public:
NoExplicitMoveConstructorChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/NonMemMovableMemberChecker.cpp
+++ b/build/clang-plugin/NonMemMovableMemberChecker.cpp
@@ -2,37 +2,33 @@
* 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 "NonMemMovableMemberChecker.h"
#include "CustomMatchers.h"
MemMoveAnnotation NonMemMovable = MemMoveAnnotation();
-void NonMemMovableMemberChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NonMemMovableMemberChecker::registerMatchers(MatchFinder *AstMatcher) {
// Handle non-mem-movable members
- AstMatcher->addMatcher(
- cxxRecordDecl(needsMemMovableMembers())
- .bind("decl"),
- this);
+ AstMatcher->addMatcher(cxxRecordDecl(needsMemMovableMembers()).bind("decl"),
+ this);
}
-void NonMemMovableMemberChecker::check(
- const MatchFinder::MatchResult &Result) {
- const char* Error =
+void NonMemMovableMemberChecker::check(const MatchFinder::MatchResult &Result) {
+ const char *Error =
"class %0 cannot have non-memmovable member %1 of type %2";
// Get the specialization
- const CXXRecordDecl* Declaration =
+ const CXXRecordDecl *Declaration =
Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
// Report an error for every member which is non-memmovable
for (const FieldDecl *Field : Declaration->fields()) {
QualType Type = Field->getType();
if (NonMemMovable.hasEffectiveAnnotation(Type)) {
diag(Field->getLocation(), Error, DiagnosticIDs::Error)
- << Declaration
- << Field
- << Type;
- NonMemMovable.dumpAnnotationReason(*this, Type, Declaration->getLocation());
+ << Declaration << Field << Type;
+ NonMemMovable.dumpAnnotationReason(*this, Type,
+ Declaration->getLocation());
}
}
}
--- a/build/clang-plugin/NonMemMovableMemberChecker.h
+++ b/build/clang-plugin/NonMemMovableMemberChecker.h
@@ -6,14 +6,14 @@
#define NonMemMovableMemberChecker_h__
#include "plugin.h"
class NonMemMovableMemberChecker : public BaseCheck {
public:
NonMemMovableMemberChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/NonMemMovableTemplateArgChecker.cpp
+++ b/build/clang-plugin/NonMemMovableTemplateArgChecker.cpp
@@ -1,46 +1,45 @@
/* 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 "NonMemMovableTemplateArgChecker.h"
#include "CustomMatchers.h"
-void NonMemMovableTemplateArgChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NonMemMovableTemplateArgChecker::registerMatchers(
+ MatchFinder *AstMatcher) {
// Handle non-mem-movable template specializations
AstMatcher->addMatcher(
classTemplateSpecializationDecl(
allOf(needsMemMovableTemplateArg(),
hasAnyTemplateArgument(refersToType(isNonMemMovable()))))
.bind("specialization"),
this);
}
void NonMemMovableTemplateArgChecker::check(
const MatchFinder::MatchResult &Result) {
- const char* Error =
+ const char *Error =
"Cannot instantiate %0 with non-memmovable template argument %1";
- const char* Note =
- "instantiation of %0 requested here";
+ const char *Note = "instantiation of %0 requested here";
// Get the specialization
const ClassTemplateSpecializationDecl *Specialization =
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization");
SourceLocation RequestLoc = Specialization->getPointOfInstantiation();
// Report an error for every template argument which is non-memmovable
const TemplateArgumentList &Args =
Specialization->getTemplateInstantiationArgs();
for (unsigned i = 0; i < Args.size(); ++i) {
QualType ArgType = Args[i].getAsType();
if (NonMemMovable.hasEffectiveAnnotation(ArgType)) {
- diag(Specialization->getLocation(), Error,
- DiagnosticIDs::Error) << Specialization
- << ArgType;
+ diag(Specialization->getLocation(), Error, DiagnosticIDs::Error)
+ << Specialization << ArgType;
// XXX It would be really nice if we could get the instantiation stack
// information
// from Sema such that we could print a full template instantiation stack,
// however,
// it seems as though that information is thrown out by the time we get
// here so we
// can only report one level of template specialization (which in many
// cases won't
--- a/build/clang-plugin/NonMemMovableTemplateArgChecker.h
+++ b/build/clang-plugin/NonMemMovableTemplateArgChecker.h
@@ -6,14 +6,14 @@
#define NonMemMovableTemplateArgChecker_h__
#include "plugin.h"
class NonMemMovableTemplateArgChecker : public BaseCheck {
public:
NonMemMovableTemplateArgChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/NonParamInsideFunctionDeclChecker.cpp
+++ b/build/clang-plugin/NonParamInsideFunctionDeclChecker.cpp
@@ -1,19 +1,18 @@
/* 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 "NonParamInsideFunctionDeclChecker.h"
#include "CustomMatchers.h"
-class NonParamAnnotation : public CustomTypeAnnotation
-{
+class NonParamAnnotation : public CustomTypeAnnotation {
public:
- NonParamAnnotation() : CustomTypeAnnotation("moz_non_param", "non-param") {};
+ NonParamAnnotation() : CustomTypeAnnotation("moz_non_param", "non-param"){};
protected:
// Adding alignas(_) on a struct implicitly marks it as MOZ_NON_PARAM, due to
// MSVC limitations which prevent passing explcitly aligned types by value as
// parameters. This overload of hasFakeAnnotation injects fake MOZ_NON_PARAM
// annotations onto these types.
std::string getImplicitReason(const TagDecl *D) const override {
// Check if the decl itself has an AlignedAttr on it.
@@ -23,45 +22,47 @@ protected:
}
}
// Check if any of the decl's fields have an AlignedAttr on them.
if (auto RD = dyn_cast<RecordDecl>(D)) {
for (auto F : RD->fields()) {
for (auto A : F->attrs()) {
if (isa<AlignedAttr>(A)) {
- return ("member '" + F->getName() + "' has an alignas(_) annotation").str();
+ return ("member '" + F->getName() +
+ "' has an alignas(_) annotation")
+ .str();
}
}
}
}
// We don't need to check the types of fields, as the CustomTypeAnnotation
// infrastructure will handle that for us.
return "";
}
};
NonParamAnnotation NonParam;
-void NonParamInsideFunctionDeclChecker::registerMatchers(MatchFinder* AstMatcher) {
+void NonParamInsideFunctionDeclChecker::registerMatchers(
+ MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
- functionDecl(anyOf(allOf(isDefinition(),
- hasAncestor(classTemplateSpecializationDecl()
- .bind("spec"))),
- isDefinition()))
+ functionDecl(
+ anyOf(allOf(isDefinition(),
+ hasAncestor(
+ classTemplateSpecializationDecl().bind("spec"))),
+ isDefinition()))
.bind("func"),
this);
- AstMatcher->addMatcher(
- lambdaExpr().bind("lambda"),
- this);
+ AstMatcher->addMatcher(lambdaExpr().bind("lambda"), this);
}
void NonParamInsideFunctionDeclChecker::check(
const MatchFinder::MatchResult &Result) {
- static DenseSet<const FunctionDecl*> CheckedFunctionDecls;
+ static DenseSet<const FunctionDecl *> CheckedFunctionDecls;
const FunctionDecl *func = Result.Nodes.getNodeAs<FunctionDecl>("func");
if (!func) {
const LambdaExpr *lambda = Result.Nodes.getNodeAs<LambdaExpr>("lambda");
if (lambda) {
func = lambda->getCallOperator();
}
}
@@ -93,23 +94,24 @@ void NonParamInsideFunctionDeclChecker::
const ClassTemplateSpecializationDecl *Spec =
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("spec");
for (ParmVarDecl *p : func->parameters()) {
QualType T = p->getType().withoutLocalFastQualifiers();
if (NonParam.hasEffectiveAnnotation(T)) {
diag(p->getLocation(), "Type %0 must not be used as parameter",
- DiagnosticIDs::Error) << T;
- diag(p->getLocation(), "Please consider passing a const reference instead",
+ DiagnosticIDs::Error)
+ << T;
+ diag(p->getLocation(),
+ "Please consider passing a const reference instead",
DiagnosticIDs::Note);
if (Spec) {
diag(Spec->getPointOfInstantiation(),
- "The bad argument was passed to %0 here",
- DiagnosticIDs::Note)
- << Spec->getSpecializedTemplate();
+ "The bad argument was passed to %0 here", DiagnosticIDs::Note)
+ << Spec->getSpecializedTemplate();
}
NonParam.dumpAnnotationReason(*this, T, p->getLocation());
}
}
}
--- a/build/clang-plugin/NonParamInsideFunctionDeclChecker.h
+++ b/build/clang-plugin/NonParamInsideFunctionDeclChecker.h
@@ -6,14 +6,14 @@
#define NonParamInsideFunctionDeclChecker_h__
#include "plugin.h"
class NonParamInsideFunctionDeclChecker : public BaseCheck {
public:
NonParamInsideFunctionDeclChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/OverrideBaseCallChecker.cpp
+++ b/build/clang-plugin/OverrideBaseCallChecker.cpp
@@ -1,95 +1,93 @@
/* 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 "OverrideBaseCallChecker.h"
#include "CustomMatchers.h"
-void OverrideBaseCallChecker::registerMatchers(MatchFinder* AstMatcher) {
- AstMatcher->addMatcher(cxxRecordDecl(hasBaseClasses()).bind("class"),
- this);
+void OverrideBaseCallChecker::registerMatchers(MatchFinder *AstMatcher) {
+ AstMatcher->addMatcher(cxxRecordDecl(hasBaseClasses()).bind("class"), this);
}
bool OverrideBaseCallChecker::isRequiredBaseMethod(
const CXXMethodDecl *Method) {
return hasCustomAnnotation(Method, "moz_required_base_method");
}
void OverrideBaseCallChecker::evaluateExpression(
- const Stmt *StmtExpr, std::list<const CXXMethodDecl*> &MethodList) {
+ const Stmt *StmtExpr, std::list<const CXXMethodDecl *> &MethodList) {
// Continue while we have methods in our list
if (!MethodList.size()) {
return;
}
if (auto MemberFuncCall = dyn_cast<CXXMemberCallExpr>(StmtExpr)) {
- if (auto Method = dyn_cast<CXXMethodDecl>(
- MemberFuncCall->getDirectCallee())) {
+ if (auto Method =
+ dyn_cast<CXXMethodDecl>(MemberFuncCall->getDirectCallee())) {
findBaseMethodCall(Method, MethodList);
}
}
for (auto S : StmtExpr->children()) {
if (S) {
evaluateExpression(S, MethodList);
}
}
}
void OverrideBaseCallChecker::getRequiredBaseMethod(
const CXXMethodDecl *Method,
- std::list<const CXXMethodDecl*>& MethodsList) {
+ std::list<const CXXMethodDecl *> &MethodsList) {
if (isRequiredBaseMethod(Method)) {
MethodsList.push_back(Method);
} else {
// Loop through all it's base methods.
for (auto BaseMethod = Method->begin_overridden_methods();
- BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
+ BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
getRequiredBaseMethod(*BaseMethod, MethodsList);
}
}
}
void OverrideBaseCallChecker::findBaseMethodCall(
- const CXXMethodDecl* Method,
- std::list<const CXXMethodDecl*>& MethodsList) {
+ const CXXMethodDecl *Method,
+ std::list<const CXXMethodDecl *> &MethodsList) {
MethodsList.remove(Method);
// Loop also through all it's base methods;
for (auto BaseMethod = Method->begin_overridden_methods();
- BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
+ BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
findBaseMethodCall(*BaseMethod, MethodsList);
}
}
-void OverrideBaseCallChecker::check(
- const MatchFinder::MatchResult &Result) {
- const char* Error =
+void OverrideBaseCallChecker::check(const MatchFinder::MatchResult &Result) {
+ const char *Error =
"Method %0 must be called in all overrides, but is not called in "
"this override defined for class %1";
const CXXRecordDecl *Decl = Result.Nodes.getNodeAs<CXXRecordDecl>("class");
// Loop through the methods and look for the ones that are overridden.
for (auto Method : Decl->methods()) {
// If this method doesn't override other methods or it doesn't have a body,
// continue to the next declaration.
if (!Method->size_overridden_methods() || !Method->hasBody()) {
continue;
}
// Preferred the usage of list instead of vector in order to avoid
// calling erase-remove when deleting items
- std::list<const CXXMethodDecl*> MethodsList;
+ std::list<const CXXMethodDecl *> MethodsList;
// For each overridden method push it to a list if it meets our
// criteria
for (auto BaseMethod = Method->begin_overridden_methods();
- BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
+ BaseMethod != Method->end_overridden_methods(); BaseMethod++) {
getRequiredBaseMethod(*BaseMethod, MethodsList);
}
// If no method has been found then no annotation was used
// so checking is not needed
if (!MethodsList.size()) {
continue;
}
@@ -100,13 +98,12 @@ void OverrideBaseCallChecker::check(
// If list is not empty pop up errors
for (auto BaseMethod : MethodsList) {
std::string QualName;
raw_string_ostream OS(QualName);
BaseMethod->printQualifiedName(OS);
diag(Method->getLocation(), Error, DiagnosticIDs::Error)
- << OS.str()
- << Decl->getName();
+ << OS.str() << Decl->getName();
}
}
}
--- a/build/clang-plugin/OverrideBaseCallChecker.h
+++ b/build/clang-plugin/OverrideBaseCallChecker.h
@@ -4,24 +4,24 @@
#ifndef OverrideBaseCallChecker_h__
#define OverrideBaseCallChecker_h__
#include "plugin.h"
class OverrideBaseCallChecker : public BaseCheck {
public:
- OverrideBaseCallChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ OverrideBaseCallChecker(StringRef CheckName, ContextType *Context = nullptr)
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
+
private:
void evaluateExpression(const Stmt *StmtExpr,
- std::list<const CXXMethodDecl*> &MethodList);
- void getRequiredBaseMethod(const CXXMethodDecl* Method,
- std::list<const CXXMethodDecl*>& MethodsList);
- void findBaseMethodCall(const CXXMethodDecl* Method,
- std::list<const CXXMethodDecl*>& MethodsList);
+ std::list<const CXXMethodDecl *> &MethodList);
+ void getRequiredBaseMethod(const CXXMethodDecl *Method,
+ std::list<const CXXMethodDecl *> &MethodsList);
+ void findBaseMethodCall(const CXXMethodDecl *Method,
+ std::list<const CXXMethodDecl *> &MethodsList);
bool isRequiredBaseMethod(const CXXMethodDecl *Method);
};
#endif
--- a/build/clang-plugin/OverrideBaseCallUsageChecker.cpp
+++ b/build/clang-plugin/OverrideBaseCallUsageChecker.cpp
@@ -1,21 +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 "OverrideBaseCallUsageChecker.h"
#include "CustomMatchers.h"
-void OverrideBaseCallUsageChecker::registerMatchers(MatchFinder* AstMatcher) {
+void OverrideBaseCallUsageChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
cxxMethodDecl(isNonVirtual(), isRequiredBaseMethod()).bind("method"),
this);
}
void OverrideBaseCallUsageChecker::check(
const MatchFinder::MatchResult &Result) {
- const char* Error =
+ const char *Error =
"MOZ_REQUIRED_BASE_METHOD can be used only on virtual methods";
const CXXMethodDecl *Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
diag(Method->getLocation(), Error, DiagnosticIDs::Error);
}
--- a/build/clang-plugin/OverrideBaseCallUsageChecker.h
+++ b/build/clang-plugin/OverrideBaseCallUsageChecker.h
@@ -10,14 +10,14 @@
/*
* This is a companion checker for OverrideBaseCallChecker that rejects
* the usage of MOZ_REQUIRED_BASE_METHOD on non-virtual base methods.
*/
class OverrideBaseCallUsageChecker : public BaseCheck {
public:
OverrideBaseCallUsageChecker(StringRef CheckName = "override-base-call-usage",
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/RecurseGuard.h
+++ b/build/clang-plugin/RecurseGuard.h
@@ -12,52 +12,45 @@
//
// Constructing a RecurseGuard sets up a shared backing store which tracks the
// currently observed objects. Whenever recursing, use RecurseGuard.recurse(T)
// to construct another RecurseGuard with the same backing store.
//
// The RecurseGuard object will unregister its object when it is destroyed, and
// has a method `isRepeat()` which will return `true` if the item was already
// seen.
-template<typename T>
-class RecurseGuard {
+template <typename T> class RecurseGuard {
public:
RecurseGuard(T Thing) : Thing(Thing), Set(new DenseSet<T>()), Repeat(false) {
Set->insert(Thing);
}
- RecurseGuard(T Thing, std::shared_ptr<DenseSet<T>>& Set)
- : Thing(Thing), Set(Set), Repeat(false) {
+ RecurseGuard(T Thing, std::shared_ptr<DenseSet<T>> &Set)
+ : Thing(Thing), Set(Set), Repeat(false) {
Repeat = !Set->insert(Thing).second;
}
RecurseGuard(const RecurseGuard &) = delete;
- RecurseGuard(RecurseGuard && Other)
- : Thing(Other.Thing), Set(Other.Set), Repeat(Other.Repeat) {
+ RecurseGuard(RecurseGuard &&Other)
+ : Thing(Other.Thing), Set(Other.Set), Repeat(Other.Repeat) {
Other.Repeat = true;
}
~RecurseGuard() {
if (!Repeat) {
Set->erase(Thing);
}
}
bool isRepeat() { return Repeat; }
T get() { return Thing; }
- operator T() {
- return Thing;
- }
+ operator T() { return Thing; }
- T operator ->() {
- return Thing;
- }
+ T operator->() { return Thing; }
- RecurseGuard recurse(T NewThing) {
- return RecurseGuard(NewThing, Set);
- }
+ RecurseGuard recurse(T NewThing) { return RecurseGuard(NewThing, Set); }
private:
T Thing;
std::shared_ptr<DenseSet<T>> Set;
bool Repeat;
};
#endif // RecurseGuard_h__
--- a/build/clang-plugin/RefCountedCopyConstructorChecker.cpp
+++ b/build/clang-plugin/RefCountedCopyConstructorChecker.cpp
@@ -1,34 +1,34 @@
/* 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 "RefCountedCopyConstructorChecker.h"
#include "CustomMatchers.h"
-void RefCountedCopyConstructorChecker::registerMatchers(MatchFinder* AstMatcher) {
+void RefCountedCopyConstructorChecker::registerMatchers(
+ MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
cxxConstructExpr(
hasDeclaration(cxxConstructorDecl(isCompilerProvidedCopyConstructor(),
ofClass(hasRefCntMember()))))
.bind("node"),
this);
}
void RefCountedCopyConstructorChecker::check(
const MatchFinder::MatchResult &Result) {
- const char* Error =
+ const char *Error =
"Invalid use of compiler-provided copy constructor on refcounted type";
- const char* Note =
- "The default copy constructor also copies the "
- "default mRefCnt property, leading to reference "
- "count imbalance issues. Please provide your own "
- "copy constructor which only copies the fields which "
- "need to be copied";
+ const char *Note = "The default copy constructor also copies the "
+ "default mRefCnt property, leading to reference "
+ "count imbalance issues. Please provide your own "
+ "copy constructor which only copies the fields which "
+ "need to be copied";
// Everything we needed to know was checked in the matcher - we just report
// the error here
const CXXConstructExpr *E = Result.Nodes.getNodeAs<CXXConstructExpr>("node");
diag(E->getLocation(), Error, DiagnosticIDs::Error);
diag(E->getLocation(), Note, DiagnosticIDs::Note);
}
--- a/build/clang-plugin/RefCountedCopyConstructorChecker.h
+++ b/build/clang-plugin/RefCountedCopyConstructorChecker.h
@@ -6,14 +6,14 @@
#define RefCountedCopyConstructorChecker_h__
#include "plugin.h"
class RefCountedCopyConstructorChecker : public BaseCheck {
public:
RefCountedCopyConstructorChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/RefCountedInsideLambdaChecker.cpp
+++ b/build/clang-plugin/RefCountedInsideLambdaChecker.cpp
@@ -2,54 +2,53 @@
* 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 "RefCountedInsideLambdaChecker.h"
#include "CustomMatchers.h"
RefCountedMap RefCountedClasses;
-void RefCountedInsideLambdaChecker::registerMatchers(MatchFinder* AstMatcher) {
+void RefCountedInsideLambdaChecker::registerMatchers(MatchFinder *AstMatcher) {
// We want to reject any code which captures a pointer to an object of a
// refcounted type, and then lets that value escape. As a primitive analysis,
// we reject any occurances of the lambda as a template parameter to a class
// (which could allow it to escape), as well as any presence of such a lambda
// in a return value (either from lambdas, or in c++14, auto functions).
//
// We check these lambdas' capture lists for raw pointers to refcounted types.
+ AstMatcher->addMatcher(functionDecl(returns(recordType(hasDeclaration(
+ cxxRecordDecl(isLambdaDecl()).bind("decl"))))),
+ this);
+ AstMatcher->addMatcher(lambdaExpr().bind("lambdaExpr"), this);
AstMatcher->addMatcher(
- functionDecl(returns(recordType(hasDeclaration(cxxRecordDecl(
- isLambdaDecl()).bind("decl"))))),
- this);
- AstMatcher->addMatcher(lambdaExpr().bind("lambdaExpr"),
- this);
- AstMatcher->addMatcher(
- classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(
- recordType(hasDeclaration(cxxRecordDecl(
- isLambdaDecl()).bind("decl")))))),
+ classTemplateSpecializationDecl(
+ hasAnyTemplateArgument(refersToType(recordType(
+ hasDeclaration(cxxRecordDecl(isLambdaDecl()).bind("decl")))))),
this);
}
void RefCountedInsideLambdaChecker::emitDiagnostics(SourceLocation Loc,
StringRef Name,
QualType Type) {
- diag(Loc, "Refcounted variable '%0' of type %1 cannot be captured by a lambda",
- DiagnosticIDs::Error) << Name << Type;
- diag(Loc, "Please consider using a smart pointer",
- DiagnosticIDs::Note);
+ diag(Loc,
+ "Refcounted variable '%0' of type %1 cannot be captured by a lambda",
+ DiagnosticIDs::Error)
+ << Name << Type;
+ diag(Loc, "Please consider using a smart pointer", DiagnosticIDs::Note);
}
void RefCountedInsideLambdaChecker::check(
const MatchFinder::MatchResult &Result) {
- static DenseSet<const CXXRecordDecl*> CheckedDecls;
+ static DenseSet<const CXXRecordDecl *> CheckedDecls;
const CXXRecordDecl *Lambda = Result.Nodes.getNodeAs<CXXRecordDecl>("decl");
if (const LambdaExpr *OuterLambda =
- Result.Nodes.getNodeAs<LambdaExpr>("lambdaExpr")) {
+ Result.Nodes.getNodeAs<LambdaExpr>("lambdaExpr")) {
const CXXMethodDecl *OpCall = OuterLambda->getCallOperator();
QualType ReturnTy = OpCall->getReturnType();
if (const CXXRecordDecl *Record = ReturnTy->getAsCXXRecordDecl()) {
Lambda = Record;
}
}
if (!Lambda || !Lambda->isLambda()) {
@@ -59,29 +58,30 @@ void RefCountedInsideLambdaChecker::chec
// Don't report errors on the same declarations more than once.
if (CheckedDecls.count(Lambda)) {
return;
}
CheckedDecls.insert(Lambda);
bool StrongRefToThisCaptured = false;
- for (const LambdaCapture& Capture : Lambda->captures()) {
+ for (const LambdaCapture &Capture : Lambda->captures()) {
// Check if any of the captures are ByRef. If they are, we have nothing to
- // report, as it's OK to capture raw pointers to refcounted objects so long as
- // the Lambda doesn't escape the current scope, which is required by ByRef
- // captures already.
+ // report, as it's OK to capture raw pointers to refcounted objects so long
+ // as the Lambda doesn't escape the current scope, which is required by
+ // ByRef captures already.
if (Capture.getCaptureKind() == LCK_ByRef) {
return;
}
- // Check if this capture is byvalue, and captures a strong reference to this.
- // XXX: Do we want to make sure that this type which we are capturing is a "Smart Pointer" somehow?
- if (!StrongRefToThisCaptured &&
- Capture.capturesVariable() &&
+ // Check if this capture is byvalue, and captures a strong reference to
+ // this.
+ // XXX: Do we want to make sure that this type which we are capturing is a
+ // "Smart Pointer" somehow?
+ if (!StrongRefToThisCaptured && Capture.capturesVariable() &&
Capture.getCaptureKind() == LCK_ByCopy) {
const VarDecl *Var = Capture.getCapturedVar();
if (Var->hasInit()) {
const Stmt *Init = Var->getInit();
// Ignore single argument constructors, and trivial nodes.
while (true) {
auto NewInit = IgnoreTrivials(Init);
@@ -98,52 +98,55 @@ void RefCountedInsideLambdaChecker::chec
if (isa<CXXThisExpr>(Init)) {
StrongRefToThisCaptured = true;
}
}
}
}
- // Now we can go through and produce errors for any captured variables or this pointers.
- for (const LambdaCapture& Capture : Lambda->captures()) {
+ // Now we can go through and produce errors for any captured variables or this
+ // pointers.
+ for (const LambdaCapture &Capture : Lambda->captures()) {
if (Capture.capturesVariable()) {
QualType Pointee = Capture.getCapturedVar()->getType()->getPointeeType();
if (!Pointee.isNull() && isClassRefCounted(Pointee)) {
- emitDiagnostics(Capture.getLocation(), Capture.getCapturedVar()->getName(), Pointee);
+ emitDiagnostics(Capture.getLocation(),
+ Capture.getCapturedVar()->getName(), Pointee);
return;
}
}
// The situation with captures of `this` is more complex. All captures of
// `this` look the same-ish (they are LCK_This). We want to complain about
// captures of `this` where `this` is a refcounted type, and the capture is
// actually used in the body of the lambda (if the capture isn't used, then
// we don't care, because it's only being captured in order to give access
// to private methods).
//
// In addition, we don't complain about this, even if it is used, if it was
// captured implicitly when the LambdaCaptureDefault was LCD_ByRef, as that
// expresses the intent that the lambda won't leave the enclosing scope.
bool ImplicitByRefDefaultedCapture =
- Capture.isImplicit() && Lambda->getLambdaCaptureDefault() == LCD_ByRef;
- if (Capture.capturesThis() &&
- !ImplicitByRefDefaultedCapture &&
+ Capture.isImplicit() && Lambda->getLambdaCaptureDefault() == LCD_ByRef;
+ if (Capture.capturesThis() && !ImplicitByRefDefaultedCapture &&
!StrongRefToThisCaptured) {
ThisVisitor V(*this);
- bool NotAborted = V.TraverseDecl(const_cast<CXXMethodDecl *>(Lambda->getLambdaCallOperator()));
+ bool NotAborted = V.TraverseDecl(
+ const_cast<CXXMethodDecl *>(Lambda->getLambdaCallOperator()));
if (!NotAborted) {
return;
}
}
}
}
-bool RefCountedInsideLambdaChecker::ThisVisitor::VisitCXXThisExpr(CXXThisExpr *This) {
+bool RefCountedInsideLambdaChecker::ThisVisitor::VisitCXXThisExpr(
+ CXXThisExpr *This) {
QualType Pointee = This->getType()->getPointeeType();
if (!Pointee.isNull() && isClassRefCounted(Pointee)) {
Checker.emitDiagnostics(This->getLocStart(), "this", Pointee);
return false;
}
return true;
}
--- a/build/clang-plugin/RefCountedInsideLambdaChecker.h
+++ b/build/clang-plugin/RefCountedInsideLambdaChecker.h
@@ -6,27 +6,28 @@
#define RefCountedInsideLambdaChecker_h__
#include "plugin.h"
class RefCountedInsideLambdaChecker : public BaseCheck {
public:
RefCountedInsideLambdaChecker(StringRef CheckName,
ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
void emitDiagnostics(SourceLocation Loc, StringRef Name, QualType Type);
private:
class ThisVisitor : public RecursiveASTVisitor<ThisVisitor> {
public:
- explicit ThisVisitor(RefCountedInsideLambdaChecker& Checker)
- : Checker(Checker) {}
+ explicit ThisVisitor(RefCountedInsideLambdaChecker &Checker)
+ : Checker(Checker) {}
bool VisitCXXThisExpr(CXXThisExpr *This);
+
private:
- RefCountedInsideLambdaChecker& Checker;
+ RefCountedInsideLambdaChecker &Checker;
};
};
#endif
--- a/build/clang-plugin/ScopeChecker.cpp
+++ b/build/clang-plugin/ScopeChecker.cpp
@@ -1,22 +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 "ScopeChecker.h"
#include "CustomMatchers.h"
-void ScopeChecker::registerMatchers(MatchFinder* AstMatcher) {
+void ScopeChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(varDecl().bind("node"), this);
AstMatcher->addMatcher(cxxNewExpr().bind("node"), this);
AstMatcher->addMatcher(materializeTemporaryExpr().bind("node"), this);
AstMatcher->addMatcher(
- callExpr(callee(functionDecl(heapAllocator()))).bind("node"),
- this);
+ callExpr(callee(functionDecl(heapAllocator()))).bind("node"), this);
AstMatcher->addMatcher(parmVarDecl().bind("parm_vardecl"), this);
}
// These enum variants determine whether an allocation has occured in the code.
enum AllocationVariety {
AV_None,
AV_Global,
AV_Automatic,
@@ -26,18 +25,17 @@ enum AllocationVariety {
// XXX Currently the Decl* in the AutomaticTemporaryMap is unused, but it
// probably will be used at some point in the future, in order to produce better
// error messages.
typedef DenseMap<const MaterializeTemporaryExpr *, const Decl *>
AutomaticTemporaryMap;
AutomaticTemporaryMap AutomaticTemporaries;
-void ScopeChecker::check(
- const MatchFinder::MatchResult &Result) {
+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;
if (const ParmVarDecl *D =
Result.Nodes.getNodeAs<ParmVarDecl>("parm_vardecl")) {
if (D->hasUnparsedDefaultArg() || D->hasUninstantiatedDefaultArg()) {
@@ -115,35 +113,27 @@ void ScopeChecker::check(
// This will always allocate on the heap, as the heapAllocator() check
// was made in the matcher
Variety = AV_Heap;
Loc = E->getLocStart();
}
}
// Error messages for incorrect allocations.
- const char* Stack =
- "variable of type %0 only valid on the stack";
- const char* Global =
- "variable of type %0 only valid as global";
- const char* Heap =
- "variable of type %0 only valid on the heap";
- const char* NonHeap =
- "variable of type %0 is not valid on the heap";
- const char* NonTemporary =
- "variable of type %0 is not valid in a temporary";
+ const char *Stack = "variable of type %0 only valid on the stack";
+ const char *Global = "variable of type %0 only valid as global";
+ const char *Heap = "variable of type %0 only valid on the heap";
+ const char *NonHeap = "variable of type %0 is not valid on the heap";
+ const char *NonTemporary = "variable of type %0 is not valid in a temporary";
- const char* StackNote =
+ const char *StackNote =
"value incorrectly allocated in an automatic variable";
- const char* GlobalNote =
- "value incorrectly allocated in a global variable";
- const char* HeapNote =
- "value incorrectly allocated on the heap";
- const char* TemporaryNote =
- "value incorrectly allocated in a temporary";
+ const char *GlobalNote = "value incorrectly allocated in a global variable";
+ const char *HeapNote = "value incorrectly allocated on the heap";
+ const char *TemporaryNote = "value incorrectly allocated in a temporary";
// Report errors depending on the annotations on the input types.
switch (Variety) {
case AV_None:
return;
case AV_Global:
StackClass.reportErrorIfPresent(*this, T, Loc, Stack, GlobalNote);
--- a/build/clang-plugin/ScopeChecker.h
+++ b/build/clang-plugin/ScopeChecker.h
@@ -5,14 +5,14 @@
#ifndef ScopeChecker_h__
#define ScopeChecker_h__
#include "plugin.h"
class ScopeChecker : public BaseCheck {
public:
ScopeChecker(StringRef CheckName, ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ : BaseCheck(CheckName, Context) {}
+ void registerMatchers(MatchFinder *AstMatcher) override;
void check(const MatchFinder::MatchResult &Result) override;
};
#endif
--- a/build/clang-plugin/SprintfLiteralChecker.cpp
+++ b/build/clang-plugin/SprintfLiteralChecker.cpp
@@ -1,40 +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/. */
#include "SprintfLiteralChecker.h"
#include "CustomMatchers.h"
-void SprintfLiteralChecker::registerMatchers(MatchFinder* AstMatcher) {
+void SprintfLiteralChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(
- callExpr(isSnprintfLikeFunc(),
- allOf(hasArgument(0, ignoringParenImpCasts(declRefExpr().bind("buffer"))),
- anyOf(hasArgument(1, sizeOfExpr(hasIgnoringParenImpCasts(declRefExpr().bind("size")))),
- hasArgument(1, integerLiteral().bind("immediate")),
- hasArgument(1, declRefExpr(to(varDecl(hasType(isConstQualified()),
- hasInitializer(integerLiteral().bind("constant")))))))))
- .bind("funcCall"),
- this
- );
+ callExpr(
+ isSnprintfLikeFunc(),
+ allOf(hasArgument(
+ 0, ignoringParenImpCasts(declRefExpr().bind("buffer"))),
+ anyOf(hasArgument(1, sizeOfExpr(hasIgnoringParenImpCasts(
+ declRefExpr().bind("size")))),
+ hasArgument(1, integerLiteral().bind("immediate")),
+ hasArgument(1, declRefExpr(to(varDecl(
+ hasType(isConstQualified()),
+ hasInitializer(integerLiteral().bind(
+ "constant")))))))))
+ .bind("funcCall"),
+ this);
}
-void SprintfLiteralChecker::check(
- const MatchFinder::MatchResult &Result) {
+void SprintfLiteralChecker::check(const MatchFinder::MatchResult &Result) {
if (!Result.Context->getLangOpts().CPlusPlus) {
// SprintfLiteral is not usable in C, so there is no point in issuing these
// warnings.
return;
}
- const char* Error =
- "Use %1 instead of %0 when writing into a character array.";
- const char* Note =
- "This will prevent passing in the wrong size to %0 accidentally.";
+ const char *Error =
+ "Use %1 instead of %0 when writing into a character array.";
+ const char *Note =
+ "This will prevent passing in the wrong size to %0 accidentally.";
const CallExpr *D = Result.Nodes.getNodeAs<CallExpr>("funcCall");
StringRef Name = D->getDirectCallee()->getName();
const char *Replacement;
if (Name == "snprintf") {
Replacement = "SprintfLiteral";
} else {
@@ -51,27 +54,31 @@ void SprintfLiteralChecker::check(
}
diag(D->getLocStart(), Error, DiagnosticIDs::Error) << Name << Replacement;
diag(D->getLocStart(), Note, DiagnosticIDs::Note) << Name;
return;
}
const QualType QType = Buffer->getType();
- const ConstantArrayType *Type = dyn_cast<ConstantArrayType>(QType.getTypePtrOrNull());
+ const ConstantArrayType *Type =
+ dyn_cast<ConstantArrayType>(QType.getTypePtrOrNull());
if (Type) {
// Match calls like snprintf(x, 100, ...), where x is int[100];
- const IntegerLiteral *Literal = Result.Nodes.getNodeAs<IntegerLiteral>("immediate");
+ const IntegerLiteral *Literal =
+ Result.Nodes.getNodeAs<IntegerLiteral>("immediate");
if (!Literal) {
// Match calls like: const int y = 100; snprintf(x, y, ...);
Literal = Result.Nodes.getNodeAs<IntegerLiteral>("constant");
}
- // We're going to assume here that the bitwidth of both of these values fits within 64 bits.
- // and zero-extend both values to 64-bits before comparing them.
+ // We're going to assume here that the bitwidth of both of these values fits
+ // within 64 bits. and zero-extend both values to 64-bits before comparing
+ // them.
uint64_t Size = Type->getSize().getZExtValue();
uint64_t Lit = Literal->getValue().getZExtValue();
if (Size <= Lit) {
- diag(D->getLocStart(), Error, DiagnosticIDs::Error) << Name << Replacement;
+ diag(D->getLocStart(), Error, DiagnosticIDs::Error)
+ << Name << Replacement;
diag(D->getLocStart(), Note, DiagnosticIDs::Note) << Name;
}
}
}
--- a/build/clang-plugin/SprintfLiteralChecker.h
+++ b/build/clang-plugin/SprintfLiteralChecker.h
@@ -4,16 +4,15 @@
#ifndef SprintfLiteralChecker_h__
#define SprintfLiteralChecker_h__
#include "plugin.h"
class SprintfLiteralChecker : public BaseCheck {
public:
- SprintfLiteralChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ SprintfLiteralChecker(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/StmtToBlockMap.h
+++ b/build/clang-plugin/StmtToBlockMap.h
@@ -33,52 +33,56 @@ inline SmallVector<const Stmt *, 1> getP
Parents = Context->getParents(Node);
NodesToProcess.append(Parents.begin(), Parents.end());
}
}
return Result;
}
-// This class is a modified version of the class from clang-tidy's ExprSequence.cpp
+// This class is a modified version of the class from clang-tidy's
+// ExprSequence.cpp
//
// Maps `Stmt`s to the `CFGBlock` that contains them. Some `Stmt`s may be
// contained in more than one `CFGBlock`; in this case, they are mapped to the
// innermost block (i.e. the one that is furthest from the root of the tree).
// An optional outparameter provides the index into the block where the `Stmt`
// was found.
class StmtToBlockMap {
public:
// Initializes the map for the given `CFG`.
- StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext) : Context(TheContext) {
+ StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext)
+ : Context(TheContext) {
for (const auto *B : *TheCFG) {
for (size_t I = 0; I < B->size(); ++I) {
if (Optional<CFGStmt> S = (*B)[I].getAs<CFGStmt>()) {
Map[S->getStmt()] = std::make_pair(B, I);
}
}
}
}
// Returns the block that S is contained in. Some `Stmt`s may be contained
// in more than one `CFGBlock`; in this case, this function returns the
// innermost block (i.e. the one that is furthest from the root of the tree).
//
// The optional outparameter `Index` is set to the index into the block where
// the `Stmt` was found.
- const CFGBlock *blockContainingStmt(const Stmt *S, size_t *Index = nullptr) const {
+ const CFGBlock *blockContainingStmt(const Stmt *S,
+ size_t *Index = nullptr) const {
while (!Map.count(S)) {
SmallVector<const Stmt *, 1> Parents = getParentStmts(S, Context);
if (Parents.empty())
return nullptr;
S = Parents[0];
}
const auto &E = Map.lookup(S);
- if (Index) *Index = E.second;
+ if (Index)
+ *Index = E.second;
return E.first;
}
private:
ASTContext *Context;
llvm::DenseMap<const Stmt *, std::pair<const CFGBlock *, size_t>> Map;
};
--- a/build/clang-plugin/ThirdPartyPaths.h
+++ b/build/clang-plugin/ThirdPartyPaths.h
@@ -1,13 +1,13 @@
#ifndef ThirdPartyPaths_h__
#define ThirdPartyPaths_h__
#include <stdint.h>
// These two values are defined in ThirdPartyPaths.cpp, which is a file
// generated by ThirdPartyPaths.py.
-extern const char* MOZ_THIRD_PARTY_PATHS[];
+extern const char *MOZ_THIRD_PARTY_PATHS[];
extern const uint32_t MOZ_THIRD_PARTY_PATHS_COUNT;
#endif
--- a/build/clang-plugin/TrivialCtorDtorChecker.cpp
+++ b/build/clang-plugin/TrivialCtorDtorChecker.cpp
@@ -1,24 +1,22 @@
/* 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 "TrivialCtorDtorChecker.h"
#include "CustomMatchers.h"
-void TrivialCtorDtorChecker::registerMatchers(MatchFinder* AstMatcher) {
+void TrivialCtorDtorChecker::registerMatchers(MatchFinder *AstMatcher) {
AstMatcher->addMatcher(cxxRecordDecl(hasTrivialCtorDtor()).bind("node"),
this);
}
-void TrivialCtorDtorChecker::check(
- const MatchFinder::MatchResult &Result) {
- const char* Error =
- "class %0 must have trivial constructors and destructors";
+void TrivialCtorDtorChecker::check(const MatchFinder::MatchResult &Result) {
+ const char *Error = "class %0 must have trivial constructors and destructors";
const CXXRecordDecl *Node = Result.Nodes.getNodeAs<CXXRecordDecl>("node");
if (!Node->hasDefinition()) {
return;
}
// We need to accept non-constexpr trivial constructors as well. This occurs
// when a struct contains pod members, which will not be initialized. As
--- a/build/clang-plugin/TrivialCtorDtorChecker.h
+++ b/build/clang-plugin/TrivialCtorDtorChecker.h
@@ -4,16 +4,15 @@
#ifndef TrivialCtorDtorChecker_h__
#define TrivialCtorDtorChecker_h__
#include "plugin.h"
class TrivialCtorDtorChecker : public BaseCheck {
public:
- TrivialCtorDtorChecker(StringRef CheckName,
- ContextType *Context = nullptr)
- : BaseCheck(CheckName, Context) {}
- void registerMatchers(MatchFinder* AstMatcher) override;
+ TrivialCtorDtorChecker(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/Utils.h
+++ b/build/clang-plugin/Utils.h
@@ -423,17 +423,17 @@ inline bool inThirdPartyPath(SourceLocat
inline bool inThirdPartyPath(const Decl *D, ASTContext *context) {
D = D->getCanonicalDecl();
SourceLocation Loc = D->getLocation();
const SourceManager &SM = context->getSourceManager();
return inThirdPartyPath(Loc, SM);
}
-inline CXXRecordDecl* getNonTemplateSpecializedCXXRecordDecl(QualType Q) {
+inline CXXRecordDecl *getNonTemplateSpecializedCXXRecordDecl(QualType Q) {
auto *D = Q->getAsCXXRecordDecl();
if (!D) {
auto TemplateQ = Q->getAs<TemplateSpecializationType>();
if (!TemplateQ) {
return nullptr;
}
@@ -458,27 +458,27 @@ inline bool inThirdPartyPath(const Decl
inline bool inThirdPartyPath(const Stmt *S, ASTContext *context) {
SourceLocation Loc = S->getLocStart();
const SourceManager &SM = context->getSourceManager();
return inThirdPartyPath(Loc, SM);
}
/// Polyfill for CXXOperatorCallExpr::isInfixBinaryOp()
-inline bool isInfixBinaryOp(const CXXOperatorCallExpr* OpCall) {
+inline bool isInfixBinaryOp(const CXXOperatorCallExpr *OpCall) {
#if CLANG_VERSION_FULL >= 400
return OpCall->isInfixBinaryOp();
#else
// Taken from clang source.
if (OpCall->getNumArgs() != 2)
- return false;
+ return false;
switch (OpCall->getOperator()) {
- case OO_Call: case OO_Subscript:
- return false;
- default:
- return true;
+ case OO_Call:
+ case OO_Subscript:
+ return false;
+ default:
+ return true;
}
#endif
}
-
#endif
--- a/build/clang-plugin/VariableUsageHelpers.cpp
+++ b/build/clang-plugin/VariableUsageHelpers.cpp
@@ -1,33 +1,31 @@
#include "VariableUsageHelpers.h"
#include "Utils.h"
-std::vector<const Stmt*>
-getUsageAsRvalue(const ValueDecl* ValueDeclaration,
- const FunctionDecl* FuncDecl) {
- std::vector<const Stmt*> UsageStatements;
+std::vector<const Stmt *> getUsageAsRvalue(const ValueDecl *ValueDeclaration,
+ const FunctionDecl *FuncDecl) {
+ std::vector<const Stmt *> UsageStatements;
// We check the function declaration has a body.
auto Body = FuncDecl->getBody();
if (!Body) {
- return std::vector<const Stmt*>();
+ return std::vector<const Stmt *>();
}
// We build a Control Flow Graph (CFG) fron the body of the function
// declaration.
- std::unique_ptr<CFG> StatementCFG
- = CFG::buildCFG(FuncDecl, Body, &FuncDecl->getASTContext(),
- CFG::BuildOptions());
+ std::unique_ptr<CFG> StatementCFG = CFG::buildCFG(
+ FuncDecl, Body, &FuncDecl->getASTContext(), CFG::BuildOptions());
// We iterate through all the CFGBlocks, which basically means that we go over
// all the possible branches of the code and therefore cover all statements.
- for (auto& Block : *StatementCFG) {
+ for (auto &Block : *StatementCFG) {
// We iterate through all the statements of the block.
- for (auto& BlockItem : *Block) {
+ for (auto &BlockItem : *Block) {
Optional<CFGStmt> CFGStatement = BlockItem.getAs<CFGStmt>();
if (!CFGStatement) {
continue;
}
// FIXME: Right now this function/if chain is very basic and only covers
// the cases we need for escapesFunction()
if (auto BinOp = dyn_cast<BinaryOperator>(CFGStatement->getStmt())) {
@@ -45,17 +43,17 @@ getUsageAsRvalue(const ValueDecl* ValueD
if (DeclRef->getDecl() != ValueDeclaration) {
continue;
}
} else if (auto Return = dyn_cast<ReturnStmt>(CFGStatement->getStmt())) {
// We want our declaration to be used as the expression of the return
// statement.
auto DeclRef = dyn_cast_or_null<DeclRefExpr>(
- IgnoreTrivials(Return->getRetValue()));
+ IgnoreTrivials(Return->getRetValue()));
if (!DeclRef) {
continue;
}
if (DeclRef->getDecl() != ValueDeclaration) {
continue;
}
} else {
@@ -66,96 +64,89 @@ getUsageAsRvalue(const ValueDecl* ValueD
UsageStatements.push_back(CFGStatement->getStmt());
}
}
return UsageStatements;
}
// We declare our EscapesFunctionError enum to be an error code enum.
-namespace std
-{
- template <>
- struct is_error_code_enum<EscapesFunctionError> : true_type {};
-}
+namespace std {
+template <> struct is_error_code_enum<EscapesFunctionError> : true_type {};
+} // namespace std
// We define the EscapesFunctionErrorCategory which contains the error messages
// corresponding to each enum variant.
namespace {
- struct EscapesFunctionErrorCategory : std::error_category
- {
- const char* name() const noexcept override;
- std::string message(int ev) const override;
- };
-
- const char* EscapesFunctionErrorCategory::name() const noexcept
- {
- return "escapes function";
- }
-
- std::string EscapesFunctionErrorCategory::message(int ev) const
- {
- switch (static_cast<EscapesFunctionError>(ev))
- {
- case EscapesFunctionError::ConstructorDeclNotFound:
- return "constructor declaration not found";
+struct EscapesFunctionErrorCategory : std::error_category {
+ const char *name() const noexcept override;
+ std::string message(int ev) const override;
+};
- case EscapesFunctionError::FunctionDeclNotFound:
- return "function declaration not found";
-
- case EscapesFunctionError::FunctionIsBuiltin:
- return "function is builtin";
-
- case EscapesFunctionError::FunctionIsVariadic:
- return "function is variadic";
-
- case EscapesFunctionError::ExprNotInCall:
- return "expression is not in call";
-
- case EscapesFunctionError::NoParamForArg:
- return "no parameter for argument";
-
- case EscapesFunctionError::ArgAndParamNotPointers:
- return "argument and parameter are not pointers";
- }
- }
-
- const EscapesFunctionErrorCategory TheEscapesFunctionErrorCategory {};
+const char *EscapesFunctionErrorCategory::name() const noexcept {
+ return "escapes function";
}
-std::error_code make_error_code(EscapesFunctionError e)
-{
+std::string EscapesFunctionErrorCategory::message(int ev) const {
+ switch (static_cast<EscapesFunctionError>(ev)) {
+ case EscapesFunctionError::ConstructorDeclNotFound:
+ return "constructor declaration not found";
+
+ case EscapesFunctionError::FunctionDeclNotFound:
+ return "function declaration not found";
+
+ case EscapesFunctionError::FunctionIsBuiltin:
+ return "function is builtin";
+
+ case EscapesFunctionError::FunctionIsVariadic:
+ return "function is variadic";
+
+ case EscapesFunctionError::ExprNotInCall:
+ return "expression is not in call";
+
+ case EscapesFunctionError::NoParamForArg:
+ return "no parameter for argument";
+
+ case EscapesFunctionError::ArgAndParamNotPointers:
+ return "argument and parameter are not pointers";
+ }
+}
+
+const EscapesFunctionErrorCategory TheEscapesFunctionErrorCategory{};
+} // namespace
+
+std::error_code make_error_code(EscapesFunctionError e) {
return {static_cast<int>(e), TheEscapesFunctionErrorCategory};
}
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CXXConstructExpr* Construct) {
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CXXConstructExpr *Construct) {
// We get the function declaration corresponding to the call.
auto CtorDecl = Construct->getConstructor();
if (!CtorDecl) {
return EscapesFunctionError::ConstructorDeclNotFound;
}
return escapesFunction(Arg, CtorDecl, Construct->getArgs(),
Construct->getNumArgs());
}
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CallExpr* Call) {
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CallExpr *Call) {
// We get the function declaration corresponding to the call.
auto FuncDecl = Call->getDirectCallee();
if (!FuncDecl) {
return EscapesFunctionError::FunctionDeclNotFound;
}
return escapesFunction(Arg, FuncDecl, Call->getArgs(), Call->getNumArgs());
}
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CXXOperatorCallExpr* OpCall) {
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CXXOperatorCallExpr *OpCall) {
// We get the function declaration corresponding to the operator call.
auto FuncDecl = OpCall->getDirectCallee();
if (!FuncDecl) {
return EscapesFunctionError::FunctionDeclNotFound;
}
auto Args = OpCall->getArgs();
auto NumArgs = OpCall->getNumArgs();
@@ -165,21 +156,21 @@ escapesFunction(const Expr* Arg, const C
if (isInfixBinaryOp(OpCall) && FuncDecl->getNumParams() == 1) {
Args++;
NumArgs--;
}
return escapesFunction(Arg, FuncDecl, Args, NumArgs);
}
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const FunctionDecl *FuncDecl,
- const Expr* const* Arguments, unsigned NumArgs) {
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const FunctionDecl *FuncDecl,
+ const Expr *const *Arguments, unsigned NumArgs) {
if (!NumArgs) {
- return std::make_tuple((const Stmt*)nullptr, (const Decl*)nullptr);
+ return std::make_tuple((const Stmt *)nullptr, (const Decl *)nullptr);
}
if (FuncDecl->getBuiltinID() != 0 ||
ASTIsInSystemHeader(FuncDecl->getASTContext(), *FuncDecl)) {
return EscapesFunctionError::FunctionIsBuiltin;
}
// FIXME: should probably be handled at some point, but it's too annoying
@@ -242,38 +233,39 @@ escapesFunction(const Expr* Arg, const F
// *param2 = param1;
// }
// This should be fixed when we have better/more helper functions to
// help deal with this kind of lvalue expressions.
if (!ParamDeclaration->getType()->isReferenceType()) {
continue;
}
- return std::make_tuple(Usage, (const Decl*)ParamDeclaration);
+ return std::make_tuple(Usage, (const Decl *)ParamDeclaration);
} else if (auto VarDeclaration = dyn_cast<VarDecl>(DeclRef->getDecl())) {
// This is the case where the parameter escapes through a global/static
// variable.
if (!VarDeclaration->hasGlobalStorage()) {
continue;
}
- return std::make_tuple(Usage, (const Decl*)VarDeclaration);
- } else if (auto FieldDeclaration = dyn_cast<FieldDecl>(DeclRef->getDecl())) {
+ return std::make_tuple(Usage, (const Decl *)VarDeclaration);
+ } else if (auto FieldDeclaration =
+ dyn_cast<FieldDecl>(DeclRef->getDecl())) {
// This is the case where the parameter escapes through a field.
- return std::make_tuple(Usage, (const Decl*)FieldDeclaration);
+ return std::make_tuple(Usage, (const Decl *)FieldDeclaration);
}
} else if (isa<ReturnStmt>(Usage)) {
// This is the case where the parameter escapes through the return value
// of the function.
- if (!FuncDecl->getReturnType()->isPointerType()
- && !FuncDecl->getReturnType()->isReferenceType()) {
+ if (!FuncDecl->getReturnType()->isPointerType() &&
+ !FuncDecl->getReturnType()->isReferenceType()) {
continue;
}
- return std::make_tuple(Usage, (const Decl*)FuncDecl);
+ return std::make_tuple(Usage, (const Decl *)FuncDecl);
}
}
// No early-return, this means that we haven't found any case of funciton
// escaping and that therefore the parameter remains in the function scope.
- return std::make_tuple((const Stmt*)nullptr, (const Decl*)nullptr);
+ return std::make_tuple((const Stmt *)nullptr, (const Decl *)nullptr);
}
--- a/build/clang-plugin/VariableUsageHelpers.h
+++ b/build/clang-plugin/VariableUsageHelpers.h
@@ -1,27 +1,25 @@
/* 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 VariableUsageHelpers_h__
#define VariableUsageHelpers_h__
#include "plugin.h"
/// Returns a list of the statements where the given declaration is used as an
/// rvalue (within the provided function).
///
/// WARNING: incomplete behaviour/implementation for general-purpose use outside
/// of escapesFunction(). This only detects very basic usages (see
/// implementation for more details).
-std::vector<const Stmt*>
-getUsageAsRvalue(const ValueDecl* ValueDeclaration,
- const FunctionDecl* FuncDecl);
+std::vector<const Stmt *> getUsageAsRvalue(const ValueDecl *ValueDeclaration,
+ const FunctionDecl *FuncDecl);
/// This is the error enumeration for escapesFunction(), describing all the
/// possible error cases.
enum class EscapesFunctionError {
ConstructorDeclNotFound = 1,
FunctionDeclNotFound,
FunctionIsBuiltin,
FunctionIsVariadic,
@@ -41,25 +39,25 @@ std::error_code make_error_code(EscapesF
/// function, the tuple will only contain nullptrs.
/// If the analysis runs into an unexpected error or into an unimplemented
/// configuration, it will return an error_code of type EscapesFunctionError
/// representing the precise issue.
///
/// WARNING: incomplete behaviour/implementation for general-purpose use outside
/// of DanglingOnTemporaryChecker. This only covers a limited set of cases,
/// mainly in terms of arguments and parameter types.
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const FunctionDecl *FuncDecl,
- const Expr* const* Arguments, unsigned NumArgs);
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const FunctionDecl *FuncDecl,
+ const Expr *const *Arguments, unsigned NumArgs);
/// Helper function taking a call expression.
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CallExpr* Call);
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CallExpr *Call);
/// Helper function taking a construct expression.
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CXXConstructExpr* Construct);
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CXXConstructExpr *Construct);
/// Helper function taking an operator call expression.
-ErrorOr<std::tuple<const Stmt*, const Decl*>>
-escapesFunction(const Expr* Arg, const CXXOperatorCallExpr* OpCall);
+ErrorOr<std::tuple<const Stmt *, const Decl *>>
+escapesFunction(const Expr *Arg, const CXXOperatorCallExpr *OpCall);
#endif
--- a/build/clang-plugin/plugin.h
+++ b/build/clang-plugin/plugin.h
@@ -1,30 +1,30 @@
/* 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 plugin_h__
#define plugin_h__
-#include "clang/Analysis/CFG.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
#include "clang/Basic/Version.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include <iterator>
#include <memory>
-#include <iterator>
#define CLANG_VERSION_FULL (CLANG_VERSION_MAJOR * 100 + CLANG_VERSION_MINOR)
using namespace llvm;
using namespace clang;
using namespace clang::ast_matchers;
#if CLANG_VERSION_FULL >= 306
@@ -49,18 +49,18 @@ typedef ASTConsumer *ASTConsumerPtr;
#else
// Before clang 3.9 "has" would behave like has(ignoringParenImpCasts(x)),
// however doing that explicitly would not compile.
#define hasIgnoringParenImpCasts(x) has(ignoringParenImpCasts(x))
#endif
#endif
-// In order to support running our checks using clang-tidy, we implement a source
-// compatible base check class called BaseCheck, and we use the preprocessor to
-// decide which base class to pick.
+// In order to support running our checks using clang-tidy, we implement a
+// source compatible base check class called BaseCheck, and we use the
+// preprocessor to decide which base class to pick.
#ifdef CLANG_TIDY
#include "../ClangTidy.h"
typedef clang::tidy::ClangTidyCheck BaseCheck;
typedef clang::tidy::ClangTidyContext ContextType;
#else
#include "BaseCheck.h"
#endif