Skip to content

Commit

Permalink
Fix clang-tidy patterns to adapt to newly added ExprWithCleanups nodes.
Browse files Browse the repository at this point in the history
Summary: This is a fix for the new ExprWithCleanups introduced by clang's temporary variable lifetime marks change.

Reviewers: bkramer, sbenza, angelgarcia, alexth

Subscribers: rsmith, cfe-commits

Differential Revision: http://reviews.llvm.org/D21243

llvm-svn: 273310
  • Loading branch information
timshen91 committed Jun 21, 2016
1 parent 8b65f10 commit 325c727
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
Expand Up @@ -33,7 +33,8 @@ void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {
if (VD->hasInit()) {
// Peel away implicit constructors and casts so we can see the actual type
// of the initializer.
const Expr *C = VD->getInit();
const Expr *C = VD->getInit()->IgnoreImplicit();

while (isa<CXXConstructExpr>(C))
C = cast<CXXConstructExpr>(C)->getArg(0)->IgnoreParenImpCasts();

Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-tidy/misc/DanglingHandleCheck.cpp
Expand Up @@ -8,11 +8,13 @@
//===----------------------------------------------------------------------===//

#include "DanglingHandleCheck.h"
#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

using namespace clang::ast_matchers;
using namespace clang::tidy::matchers;

namespace clang {
namespace tidy {
Expand Down Expand Up @@ -135,7 +137,7 @@ void DanglingHandleCheck::registerMatchersForReturn(MatchFinder *Finder) {
// 1. Value to Handle conversion.
// 2. Handle copy construction.
// We have to match both.
has(ignoringParenImpCasts(handleFrom(
has(ignoringImplicit(handleFrom(
IsAHandle,
handleFrom(IsAHandle, declRefExpr(to(varDecl(
// Is function scope ...
Expand Down
5 changes: 3 additions & 2 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

#include "LoopConvertCheck.h"
#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"

Expand Down Expand Up @@ -141,10 +142,10 @@ StatementMatcher makeIteratorLoopMatcher() {
StatementMatcher IteratorComparisonMatcher = expr(
ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName)))));

StatementMatcher OverloadedNEQMatcher =
auto OverloadedNEQMatcher = matchers::ignoringImplicit(
cxxOperatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2),
hasArgument(0, IteratorComparisonMatcher),
hasArgument(1, IteratorBoundMatcher));
hasArgument(1, IteratorBoundMatcher)));

// This matcher tests that a declaration is a CXXRecordDecl that has an
// overloaded operator*(). If the operator*() returns by value instead of by
Expand Down
Expand Up @@ -156,7 +156,7 @@ bool DeclFinderASTVisitor::VisitTypeLoc(TypeLoc TL) {
const Expr *digThroughConstructors(const Expr *E) {
if (!E)
return nullptr;
E = E->IgnoreParenImpCasts();
E = E->IgnoreImplicit();
if (const auto *ConstructExpr = dyn_cast<CXXConstructExpr>(E)) {
// The initial constructor must take exactly one parameter, but base class
// and deferred constructors can take more.
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
Expand Up @@ -42,6 +42,8 @@ AST_MATCHER(VarDecl, hasWrittenNonListInitializer) {
if (!Init)
return false;

Init = Init->IgnoreImplicit();

// The following test is based on DeclPrinter::VisitVarDecl() to find if an
// initializer is implicit or not.
if (const auto *Construct = dyn_cast<CXXConstructExpr>(Init)) {
Expand Down
Expand Up @@ -39,21 +39,21 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
stringLiteral(hasSize(0)))));

const auto EmptyStringCtorExprWithTemporaries =
expr(ignoringImplicit(
cxxConstructExpr(StringConstructorExpr,
hasArgument(0, ignoringImplicit(EmptyStringCtorExpr)))));
cxxConstructExpr(StringConstructorExpr,
hasArgument(0, ignoringImplicit(EmptyStringCtorExpr)));

// Match a variable declaration with an empty string literal as initializer.
// Examples:
// string foo = "";
// string bar("");
Finder->addMatcher(
namedDecl(varDecl(hasType(cxxRecordDecl(hasName("basic_string"))),
hasInitializer(
expr(anyOf(EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries))
.bind("expr"))),
unless(parmVarDecl()))
namedDecl(
varDecl(hasType(cxxRecordDecl(hasName("basic_string"))),
hasInitializer(expr(ignoringImplicit(anyOf(
EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries)))
.bind("expr"))),
unless(parmVarDecl()))
.bind("decl"),
this);
}
Expand Down

0 comments on commit 325c727

Please sign in to comment.