Commit 571e0cc7 authored by dcheng's avatar dcheng Committed by Commit bot

Fix extra clang tools build.

BUG=none

Review URL: https://codereview.chromium.org/1611743002

Cr-Commit-Position: refs/heads/master@{#370766}
parent 4302010a
......@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
MCParser
Option
X86AsmParser
X86CodeGen
)
add_llvm_executable(pass_to_move
......
......@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
MCParser
Option
X86AsmParser
X86CodeGen
)
add_llvm_executable(rewrite_scoped_refptr
......
......@@ -22,7 +22,7 @@
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/support/TargetSelect.h"
#include "llvm/Support/TargetSelect.h"
using namespace clang::ast_matchers;
using clang::tooling::CommonOptionsParser;
......@@ -268,14 +268,14 @@ int main(int argc, const char* argv[]) {
MatchFinder match_finder;
Replacements replacements;
auto is_scoped_refptr = recordDecl(isSameOrDerivedFrom("::scoped_refptr"),
isTemplateInstantiation());
auto is_scoped_refptr = cxxRecordDecl(isSameOrDerivedFrom("::scoped_refptr"),
isTemplateInstantiation());
// Finds all calls to conversion operator member function. This catches calls
// to "operator T*", "operator Testable", and "operator bool" equally.
auto base_matcher = memberCallExpr(thisPointerType(is_scoped_refptr),
callee(conversionDecl()),
on(id("arg", expr())));
auto base_matcher =
cxxMemberCallExpr(thisPointerType(is_scoped_refptr),
callee(conversionDecl()), on(id("arg", expr())));
// The heuristic for whether or not converting a temporary is 'unsafe'. An
// unsafe conversion is one where a temporary scoped_refptr<T> is converted to
......@@ -285,7 +285,7 @@ int main(int argc, const char* argv[]) {
// retains the necessary reference, since this is a common idiom to see in
// loop bodies.
auto is_unsafe_temporary_conversion =
on(bindTemporaryExpr(unless(has(operatorCallExpr()))));
on(cxxBindTemporaryExpr(unless(has(cxxOperatorCallExpr()))));
// Returning a scoped_refptr<T> as a T* is considered unsafe if either are
// true:
......@@ -322,12 +322,13 @@ int main(int argc, const char* argv[]) {
auto is_logging_helper =
functionDecl(anyOf(hasName("CheckEQImpl"), hasName("CheckNEImpl")));
auto is_gtest_helper = functionDecl(
anyOf(methodDecl(ofClass(recordDecl(isSameOrDerivedFrom(
hasName("::testing::internal::EqHelper")))),
hasName("Compare")),
anyOf(cxxMethodDecl(ofClass(cxxRecordDecl(isSameOrDerivedFrom(
hasName("::testing::internal::EqHelper")))),
hasName("Compare")),
hasName("::testing::internal::CmpHelperNE")));
auto is_gtest_assertion_result_ctor = constructorDecl(ofClass(
recordDecl(isSameOrDerivedFrom(hasName("::testing::AssertionResult")))));
auto is_gtest_assertion_result_ctor =
cxxConstructorDecl(ofClass(cxxRecordDecl(
isSameOrDerivedFrom(hasName("::testing::AssertionResult")))));
// Find all calls to an operator overload that are 'safe'.
//
......@@ -336,7 +337,7 @@ int main(int argc, const char* argv[]) {
// the call ambiguous.
GetRewriterCallback get_callback(&replacements);
match_finder.addMatcher(
memberCallExpr(
cxxMemberCallExpr(
base_matcher,
// Excluded since the conversion may be unsafe.
unless(anyOf(is_unsafe_temporary_conversion, is_unsafe_return)),
......@@ -345,21 +346,20 @@ int main(int argc, const char* argv[]) {
// result in an incorrect replacement that changes the helper function
// itself. Instead, the right replacement is to rewrite the macro's
// arguments.
unless(hasAncestor(decl(anyOf(is_logging_helper,
is_gtest_helper,
unless(hasAncestor(decl(anyOf(is_logging_helper, is_gtest_helper,
is_gtest_assertion_result_ctor))))),
&get_callback);
// Find temporary scoped_refptr<T>'s being unsafely assigned to a T*.
VarRewriterCallback var_callback(&replacements);
auto initialized_with_temporary = ignoringImpCasts(exprWithCleanups(
has(memberCallExpr(base_matcher, is_unsafe_temporary_conversion))));
has(cxxMemberCallExpr(base_matcher, is_unsafe_temporary_conversion))));
match_finder.addMatcher(id("var",
varDecl(hasInitializer(initialized_with_temporary),
hasType(pointerType()))),
&var_callback);
match_finder.addMatcher(
constructorDecl(forEachConstructorInitializer(
cxxConstructorDecl(forEachConstructorInitializer(
allOf(withInitializer(initialized_with_temporary),
forField(id("var", fieldDecl(hasType(pointerType()))))))),
&var_callback);
......@@ -367,7 +367,7 @@ int main(int argc, const char* argv[]) {
// Rewrite functions that unsafely turn a scoped_refptr<T> into a T* when
// returning a value.
FunctionRewriterCallback fn_callback(&replacements);
match_finder.addMatcher(memberCallExpr(base_matcher, is_unsafe_return),
match_finder.addMatcher(cxxMemberCallExpr(base_matcher, is_unsafe_return),
&fn_callback);
// Rewrite logging / gtest expressions that result in an implicit conversion.
......@@ -407,7 +407,7 @@ int main(int argc, const char* argv[]) {
// However, the tool does need to handle the _TRUE counterparts, since the
// conversion occurs inside the constructor in those cases.
match_finder.addMatcher(
constructExpr(
cxxConstructExpr(
argumentCountIs(2),
hasArgument(0, id("expr", expr(hasType(is_scoped_refptr)))),
hasDeclaration(is_gtest_assertion_result_ctor)),
......
......@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
MCParser
Option
X86AsmParser
X86CodeGen
)
add_llvm_executable(rewrite_to_chrome_style
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment