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 | d0e7354d701bd62517d2ee6cc4dc965b22f08865 (patch) | |
tree | e3484a2c80ca86f83652769cd29811ebbe11f746 /clang-tidy/utils | |
parent | 301ffe30956968a9ce679fe0f2774967b4b591ea (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@343768 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/utils')
-rw-r--r-- | clang-tidy/utils/ExprSequence.cpp | 10 | ||||
-rw-r--r-- | clang-tidy/utils/ExprSequence.h | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/clang-tidy/utils/ExprSequence.cpp b/clang-tidy/utils/ExprSequence.cpp index 48c3de54..c3602ff8 100644 --- a/clang-tidy/utils/ExprSequence.cpp +++ b/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-tidy/utils/ExprSequence.h b/clang-tidy/utils/ExprSequence.h index 2b355d9a..0868a899 100644 --- a/clang-tidy/utils/ExprSequence.h +++ b/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; }; |