if (!TheCFG)
return false;
- Sequence.reset(new ExprSequence(TheCFG.get(), Context));
- BlockMap.reset(new StmtToBlockMap(TheCFG.get(), Context));
+ Sequence =
+ llvm::make_unique<ExprSequence>(TheCFG.get(), FunctionBody, Context);
+ BlockMap = llvm::make_unique<StmtToBlockMap>(TheCFG.get(), Context);
Visited.clear();
const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall);
}
}
-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;
}
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)
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;
const Stmt *resolveSyntheticStmt(const Stmt *S) const;
ASTContext *Context;
+ const Stmt *Root;
llvm::DenseMap<const Stmt *, const Stmt *> SyntheticStmtSourceMap;
};
}
}
+// Some statements in templates (e.g. null, break and continue statements) may
+// be shared between the uninstantiated and instantiated versions of the
+// template and therefore have multiple parents. Make sure the sequencing code
+// handles this correctly.
+template <class> void nullStatementSequencesInTemplate() {
+ int c = 0;
+ (void)c;
+ ;
+ std::move(c);
+}
+template void nullStatementSequencesInTemplate<int>();
+
namespace PR33020 {
class D {
~D();