-
Notifications
You must be signed in to change notification settings - Fork 70
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.
| | 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 | |
Copilot
AI
Dec 15, 2025
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.
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.
| | 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 | |
| | 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 | |
Copilot
AI
Dec 15, 2025
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.
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.
| | 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 | |
| | 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 | |
Copilot
AI
Dec 15, 2025
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.
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.
| | 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 | |
| - `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`: |
Copilot
AI
Dec 15, 2025
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.
Typo in filename: 'CathcBlockShadowingCert.ql' should be 'CatchBlockShadowingCert.ql' (missing 't' in 'Catch').
| - `M15-3-6`, `ERR54-CPP` - `CatchBlockShadowingMisra.ql`, `CathcBlockShadowingCert.ql`: | |
| - `M15-3-6`, `ERR54-CPP` - `CatchBlockShadowingMisra.ql`, `CatchBlockShadowingCert.ql`: |
| int l6 = 0; // NON-COMPLIANT | ||
| } | ||
|
|
||
| // Rule text states tht both operands of && are considered reachable, and that |
Copilot
AI
Dec 15, 2025
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.
Typo in comment: 'tht' should be 'that'.
| // Rule text states tht both operands of && are considered reachable, and that | |
| // Rule text states that both operands of && are considered reachable, and that |
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.