File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
semmle/code/cpp/controlflow/internal Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 1111
1212import cpp
1313
14- from Initializer init , Variable v , VariableAccess va
15- where init .getDeclaration ( ) = v
16- and va .getTarget ( ) = v
17- and va .getParent * ( ) = init
14+ class VariableAccessInInitializer extends VariableAccess {
15+ Variable var ;
16+ Initializer init ;
17+ VariableAccessInInitializer ( ) {
18+ init .getDeclaration ( ) = var and
19+ init .getExpr ( ) .getAChild * ( ) = this
20+ }
21+
22+ predicate initializesItself ( Variable v , Initializer i ) {
23+ v = var and i = init and var = this .getTarget ( )
24+ }
25+ }
26+
27+ from Initializer init , Variable v , VariableAccessInInitializer va
28+ where va .initializesItself ( v , init )
1829 and (
1930 va .hasLValueToRValueConversion ( ) or
2031 exists ( Assignment assn | assn .getLValue ( ) = va ) or
Original file line number Diff line number Diff line change @@ -31,8 +31,11 @@ private cached module Cached {
3131 // or the node's predecessor has more than one successor,
3232 // then the node is the start of a new primitive basic block.
3333 or
34- strictcount ( Node pred , Node other
35- | successors_extended ( pred , node ) and successors_extended ( pred , other ) ) > 1
34+ strictcount ( Node pred | successors_extended ( pred , node ) ) > 1
35+ or
36+ exists ( ControlFlowNode pred | successors_extended ( pred , node ) |
37+ strictcount ( ControlFlowNode other | successors_extended ( pred , other ) ) > 1
38+ )
3639
3740 // If the node has zero predecessors then it is the start of
3841 // a BB. However, the C++ AST contains many nodes with zero
@@ -63,8 +66,14 @@ private cached module Cached {
6366 /** Holds if `node` is the `pos`th control-flow node in primitive basic block `bb`. */
6467 cached
6568 predicate primitive_basic_block_member ( Node node , PrimitiveBasicBlock bb , int pos ) {
66- pos = getMemberIndex ( node ) and
67- member_step * ( bb , node )
69+ primitive_basic_block_entry_node ( bb ) and
70+ (
71+ pos = 0 and
72+ node = bb
73+ or
74+ pos = getMemberIndex ( node ) and
75+ member_step + ( bb , node )
76+ )
6877 }
6978
7079 /** Gets the number of control-flow nodes in the primitive basic block `bb`. */
You can’t perform that action at this time.
0 commit comments