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