-
Notifications
You must be signed in to change notification settings - Fork 74
Implement DeadCode6, RULE-0-1-2, shared with A0-1-2. #1034
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9d8b1e
Implement DeadCode6, RULE-0-1-2, shared with A0-1-2.
MichaelRFairhurst 5239d5f
Fix formatting
MichaelRFairhurst c38153a
reword change note
MichaelRFairhurst 1ca6789
Update deviations tests, which copy A0-1-2
MichaelRFairhurst 0560f65
Change it to keep query id
MichaelRFairhurst 5475ea9
Undo change to A0-1-2 query id
MichaelRFairhurst 066200f
Reintroduce comment in deviations tests explaining deliberately copie…
MichaelRFairhurst 3be7984
Merge branch 'main' into michaelrfairhurst/package-deadcode-6
mbaluda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - `A0-1-2` - `UnusedReturnValue.ql`: | ||
| - Refactors the rule implementation into a shared library for usage in MISRA C++ ruleset. No externally visible changes expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql |
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode6.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
|
|
||
| newtype DeadCode6Query = TUnusedReturnValueMisraCppQuery() | ||
|
|
||
| predicate isDeadCode6QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `unusedReturnValueMisraCpp` query | ||
| DeadCode6Package::unusedReturnValueMisraCppQuery() and | ||
| queryId = | ||
| // `@id` for the `unusedReturnValueMisraCpp` query | ||
| "cpp/misra/unused-return-value-misra-cpp" and | ||
| ruleId = "RULE-0-1-2" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module DeadCode6Package { | ||
| Query unusedReturnValueMisraCppQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `unusedReturnValueMisraCpp` query | ||
| TQueryCPP(TDeadCode6PackageQuery(TUnusedReturnValueMisraCppQuery())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
cpp/common/src/codingstandards/cpp/rules/unusedreturnvalueshared/UnusedReturnValueShared.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Provides a configurable module UnusedReturnValue with a `problems` predicate | ||
| * for the following issue: | ||
| * The value returned by a function having a non-void return type that is not an | ||
| * overloaded operator shall be used. | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.Customizations | ||
| import codingstandards.cpp.Exclusions | ||
|
|
||
| signature module UnusedReturnValueSharedConfigSig { | ||
| Query getQuery(); | ||
| } | ||
|
|
||
| module UnusedReturnValueShared<UnusedReturnValueSharedConfigSig Config> { | ||
| /* | ||
| * This query performs a simple syntactic check to ensure that the return value of the function is | ||
| * not completely ignored. This matches the examples given in the rule, although the text itself is | ||
| * not entirely clear. This means it will not find cases where something is done with the return | ||
| * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent | ||
| * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. | ||
| */ | ||
|
|
||
| query predicate problems(FunctionCall fc, string message, Function f, string funcName) { | ||
| not isExcluded(fc, Config::getQuery()) and | ||
| message = "Return value from call to $@ is unused." and | ||
| funcName = f.getName() and | ||
| // Find function calls in `ExprStmt`s, which indicate the return value is ignored | ||
| fc.getParent() instanceof ExprStmt and | ||
| // Ignore calls to void functions, which don't return values | ||
| not fc.getUnderlyingType() instanceof VoidType and | ||
| // Get the function target | ||
| f = fc.getTarget() and | ||
| // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, | ||
| // so the rule does not require the use of the return value | ||
| not f instanceof Operator and | ||
mbaluda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Exclude cases where the function call is generated within a macro, as the user of the macro is | ||
| // not necessarily able to address those results | ||
| not fc.isAffectedByMacro() and | ||
| // Rule allows disabling this rule where a static_cast<void> or a C-style cast to void is applied | ||
| not exists(Cast cast | cast instanceof StaticCast or cast instanceof CStyleCast | | ||
| fc.getExplicitlyConverted() = cast and | ||
| cast.getActualType() instanceof VoidType | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | test.cpp:15:3:15:3 | call to f | Return value from call to $@ is unused. | test.cpp:3:5:3:5 | f | f | |
8 changes: 8 additions & 0 deletions
8
cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // GENERATED FILE - DO NOT MODIFY | ||
| import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared | ||
|
|
||
| module TestFileConfig implements UnusedReturnValueSharedConfigSig { | ||
| Query getQuery() { result instanceof TestQuery } | ||
| } | ||
|
|
||
| import UnusedReturnValueShared<TestFileConfig> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * @id cpp/misra/unused-return-value-misra-cpp | ||
| * @name RULE-0-1-2: The value returned by a function shall be used | ||
| * @description The result of a non-void function shall be used if called with function call syntax. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-0-1-2 | ||
| * scope/single-translation-unit | ||
| * correctness | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
| import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared | ||
|
|
||
| module UnusedReturnValueMisraCppConfig implements UnusedReturnValueSharedConfigSig { | ||
| Query getQuery() { result = DeadCode6Package::unusedReturnValueMisraCppQuery() } | ||
| } | ||
|
|
||
| import UnusedReturnValueShared<UnusedReturnValueMisraCppConfig> |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "MISRA-C++-2023": { | ||
| "RULE-0-1-2": { | ||
| "properties": { | ||
| "enforcement": "decidable", | ||
| "obligation": "required" | ||
| }, | ||
| "queries": [ | ||
| { | ||
| "description": "The result of a non-void function shall be used if called with function call syntax.", | ||
| "kind": "problem", | ||
| "name": "The value returned by a function shall be used", | ||
| "precision": "very-high", | ||
| "severity": "error", | ||
| "short_name": "UnusedReturnValueMisraCpp", | ||
| "shared_implementation_short_name": "UnusedReturnValueShared", | ||
| "tags": [ | ||
| "scope/single-translation-unit", | ||
| "correctness" | ||
| ] | ||
| } | ||
| ], | ||
| "title": "The value returned by a function shall be used" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.