clang-tools 20.0.0git
Public Member Functions | List of all members
clang::tidy::utils::ExprSequence Class Reference

Provides information about the evaluation order of (sub-)expressions within a CFGBlock. More...

#include <ExprSequence.h>

Public Member Functions

 ExprSequence (const CFG *TheCFG, const Stmt *Root, ASTContext *TheContext)
 Initializes this ExprSequence with sequence information for the given CFG.
 
bool inSequence (const Stmt *Before, const Stmt *After) const
 Returns whether Before is sequenced before After.
 
bool potentiallyAfter (const Stmt *After, const Stmt *Before) const
 Returns whether After can potentially be evaluated after Before.
 

Detailed Description

Provides information about the evaluation order of (sub-)expressions within a CFGBlock.

While a CFGBlock does contain individual CFGElements for some sub-expressions, the order in which those CFGElements appear reflects only one possible order in which the sub-expressions may be evaluated. However, we want to warn if any of the potential evaluation orders can lead to a use-after-move, not just the one contained in the CFGBlock.

This class implements only a simplified version of the C++ sequencing rules. The main limitation is that we do not distinguish between value computation and side effect – see the "Implementation" section for more details.

Note: SequenceChecker from SemaChecking.cpp does a similar job (and much more thoroughly), but using it would require

Implementation

ExprSequence uses two types of sequencing edges between nodes in the AST:

Definition at line 66 of file ExprSequence.h.

Constructor & Destructor Documentation

◆ ExprSequence()

clang::tidy::utils::ExprSequence::ExprSequence ( const CFG *  TheCFG,
const Stmt *  Root,
ASTContext *  TheContext 
)

Initializes this ExprSequence with sequence information for the given CFG.

Root is the root statement the CFG was built from.

Definition at line 84 of file ExprSequence.cpp.

Member Function Documentation

◆ inSequence()

bool clang::tidy::utils::ExprSequence::inSequence ( const Stmt *  Before,
const Stmt *  After 
) const

Returns whether Before is sequenced before After.

Definition at line 92 of file ExprSequence.cpp.

References clang::tidy::utils::getParentStmts(), inSequence(), and Parent.

Referenced by inSequence(), and potentiallyAfter().

◆ potentiallyAfter()

bool clang::tidy::utils::ExprSequence::potentiallyAfter ( const Stmt *  After,
const Stmt *  Before 
) const

Returns whether After can potentially be evaluated after Before.

This is exactly equivalent to !inSequence(After, Before) but makes some conditions read more naturally.

Definition at line 164 of file ExprSequence.cpp.

References inSequence().


The documentation for this class was generated from the following files: