diff options
author | Martin Bohme <mboehme@google.com> | 2018-10-04 11:36:39 +0000 |
---|---|---|
committer | Martin Bohme <mboehme@google.com> | 2018-10-04 11:36:39 +0000 |
commit | 764ad2f732c46199af6a84b08d288cd72fc49dbf (patch) | |
tree | 4d5cb242cfcd6a87c96512f481077eb924315905 /clang-tools-extra/clang-tidy/utils | |
parent | e94c8694344369d16814b19e4828a6b42e4ea2c0 (diff) | |
download | bcm5719-llvm-764ad2f732c46199af6a84b08d288cd72fc49dbf.tar.gz bcm5719-llvm-764ad2f732c46199af6a84b08d288cd72fc49dbf.zip |
[clang-tidy] Sequence statements with multiple parents correctly (PR39149)
Summary:
Before this fix, the bugprone-use-after-move check could incorrectly
conclude that a use and move in a function template were not sequenced.
For details, see
https://bugs.llvm.org/show_bug.cgi?id=39149
Reviewers: alexfh, hokein, aaron.ballman, JonasToth
Reviewed By: aaron.ballman
Subscribers: xazax.hun, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D52782
llvm-svn: 343768
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils')
-rw-r--r-- | clang-tools-extra/clang-tidy/utils/ExprSequence.cpp | 10 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/utils/ExprSequence.h | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp index 48c3de5450f..c3602ff8ad7 100644 --- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp @@ -63,8 +63,9 @@ bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor, } } -ExprSequence::ExprSequence(const CFG *TheCFG, ASTContext *TheContext) - : Context(TheContext) { +ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root, + ASTContext *TheContext) + : Context(TheContext), Root(Root) { for (const auto &SyntheticStmt : TheCFG->synthetic_stmts()) { SyntheticStmtSourceMap[SyntheticStmt.first] = SyntheticStmt.second; } @@ -99,6 +100,11 @@ bool ExprSequence::potentiallyAfter(const Stmt *After, const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const { for (const Stmt *Parent : getParentStmts(S, Context)) { + // If a statement has multiple parents, make sure we're using the parent + // that lies within the sub-tree under Root. + if (!isDescendantOrEqual(Parent, Root, Context)) + continue; + if (const auto *BO = dyn_cast<BinaryOperator>(Parent)) { // Comma operator: Right-hand side is sequenced after the left-hand side. if (BO->getLHS() == S && BO->getOpcode() == BO_Comma) diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.h b/clang-tools-extra/clang-tidy/utils/ExprSequence.h index 2b355d9a94f..0868a899779 100644 --- a/clang-tools-extra/clang-tidy/utils/ExprSequence.h +++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.h @@ -69,8 +69,8 @@ namespace utils { class ExprSequence { public: /// Initializes this `ExprSequence` with sequence information for the given - /// `CFG`. - ExprSequence(const CFG *TheCFG, ASTContext *TheContext); + /// `CFG`. `Root` is the root statement the CFG was built from. + ExprSequence(const CFG *TheCFG, const Stmt *Root, ASTContext *TheContext); /// Returns whether \p Before is sequenced before \p After. bool inSequence(const Stmt *Before, const Stmt *After) const; @@ -94,6 +94,7 @@ private: const Stmt *resolveSyntheticStmt(const Stmt *S) const; ASTContext *Context; + const Stmt *Root; llvm::DenseMap<const Stmt *, const Stmt *> SyntheticStmtSourceMap; }; |