Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
c8f559c
Generate query files for "Statements" package
jeongsoolee09 Jul 29, 2025
ffcb432
Add agent-generated first draft
jeongsoolee09 Jul 30, 2025
221b9b2
Add some test cases
jeongsoolee09 Jul 30, 2025
fabb7e5
Finish first draft
jeongsoolee09 Jul 31, 2025
6909528
Add test case for Rule 9.5.2
jeongsoolee09 Aug 1, 2025
0b5250f
Minor
jeongsoolee09 Aug 1, 2025
b239862
Update test case for Rule 9.5.2
jeongsoolee09 Aug 1, 2025
a013388
Add first draft of `ForRangeInitializerAtMostOneFunctionCall`
jeongsoolee09 Aug 1, 2025
1c623f4
Add test cases
jeongsoolee09 Aug 8, 2025
b792897
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
jeongsoolee09 Aug 8, 2025
0d38cd7
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
jeongsoolee09 Aug 8, 2025
c2cbed3
Update unit test
jeongsoolee09 Aug 18, 2025
b7ae38e
Add more cases and more vocabularies to reason about them
jeongsoolee09 Aug 27, 2025
86aaa0e
Fix labeling of two cases
jeongsoolee09 Sep 8, 2025
49bdc07
Add cases of addresses taken as part of non-const declaration or expr…
jeongsoolee09 Sep 8, 2025
01e3276
Finish first draft
jeongsoolee09 Sep 9, 2025
9cab1f5
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
jeongsoolee09 Sep 9, 2025
2f6fc3d
Finish first draft
jeongsoolee09 Sep 10, 2025
999e870
Tidy up, refine a bit more, add a series of test cases
jeongsoolee09 Sep 17, 2025
562c7be
Add two more cases
jeongsoolee09 Sep 17, 2025
6855e6a
Add QLDocs to two helper predicates
jeongsoolee09 Sep 17, 2025
5e24d1b
Introduce `from` variables and fix logical operator association
jeongsoolee09 Sep 22, 2025
18daff7
Introduce newtype
jeongsoolee09 Sep 22, 2025
55b8476
Split cases `5-1` and `5-2`
jeongsoolee09 Sep 22, 2025
662f51f
Debug 5-1-2 and 5-2-2 not being reported
jeongsoolee09 Sep 22, 2025
a653b66
Add LegacyForLoopUpdateExpression and test cases
jeongsoolee09 Sep 23, 2025
c8c0770
Separate out helper classes into libraries
jeongsoolee09 Sep 24, 2025
2227255
Finish draft of `LegacyForStatementsShouldBeSimple`
jeongsoolee09 Sep 24, 2025
38b5fbc
Decouple ForStmt from `Increment.qll` and rewrite `getLoopStepOfForStmt`
jeongsoolee09 Sep 24, 2025
23aa711
Update expected result of `RULE-9-5-1`
jeongsoolee09 Sep 29, 2025
f0b53e2
Update expected results of `RULE-9-5-2`
jeongsoolee09 Sep 29, 2025
7d5f08b
Count in typedefs and cv-qualifiers
jeongsoolee09 Oct 7, 2025
e135fe6
Fix cross-join issue in `TLoopCounterUpdatedNotByCrementOrAddSubAssig…
jeongsoolee09 Oct 7, 2025
b13ffd2
Slightly change wording in the message
jeongsoolee09 Oct 7, 2025
82f9adc
Make the loop counter detection more relaxed
jeongsoolee09 Oct 7, 2025
2116400
Refine `LegacyForLoopCondition`
jeongsoolee09 Oct 8, 2025
1f8083a
Change phrasing of message from `TNoRelationalOperatorInLoopCondition`
jeongsoolee09 Oct 8, 2025
1355eff
Use `upperbound/0` and `getFullyConverted/0` to more precisely infer …
jeongsoolee09 Oct 8, 2025
3ad5ef2
Apply suggestion from @Copilot
jeongsoolee09 Oct 9, 2025
fb20065
Apply suggestion from @Copilot
jeongsoolee09 Oct 9, 2025
bce38a0
Reformat test cases of 9-4-2 and 9-5-2
jeongsoolee09 Oct 9, 2025
32c36fe
Merge branch 'jeongsoolee09/MISRA-C++-2023-Statements' of github.com:…
jeongsoolee09 Oct 9, 2025
c0a8253
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
jeongsoolee09 Oct 9, 2025
59a4096
Update expected results coming from change in message
jeongsoolee09 Oct 9, 2025
d37bc70
Use different range predicate and update tests
jeongsoolee09 Oct 9, 2025
25e29e4
Refine `TLoopCounterMutatedInLoopBody`
jeongsoolee09 Oct 10, 2025
01216fa
Add more candidate exprs and remove duplicate reportings on compound …
jeongsoolee09 Oct 13, 2025
0f998ea
Add more test cases
jeongsoolee09 Oct 13, 2025
87a5158
Fix loop counter -> loop bound
jeongsoolee09 Oct 13, 2025
2aed0f1
Add const-but-mutable pointer examples
jeongsoolee09 Oct 13, 2025
33222ae
Debug loopVariableAssignedToNonConstPointOrReferenceType
jeongsoolee09 Oct 14, 2025
3dca053
Update expected results of 9-5-1
jeongsoolee09 Oct 14, 2025
15be010
Enforce loop counter to be variable access and add tests
jeongsoolee09 Nov 5, 2025
6ffd229
Expose mutating / assignment rhs expressions
jeongsoolee09 Nov 5, 2025
2163c54
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Statements
jeongsoolee09 Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more candidate exprs and remove duplicate reportings on compound …
…mutating exprs
  • Loading branch information
jeongsoolee09 committed Oct 13, 2025
commit 01216fa1cdd0b4e8a01bedd09b8ab52e53453c61
80 changes: 53 additions & 27 deletions cpp/misra/src/rules/RULE-9-5-1/LegacyForStatementsShouldBeSimple.ql
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,57 @@ private newtype TAlertType =
)
} or
/* 5-1-1. The loop bound is a variable that is mutated in the for loop. */
TLoopBoundIsMutatedVariableAccess(ForStmt forLoop, Expr loopBound, Expr mutatingExpr) {
loopBound = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
(
/* The mutating expression may be in the loop body. */
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
or
/* The mutating expression may be in the loop updating expression. */
mutatingExpr = forLoop.getUpdate().getAChild*()
) and
variableModifiedInExpression(mutatingExpr, loopBound.(VariableAccess).getTarget().getAnAccess())
TLoopBoundIsMutatedVariableAccess(
ForStmt forLoop, VariableAccess variableAccess, VariableAccess mutatedVariableAccess
) {
exists(Expr loopBoundExpr, Expr mutatingExpr |
loopBoundExpr = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
(
/* 1. The mutating expression may be in the loop body. */
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
or
/* 2. The mutating expression may be in the loop updating expression. */
mutatingExpr = forLoop.getUpdate().getAChild*()
or
/* 3. The mutating expression may be in the loop condition */
mutatingExpr = forLoop.getCondition().getAChild*()
or
/* 4. The mutating expression may be in the loop initializer */
mutatingExpr = forLoop.getInitialization().getAChild*()
) and
variableAccess = loopBoundExpr.getAChild*() and
mutatedVariableAccess = variableAccess.getTarget().getAnAccess() and
variableModifiedInExpression(mutatingExpr, mutatedVariableAccess)
)
} or
/* 5-1-2. The loop bound is not a variable access nor a constant expression. */
TLoopBoundIsNonConstExpr(ForStmt forLoop, Expr loopBound) {
loopBound = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
(not loopBound instanceof VariableAccess and not loopBound.isConstant())
} or
/* 5-2-1. The loop step is a variable that is mutated in the for loop. */
TLoopStepIsMutatedVariableAccess(ForStmt forLoop, Expr loopStep, Expr mutatingExpr) {
loopStep = getLoopStepOfForStmt(forLoop) and
(
/* The mutating expression may be in the loop body. */
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
or
/* The mutating expression may be in the loop updating expression. */
mutatingExpr = forLoop.getUpdate().getAChild*()
) and
variableModifiedInExpression(mutatingExpr, loopStep.(VariableAccess).getTarget().getAnAccess())
TLoopStepIsMutatedVariableAccess(
ForStmt forLoop, VariableAccess variableAccess, VariableAccess mutatedVariableAccess
) {
exists(Expr loopStepExpr, Expr mutatingExpr |
loopStepExpr = getLoopStepOfForStmt(forLoop) and
(
/* 1. The mutating expression may be in the loop body. */
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
or
/* 2. The mutating expression may be in the loop updating expression. */
mutatingExpr = forLoop.getUpdate().getAChild*()
or
/* 3. The mutating expression may be in the loop condition */
mutatingExpr = forLoop.getCondition().getAChild*()
or
/* 4. The mutating expression may be in the loop initializer */
mutatingExpr = forLoop.getInitialization().getAChild*()
) and
variableAccess = loopStepExpr.getAChild*() and
mutatedVariableAccess = variableAccess.getTarget().getAnAccess() and
variableModifiedInExpression(mutatingExpr, mutatedVariableAccess)
)
} or
/* 5-2-2. The loop step is not a variable access nor a constant expression. */
TLoopStepIsNonConstExpr(ForStmt forLoop, Expr loopStep) {
Expand All @@ -244,13 +268,15 @@ private newtype TAlertType =
* 6-2. The loop bound is taken as a mutable reference or its address to a mutable pointer.
*/

TLoopBoundIsTakenNonConstAddress(ForStmt forLoop, Expr loopVariableAccessInCondition) {
loopVariableAccessInCondition = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
(
loopVariableAssignedToNonConstPointerOrReferenceType(forLoop, loopVariableAccessInCondition)
or
loopVariablePassedAsArgumentToNonConstReferenceParameter(forLoop,
loopVariableAccessInCondition)
TLoopBoundIsTakenNonConstAddress(ForStmt forLoop, Expr loopBoundExpr) {
loopBoundExpr = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
exists(VariableAccess variableAccess |
variableAccess = loopBoundExpr.getAChild*() and
(
loopVariableAssignedToNonConstPointerOrReferenceType(forLoop, variableAccess)
or
loopVariablePassedAsArgumentToNonConstReferenceParameter(forLoop, variableAccess)
)
)
} or
/*
Expand Down
Loading