@@ -236,41 +236,6 @@ static std::string replacementExpression(const ASTContext &Context,
236
236
return asBool (getText (Context, *E), NeedsStaticCast);
237
237
}
238
238
239
- static const Expr *stmtReturnsBool (const ReturnStmt *Ret, bool Negated) {
240
- if (const auto *Bool = dyn_cast<CXXBoolLiteralExpr>(Ret->getRetValue ())) {
241
- if (Bool->getValue () == !Negated)
242
- return Bool;
243
- }
244
- if (const auto *Unary = dyn_cast<UnaryOperator>(Ret->getRetValue ())) {
245
- if (Unary->getOpcode () == UO_LNot) {
246
- if (const auto *Bool =
247
- dyn_cast<CXXBoolLiteralExpr>(Unary->getSubExpr ())) {
248
- if (Bool->getValue () == Negated)
249
- return Bool;
250
- }
251
- }
252
- }
253
-
254
- return nullptr ;
255
- }
256
-
257
- static const Expr *stmtReturnsBool (const IfStmt *IfRet, bool Negated) {
258
- if (IfRet->getElse () != nullptr )
259
- return nullptr ;
260
-
261
- if (const auto *Ret = dyn_cast<ReturnStmt>(IfRet->getThen ()))
262
- return stmtReturnsBool (Ret, Negated);
263
-
264
- if (const auto *Compound = dyn_cast<CompoundStmt>(IfRet->getThen ())) {
265
- if (Compound->size () == 1 ) {
266
- if (const auto *CompoundRet = dyn_cast<ReturnStmt>(Compound->body_back ()))
267
- return stmtReturnsBool (CompoundRet, Negated);
268
- }
269
- }
270
-
271
- return nullptr ;
272
- }
273
-
274
239
static bool containsDiscardedTokens (const ASTContext &Context,
275
240
CharSourceRange CharRange) {
276
241
std::string ReplacementText =
@@ -502,8 +467,8 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
502
467
if (Check->ChainedConditionalReturn ||
503
468
(!PrevIf && If->getElse () == nullptr )) {
504
469
Check->replaceCompoundReturnWithCondition (
505
- Context, cast<ReturnStmt>(*Second), TrailingReturnBool.Bool ,
506
- If );
470
+ Context, cast<ReturnStmt>(*Second), TrailingReturnBool.Bool , If,
471
+ ThenReturnBool. Item );
507
472
}
508
473
}
509
474
} else if (isa<LabelStmt, CaseStmt, DefaultStmt>(*First)) {
@@ -523,7 +488,7 @@ class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
523
488
ThenReturnBool.Bool != TrailingReturnBool.Bool ) {
524
489
Check->replaceCompoundReturnWithCondition (
525
490
Context, cast<ReturnStmt>(*Second), TrailingReturnBool.Bool ,
526
- SubIf);
491
+ SubIf, ThenReturnBool. Item );
527
492
}
528
493
}
529
494
}
@@ -689,11 +654,11 @@ void SimplifyBooleanExprCheck::replaceWithReturnCondition(
689
654
690
655
void SimplifyBooleanExprCheck::replaceCompoundReturnWithCondition (
691
656
const ASTContext &Context, const ReturnStmt *Ret, bool Negated,
692
- const IfStmt *If) {
693
- const auto *Lit = stmtReturnsBool (If, Negated);
657
+ const IfStmt *If, const Expr *ThenReturn) {
694
658
const std::string Replacement =
695
659
" return " + replacementExpression (Context, Negated, If->getCond ());
696
- issueDiag (Context, Lit->getBeginLoc (), SimplifyConditionalReturnDiagnostic,
660
+ issueDiag (Context, ThenReturn->getBeginLoc (),
661
+ SimplifyConditionalReturnDiagnostic,
697
662
SourceRange (If->getBeginLoc (), Ret->getEndLoc ()), Replacement);
698
663
}
699
664
0 commit comments