[PATCH] D86880: [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG1a7a2cd7474e: [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits (authored by eduucaldas). Changed prior to commit: https://reviews.llvm.org/D86880?vs=288961=290222#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86880/new/ https://reviews.llvm.org/D86880 Files: clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp clang/include/clang/AST/Expr.h clang/lib/AST/Expr.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp === --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -687,7 +687,7 @@ // base class decl, rather than the class of the instance which needs to be // checked for mutable fields. // TODO: We might as well look at the dynamic type of the object. -const Expr *Ex = getCXXThisExpr()->ignoreParenBaseCasts(); +const Expr *Ex = getCXXThisExpr()->IgnoreParenBaseCasts(); QualType T = Ex->getType(); if (T->isPointerType()) // Arrow or implicit-this syntax? T = T->getPointeeType(); Index: clang/lib/Sema/SemaExpr.cpp === --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -8372,7 +8372,7 @@ Expr **RHSExprs) { // Don't strip parenthesis: we should not warn if E is in parenthesis. E = E->IgnoreImpCasts(); - E = E->IgnoreConversionOperator(); + E = E->IgnoreConversionOperatorSingleStep(); E = E->IgnoreImpCasts(); if (auto *MTE = dyn_cast(E)) { E = MTE->getSubExpr(); Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -220,7 +220,7 @@ DevirtualizedMethod = MD->getCorrespondingMethodInClass(BestDynamicDecl); assert(DevirtualizedMethod); const CXXRecordDecl *DevirtualizedClass = DevirtualizedMethod->getParent(); -const Expr *Inner = Base->ignoreParenBaseCasts(); +const Expr *Inner = Base->IgnoreParenBaseCasts(); if (DevirtualizedMethod->getReturnType().getCanonicalType() != MD->getReturnType().getCanonicalType()) // If the return types are not the same, this might be a case where more Index: clang/lib/AST/Expr.cpp === --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -40,7 +40,7 @@ const Expr *Expr::getBestDynamicClassTypeExpr() const { const Expr *E = this; while (true) { -E = E->ignoreParenBaseCasts(); +E = E->IgnoreParenBaseCasts(); // Follow the RHS of a comma operator. if (auto *BO = dyn_cast(E)) { @@ -2780,29 +2780,6 @@ return QualType(); } -static Expr *IgnoreNoopCastsSingleStep(const ASTContext , Expr *E) { - if (auto *CE = dyn_cast(E)) { -// We ignore integer <-> casts that are of the same width, ptr<->ptr and -// ptr<->int casts of the same width. We also ignore all identity casts. -Expr *SubExpr = CE->getSubExpr(); -bool IsIdentityCast = -Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType()); -bool IsSameWidthCast = -(E->getType()->isPointerType() || E->getType()->isIntegralType(Ctx)) && -(SubExpr->getType()->isPointerType() || - SubExpr->getType()->isIntegralType(Ctx)) && -(Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SubExpr->getType())); - -if (IsIdentityCast || IsSameWidthCast) - return SubExpr; - } - - else if (auto *NTTP = dyn_cast(E)) -return NTTP->getReplacement(); - - return E; -} - Expr *Expr::IgnoreImpCasts() { return IgnoreExprNodes(this, IgnoreImplicitCastsSingleStep); } @@ -2832,7 +2809,7 @@ return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep); } -Expr *Expr::IgnoreConversionOperator() { +Expr *Expr::IgnoreConversionOperatorSingleStep() { if (auto *MCE = dyn_cast(this)) { if (MCE->getMethodDecl() && isa(MCE->getMethodDecl())) return MCE->getImplicitObjectArgument(); @@ -2845,58 +2822,72 @@ IgnoreLValueCastsSingleStep); } -Expr *Expr::ignoreParenBaseCasts() { +Expr *Expr::IgnoreParenBaseCasts() { return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreBaseCastsSingleStep); } Expr *Expr::IgnoreParenNoopCasts(const ASTContext ) { - return IgnoreExprNodes(this, IgnoreParensSingleStep, [](Expr *E) { -return IgnoreNoopCastsSingleStep(Ctx, E); - }); + auto IgnoreNoopCastsSingleStep = [](Expr *E) { +if (auto *CE =
[PATCH] D86880: [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits
eduucaldas created this revision. eduucaldas added a reviewer: gribozavr2. Herald added subscribers: cfe-commits, martong. Herald added a project: clang. eduucaldas requested review of this revision. This change groups - Rename: `ignoreParenBaseCasts` -> `IgnoreParenBaseCasts` for uniformity - Rename: `IgnoreConversionOperator` -> `IgnoreConversionOperatorSingleStep` for uniformity - Inline `IgnoreNoopCastsSingleStep` into a lambda inside `IgnoreNoopCasts` - Refactor `IgnoreUnlessSpelledInSource` to make adequate use of `IgnoreExprNodes` Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D86880 Files: clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp clang/include/clang/AST/Expr.h clang/lib/AST/Expr.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp === --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -687,7 +687,7 @@ // base class decl, rather than the class of the instance which needs to be // checked for mutable fields. // TODO: We might as well look at the dynamic type of the object. -const Expr *Ex = getCXXThisExpr()->ignoreParenBaseCasts(); +const Expr *Ex = getCXXThisExpr()->IgnoreParenBaseCasts(); QualType T = Ex->getType(); if (T->isPointerType()) // Arrow or implicit-this syntax? T = T->getPointeeType(); Index: clang/lib/Sema/SemaExpr.cpp === --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -8375,7 +8375,7 @@ Expr **RHSExprs) { // Don't strip parenthesis: we should not warn if E is in parenthesis. E = E->IgnoreImpCasts(); - E = E->IgnoreConversionOperator(); + E = E->IgnoreConversionOperatorSingleStep(); E = E->IgnoreImpCasts(); if (auto *MTE = dyn_cast(E)) { E = MTE->getSubExpr(); Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -220,7 +220,7 @@ DevirtualizedMethod = MD->getCorrespondingMethodInClass(BestDynamicDecl); assert(DevirtualizedMethod); const CXXRecordDecl *DevirtualizedClass = DevirtualizedMethod->getParent(); -const Expr *Inner = Base->ignoreParenBaseCasts(); +const Expr *Inner = Base->IgnoreParenBaseCasts(); if (DevirtualizedMethod->getReturnType().getCanonicalType() != MD->getReturnType().getCanonicalType()) // If the return types are not the same, this might be a case where more Index: clang/lib/AST/Expr.cpp === --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -40,7 +40,7 @@ const Expr *Expr::getBestDynamicClassTypeExpr() const { const Expr *E = this; while (true) { -E = E->ignoreParenBaseCasts(); +E = E->IgnoreParenBaseCasts(); // Follow the RHS of a comma operator. if (auto *BO = dyn_cast(E)) { @@ -2780,29 +2780,6 @@ return QualType(); } -static Expr *IgnoreNoopCastsSingleStep(const ASTContext , Expr *E) { - if (auto *CE = dyn_cast(E)) { -// We ignore integer <-> casts that are of the same width, ptr<->ptr and -// ptr<->int casts of the same width. We also ignore all identity casts. -Expr *SubExpr = CE->getSubExpr(); -bool IsIdentityCast = -Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType()); -bool IsSameWidthCast = -(E->getType()->isPointerType() || E->getType()->isIntegralType(Ctx)) && -(SubExpr->getType()->isPointerType() || - SubExpr->getType()->isIntegralType(Ctx)) && -(Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SubExpr->getType())); - -if (IsIdentityCast || IsSameWidthCast) - return SubExpr; - } - - else if (auto *NTTP = dyn_cast(E)) -return NTTP->getReplacement(); - - return E; -} - Expr *Expr::IgnoreImpCasts() { return IgnoreExprNodes(this, IgnoreImpCastsSingleStep); } @@ -2832,7 +2809,7 @@ return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep); } -Expr *Expr::IgnoreConversionOperator() { +Expr *Expr::IgnoreConversionOperatorSingleStep() { if (auto *MCE = dyn_cast(this)) { if (MCE->getMethodDecl() && isa(MCE->getMethodDecl())) return MCE->getImplicitObjectArgument(); @@ -2845,58 +2822,72 @@ IgnoreLValueCastsSingleStep); } -Expr *Expr::ignoreParenBaseCasts() { +Expr *Expr::IgnoreParenBaseCasts() { return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreBaseCastsSingleStep); } Expr *Expr::IgnoreParenNoopCasts(const ASTContext ) { - return IgnoreExprNodes(this, IgnoreParensSingleStep, [](Expr