-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mutation analyzer][NFC] combine ConditionalOperator
BinaryConditionalOperator
#118602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/118602.diff 1 Files Affected:
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index be0e8aa5743dd9..9387d67b6828f1 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -55,23 +55,11 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) {
// This is matched by `IgnoreDerivedToBase(canResolveToExpr(InnerMatcher))`
// below.
const auto ConditionalOperatorM = [Target](const Expr *E) {
- if (const auto *OP = dyn_cast<ConditionalOperator>(E)) {
- if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
+ if (const auto *CO = dyn_cast<AbstractConditionalOperator>(E)) {
+ if (const auto *TE = CO->getTrueExpr()->IgnoreParens())
if (canExprResolveTo(TE, Target))
return true;
- if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
- if (canExprResolveTo(FE, Target))
- return true;
- }
- return false;
- };
-
- const auto ElvisOperator = [Target](const Expr *E) {
- if (const auto *OP = dyn_cast<BinaryConditionalOperator>(E)) {
- if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
- if (canExprResolveTo(TE, Target))
- return true;
- if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
+ if (const auto *FE = CO->getFalseExpr()->IgnoreParens())
if (canExprResolveTo(FE, Target))
return true;
}
@@ -81,8 +69,7 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) {
const Expr *SourceExprP = Source->IgnoreParens();
return IgnoreDerivedToBase(SourceExprP,
[&](const Expr *E) {
- return E == Target || ConditionalOperatorM(E) ||
- ElvisOperator(E);
+ return E == Target || ConditionalOperatorM(E);
}) ||
EvalCommaExpr(SourceExprP, [&](const Expr *E) {
return IgnoreDerivedToBase(
|
@llvm/pr-subscribers-clang-analysis Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/118602.diff 1 Files Affected:
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index be0e8aa5743dd9..9387d67b6828f1 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -55,23 +55,11 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) {
// This is matched by `IgnoreDerivedToBase(canResolveToExpr(InnerMatcher))`
// below.
const auto ConditionalOperatorM = [Target](const Expr *E) {
- if (const auto *OP = dyn_cast<ConditionalOperator>(E)) {
- if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
+ if (const auto *CO = dyn_cast<AbstractConditionalOperator>(E)) {
+ if (const auto *TE = CO->getTrueExpr()->IgnoreParens())
if (canExprResolveTo(TE, Target))
return true;
- if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
- if (canExprResolveTo(FE, Target))
- return true;
- }
- return false;
- };
-
- const auto ElvisOperator = [Target](const Expr *E) {
- if (const auto *OP = dyn_cast<BinaryConditionalOperator>(E)) {
- if (const auto *TE = OP->getTrueExpr()->IgnoreParens())
- if (canExprResolveTo(TE, Target))
- return true;
- if (const auto *FE = OP->getFalseExpr()->IgnoreParens())
+ if (const auto *FE = CO->getFalseExpr()->IgnoreParens())
if (canExprResolveTo(FE, Target))
return true;
}
@@ -81,8 +69,7 @@ static bool canExprResolveTo(const Expr *Source, const Expr *Target) {
const Expr *SourceExprP = Source->IgnoreParens();
return IgnoreDerivedToBase(SourceExprP,
[&](const Expr *E) {
- return E == Target || ConditionalOperatorM(E) ||
- ElvisOperator(E);
+ return E == Target || ConditionalOperatorM(E);
}) ||
EvalCommaExpr(SourceExprP, [&](const Expr *E) {
return IgnoreDerivedToBase(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(maybe combine the if
s: const auto* TE...; TE && ...
as a cleanup?)
d5fd3c5
to
5746174
Compare
No description provided.