Skip to content

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

Implement Rule 0-0-1

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • RULE-0-0-1
  • Queries have been modified for the following rules:
    • M0-1-1
    • RULE-2-1
    • M15-3-6
    • ERR54-CPP

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

Query development review checklist

For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:

Author

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Copilot AI review requested due to automatic review settings December 15, 2025 23:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements MISRA C++ 2023 Rule 0-0-1, which prohibits unreachable statements in functions. The implementation leverages custom reachability analysis that accounts for MISRA-specific semantics (e.g., both operands of && are reachable) and integrates with exception handling analysis.

Key changes:

  • New query UnreachableStatement.ql implements MISRA-specific reachability analysis for detecting unreachable code
  • Refactored catch block shadowing logic into shared Shadowing.qll library for reuse
  • Enhanced UnreachableCode.qll to properly handle compiler-generated Handler blocks in CFG analysis

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
rules.csv Updated rule metadata to reference DeadCode3 package
rule_packages/cpp/DeadCode3.json New package definition for RULE-0-0-1 query
cpp/misra/test/rules/RULE-0-0-1/test.cpp Comprehensive test cases covering various unreachability scenarios
cpp/misra/test/rules/RULE-0-0-1/UnreachableStatement.qlref Query reference for testing
cpp/misra/test/rules/RULE-0-0-1/UnreachableStatement.expected Expected test results with location issues
cpp/misra/src/rules/RULE-0-0-1/UnreachableStatement.ql Main query implementing MISRA reachability semantics
cpp/common/src/codingstandards/cpp/rules/catchblockshadowing/CatchBlockShadowing.qll Refactored to use shared Shadowing library
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Added DeadCode3 package integration
cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode3.qll Auto-generated exclusions file for DeadCode3 package
cpp/common/src/codingstandards/cpp/exceptions/Shadowing.qll New shared library for catch block shadowing detection
cpp/common/src/codingstandards/cpp/deadcode/UnreachableCode.qll Enhanced to handle Handler blocks correctly
cpp/common/src/codingstandards/cpp/ast/Catch.qll New utility functions for catch block analysis
change_notes/2025-12-15-update-catch-block-shadowing-dead-code.md Change note with spelling error

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

| test.cpp:131:3:131:12 | declaration | Unreachable statement in function '$@'. | test.cpp:109:6:109:7 | f8 | f8 |
| test.cpp:135:18:136:14 | { ... } | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |
| test.cpp:146:5:146:14 | declaration | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |
| test.cpp:158:3:134:7 | declaration | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location range for this expected result is incorrect. The first line number should be '158' (the line of the unreachable statement) but instead it says '158:3:134:7' where the end location incorrectly references line 134 and column 7, which appears to be the function name location instead of the statement's end location. It should be '158:3:158:12' to correctly span the declaration on line 158.

Suggested change
| test.cpp:158:3:134:7 | declaration | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |
| test.cpp:158:3:158:12 | declaration | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |

Copilot uses AI. Check for mistakes.
| test.cpp:158:3:134:7 | declaration | Unreachable statement in function '$@'. | test.cpp:134:6:134:7 | f9 | f9 |
| test.cpp:162:17:163:14 | { ... } | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:173:5:173:14 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:185:3:161:8 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location range for this expected result is incorrect. The first line number should be '185' (the line of the unreachable statement) but instead it says '185:3:161:8' where the end location incorrectly references line 161 and column 8, which appears to be the function name location instead of the statement's end location. It should be '185:3:185:12' to correctly span the declaration on line 185.

Suggested change
| test.cpp:185:3:161:8 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:185:3:185:12 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |

Copilot uses AI. Check for mistakes.
| test.cpp:162:17:163:14 | { ... } | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:173:5:173:14 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:185:3:161:8 | declaration | Unreachable statement in function '$@'. | test.cpp:161:6:161:8 | f10 | f10 |
| test.cpp:192:3:190:8 | declaration | Unreachable statement in function '$@'. | test.cpp:190:6:190:8 | f11 | f11 |
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location range for this expected result is incorrect. The first line number should be '192' (the line of the unreachable statement) but instead it says '192:3:190:8' where the end location incorrectly references line 190 and column 8, which appears to be the function name location instead of the statement's end location. It should be '192:3:192:12' to correctly span the declaration on line 192.

Suggested change
| test.cpp:192:3:190:8 | declaration | Unreachable statement in function '$@'. | test.cpp:190:6:190:8 | f11 | f11 |
| test.cpp:192:3:192:12 | declaration | Unreachable statement in function '$@'. | test.cpp:190:6:190:8 | f11 | f11 |

Copilot uses AI. Check for mistakes.
- `M0-1-1`, `RULE-2-1` - `UnreachableCode.ql`:
- Updated detection of compiler generated code to include "handler" blocks, part of EDG's IR.
- "handler" blocks generated for `catch(...)` blocks are not excluded for technical reasons related to how the CFG is constructed.
- `M15-3-6`, `ERR54-CPP` - `CatchBlockShadowingMisra.ql`, `CathcBlockShadowingCert.ql`:
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in filename: 'CathcBlockShadowingCert.ql' should be 'CatchBlockShadowingCert.ql' (missing 't' in 'Catch').

Suggested change
- `M15-3-6`, `ERR54-CPP` - `CatchBlockShadowingMisra.ql`, `CathcBlockShadowingCert.ql`:
- `M15-3-6`, `ERR54-CPP` - `CatchBlockShadowingMisra.ql`, `CatchBlockShadowingCert.ql`:

Copilot uses AI. Check for mistakes.
int l6 = 0; // NON-COMPLIANT
}

// Rule text states tht both operands of && are considered reachable, and that
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'tht' should be 'that'.

Suggested change
// Rule text states tht both operands of && are considered reachable, and that
// Rule text states that both operands of && are considered reachable, and that

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants