summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/utils
diff options
context:
space:
mode:
authorMartin Bohme <mboehme@google.com>2018-08-03 22:20:04 +0000
committerMartin Bohme <mboehme@google.com>2018-08-03 22:20:04 +0000
commitb7d621b7b666691e6b2143fc401f0c09a5bc06d1 (patch)
tree86ad23c6b7924a581f7f11fa8806a0d628ec3a56 /clang-tools-extra/clang-tidy/utils
parent7499610e1b7ea0ed5375948d4321b173fd539dfa (diff)
downloadbcm5719-llvm-b7d621b7b666691e6b2143fc401f0c09a5bc06d1.tar.gz
bcm5719-llvm-b7d621b7b666691e6b2143fc401f0c09a5bc06d1.zip
[clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36516. Reviewers: ilya-biryukov, alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D49918 llvm-svn: 338932
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils')
-rw-r--r--clang-tools-extra/clang-tidy/utils/ExprSequence.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 02d4a0bdd1f..48c3de5450f 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -139,11 +139,26 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
if (S == ForRange->getLoopVarStmt())
return ForRange->getBody();
} else if (const auto *TheIfStmt = dyn_cast<IfStmt>(Parent)) {
- // If statement: If a variable is declared inside the condition, the
- // expression used to initialize the variable is sequenced before the
- // evaluation of the condition.
+ // If statement:
+ // - Sequence init statement before variable declaration.
+ // - Sequence variable declaration (along with the expression used to
+ // initialize it) before the evaluation of the condition.
+ if (S == TheIfStmt->getInit())
+ return TheIfStmt->getConditionVariableDeclStmt();
if (S == TheIfStmt->getConditionVariableDeclStmt())
return TheIfStmt->getCond();
+ } else if (const auto *TheSwitchStmt = dyn_cast<SwitchStmt>(Parent)) {
+ // Ditto for switch statements.
+ if (S == TheSwitchStmt->getInit())
+ return TheSwitchStmt->getConditionVariableDeclStmt();
+ if (S == TheSwitchStmt->getConditionVariableDeclStmt())
+ return TheSwitchStmt->getCond();
+ } else if (const auto *TheWhileStmt = dyn_cast<WhileStmt>(Parent)) {
+ // While statement: Sequence variable declaration (along with the
+ // expression used to initialize it) before the evaluation of the
+ // condition.
+ if (S == TheWhileStmt->getConditionVariableDeclStmt())
+ return TheWhileStmt->getCond();
}
}
OpenPOWER on IntegriCloud