@@ -27,6 +27,12 @@ class NestedForConditions extends SC::StructuralComparisonConfiguration {
2727 }
2828}
2929
30+ private predicate hasChild ( Stmt outer , Element child ) {
31+ outer = child .getParent ( )
32+ or
33+ hasChild ( outer , child .getParent ( ) )
34+ }
35+
3036/** A nested `for` statement that shares the same iteration variable as an outer `for` statement. */
3137class NestedForLoopSameVariable extends ForStmt {
3238 ForStmt outer ;
@@ -35,7 +41,7 @@ class NestedForLoopSameVariable extends ForStmt {
3541 MutatorOperation outerUpdate ;
3642
3743 NestedForLoopSameVariable ( ) {
38- outer = this . getParent + ( ) and
44+ hasChild ( outer , this ) and
3945 innerUpdate = this .getAnUpdate ( ) and
4046 outerUpdate = outer .getAnUpdate ( ) and
4147 innerUpdate .getOperand ( ) = iteration .getAnAccess ( ) and
@@ -88,7 +94,7 @@ class NestedForLoopSameVariable extends ForStmt {
8894
8995 /** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
9096 private ControlFlow:: Node getAnUnguardedNode ( ) {
91- result . getElement ( ) . getParent + ( ) = getOuterForStmt ( ) . getBody ( ) and
97+ hasChild ( getOuterForStmt ( ) . getBody ( ) , result . getElement ( ) ) and
9298 (
9399 result =
94100 this .getCondition ( ) .( ControlFlowElement ) .getAControlFlowExitNode ( ) .getAFalseSuccessor ( )
0 commit comments