-
Notifications
You must be signed in to change notification settings - Fork 72
Implement Rule 0-0-1, unreachable statements from DeadCode package #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement Rule 0-0-1, unreachable statements from DeadCode package #1001
Conversation
There was a problem hiding this 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.qlimplements MISRA-specific reachability analysis for detecting unreachable code - Refactored catch block shadowing logic into shared
Shadowing.qlllibrary for reuse - Enhanced
UnreachableCode.qllto 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.
Description
Implement Rule 0-0-1
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-0-0-1M0-1-1RULE-2-1M15-3-6ERR54-CPPRelease change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
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.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
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
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.
Reviewer
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.