summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra
diff options
context:
space:
mode:
authorZinovy Nis <zinovy.nis@gmail.com>2018-05-22 17:24:28 +0000
committerZinovy Nis <zinovy.nis@gmail.com>2018-05-22 17:24:28 +0000
commit9bfe932c541cdbe8978f399e79ec95bb61e94f71 (patch)
tree5bce27df82899cc575af169fd9a60c6ccadf1493 /clang-tools-extra
parent65a91288fcbf128538bd1bd227de5f8bb29784b5 (diff)
downloadbcm5719-llvm-9bfe932c541cdbe8978f399e79ec95bb61e94f71.tar.gz
bcm5719-llvm-9bfe932c541cdbe8978f399e79ec95bb61e94f71.zip
[clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type
bool foo(A &S) { if (S != (A)S) return false; return true; } is fixed into (w/o this patch) ... return !S != (A)S; // negotiation affects first operand only } instead of (with this patch) ... return S == (A)S; // note == instead of != } Differential Revision: https://reviews.llvm.org/D47122 llvm-svn: 333003
Diffstat (limited to 'clang-tools-extra')
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp3
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-simplify-bool-expr.cpp10
2 files changed, 13 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 559b085bef9..ba8e5b42cca 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -195,6 +195,9 @@ std::string compareExpressionToZero(const MatchFinder::MatchResult &Result,
std::string replacementExpression(const MatchFinder::MatchResult &Result,
bool Negated, const Expr *E) {
E = E->ignoreParenBaseCasts();
+ if (const auto *EC = dyn_cast<ExprWithCleanups>(E))
+ E = EC->getSubExpr();
+
const bool NeedsStaticCast = needsStaticCast(E);
if (Negated) {
if (const auto *UnOp = dyn_cast<UnaryOperator>(E)) {
diff --git a/clang-tools-extra/test/clang-tidy/readability-simplify-bool-expr.cpp b/clang-tools-extra/test/clang-tidy/readability-simplify-bool-expr.cpp
index edaf68e0c88..cd93c5d4be7 100644
--- a/clang-tools-extra/test/clang-tidy/readability-simplify-bool-expr.cpp
+++ b/clang-tools-extra/test/clang-tidy/readability-simplify-bool-expr.cpp
@@ -938,3 +938,13 @@ bool integer_member_implicit_cast(A *p) {
}
// CHECK-MESSAGES: :[[@LINE-5]]:12: warning: {{.*}} in conditional return
// CHECK-FIXES: return p->m != 0;{{$}}
+
+bool operator!=(const A&, const A&) { return false; }
+bool expr_with_cleanups(A &S) {
+ if (S != (A)S)
+ return false;
+
+ return true;
+}
+// CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
+// CHECK-FIXES: S == (A)S;{{$}}
OpenPOWER on IntegriCloud