@@ -70,6 +70,13 @@ class MemberAssignmentOperation extends FunctionCall {
70
70
*/
71
71
pragma [ noopt]
72
72
Variable getALoopCounter ( ForStmt fs ) {
73
+ // ------------------------------------------------------------------------------------------------
74
+ // NOTE: This is an updated version of ForStmt.getAnIterationVariable(), handling additional cases.
75
+ // The use of pragma[noopt] is retained from the original code, as we haven't determined
76
+ // whether it's still necessary across a broad range of databases. As a noopt predicate, it
77
+ // includes a degree of duplication as the join order is defined based on the order of the
78
+ // conditions.
79
+ // ------------------------------------------------------------------------------------------------
73
80
// check that it is assigned to, incremented or decremented in the update
74
81
exists ( Expr updateOpRoot , Expr updateOp |
75
82
updateOpRoot = fs .getUpdate ( ) and
@@ -106,6 +113,15 @@ Variable getALoopCounter(ForStmt fs) {
106
113
)
107
114
or
108
115
updateOp = result .getAnAssignedValue ( )
116
+ or
117
+ // updateOp is an access whose address is taken in a non-const way
118
+ exists ( FunctionCall fc , VariableAccess va |
119
+ fc = updateOp and
120
+ fc instanceof FunctionCall and
121
+ fc .getAnArgument ( ) = va and
122
+ va = result .getAnAccess ( ) and
123
+ va .isAddressOfAccessNonConst ( )
124
+ )
109
125
) and
110
126
result instanceof Variable and
111
127
// checked or used in the condition
@@ -260,7 +276,7 @@ predicate isLoopControlVarModifiedInLoopCondition(
260
276
loopControlVariableAccess = forLoop .getCondition ( ) .getAChild + ( ) and
261
277
(
262
278
loopControlVariableAccess .isModified ( ) or
263
- loopControlVariableAccess .isAddressOfAccess ( )
279
+ loopControlVariableAccess .isAddressOfAccessNonConst ( )
264
280
)
265
281
}
266
282
@@ -277,7 +293,7 @@ predicate isLoopControlVarModifiedInLoopExpr(
277
293
loopControlVariableAccess = forLoop .getUpdate ( ) .getAChild ( ) and
278
294
(
279
295
loopControlVariableAccess .isModified ( ) or
280
- loopControlVariableAccess .isAddressOfAccess ( )
296
+ loopControlVariableAccess .isAddressOfAccessNonConst ( )
281
297
)
282
298
}
283
299
0 commit comments