diff --git a/build/clang-plugin/CustomMatchers.h b/build/clang-plugin/CustomMatchers.h index 631912fe59ec..1d11cbe3f62d 100644 --- a/build/clang-plugin/CustomMatchers.h +++ b/build/clang-plugin/CustomMatchers.h @@ -126,11 +126,22 @@ AST_MATCHER(QualType, isFloat) { return Node->isRealFloatingType(); } /// This matcher will match locations in system headers. This is adopted from /// isExpansionInSystemHeader in newer clangs, but modified in order to work /// with old clangs that we use on infra. -AST_POLYMORPHIC_MATCHER(isInSystemHeader, \ +AST_POLYMORPHIC_MATCHER(isInSystemHeader, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt)) { return ASTIsInSystemHeader(Finder->getASTContext(), Node); } +/// This matcher will match a file "gtest-port.h". The file contains +/// known fopen usages that are OK. +AST_MATCHER(CallExpr, isInWhitelistForFopenUsage) { + static const char Whitelist[] = "gtest-port.h"; + SourceLocation Loc = Node.getBeginLoc(); + StringRef FileName = + getFilename(Finder->getASTContext().getSourceManager(), Loc); + + return llvm::sys::path::rbegin(FileName)->equals(Whitelist); +} + /// This matcher will match a list of files. These files contain /// known NaN-testing expressions which we would like to whitelist. AST_MATCHER(BinaryOperator, isInWhitelistForNaNExpr) { diff --git a/build/clang-plugin/FopenUsageChecker.cpp b/build/clang-plugin/FopenUsageChecker.cpp index c159ed146903..905fc91f474e 100644 --- a/build/clang-plugin/FopenUsageChecker.cpp +++ b/build/clang-plugin/FopenUsageChecker.cpp @@ -50,7 +50,8 @@ void FopenUsageChecker::registerMatchers(MatchFinder *AstMatcher) { hasIntegerParam(1), hasIntegerParam(2), hasParamOfType(3, "LPSECURITY_ATTRIBUTES"), hasIntegerParam(4), hasIntegerParam(5), - hasParamOfType(6, "HANDLE")))))))) + hasParamOfType(6, "HANDLE")))))), + unless(isInWhitelistForFopenUsage()))) .bind("funcCall"), this); }