-
Notifications
You must be signed in to change notification settings - Fork 77
Declarations4 cpp misra 2023 #1100
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
Open
knewbury01
wants to merge
4
commits into
github:main
Choose a base branch
from
knewbury01:knewbury01/cpp-misra2023-declarations4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations4.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 Declarations4Query = TVolatileQualifierNotUsedAppropriatelyQuery() | ||
|
|
||
| predicate isDeclarations4QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `volatileQualifierNotUsedAppropriately` query | ||
| Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery() and | ||
| queryId = | ||
| // `@id` for the `volatileQualifierNotUsedAppropriately` query | ||
| "cpp/misra/volatile-qualifier-not-used-appropriately" and | ||
| ruleId = "RULE-10-1-2" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module Declarations4Package { | ||
| Query volatileQualifierNotUsedAppropriatelyQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `volatileQualifierNotUsedAppropriately` query | ||
| TQueryCPP(TDeclarations4PackageQuery(TVolatileQualifierNotUsedAppropriatelyQuery())) | ||
| } | ||
| } |
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
31 changes: 31 additions & 0 deletions
31
cpp/misra/src/rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.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,31 @@ | ||
| /** | ||
| * @id cpp/misra/volatile-qualifier-not-used-appropriately | ||
| * @name RULE-10-1-2: The volatile qualifier shall be used appropriately | ||
| * @description Using the volatile qualifier on certain entities can lead to undefined behavior or | ||
| * code that is hard to understand. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-10-1-2 | ||
| * correctness | ||
| * readability | ||
| * maintainability | ||
| * scope/single-translation-unit | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
|
|
||
| from Declaration d | ||
| where | ||
| not isExcluded(d, Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery()) and | ||
| d.getADeclarationEntry().getType().isVolatile() and | ||
| ( | ||
| d instanceof LocalVariable or | ||
| exists(d.(Parameter).getFunction()) or | ||
| d instanceof Function or | ||
| d.(Variable).isStructuredBinding() | ||
| ) | ||
| select d, "Volatile entity declared." | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
7 changes: 7 additions & 0 deletions
7
cpp/misra/test/rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.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,7 @@ | ||
| | test.cpp:2:16:2:16 | g1 | Volatile entity declared. | | ||
| | test.cpp:4:21:4:21 | p | Volatile entity declared. | | ||
| | test.cpp:5:16:5:16 | x | Volatile entity declared. | | ||
| | test.cpp:9:18:9:18 | a | Volatile entity declared. | | ||
| | test.cpp:12:14:12:15 | f1 | Volatile entity declared. | | ||
| | test.cpp:15:23:15:23 | p | Volatile entity declared. | | ||
| | test.cpp:19:16:19:16 | m | Volatile entity declared. | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.qlref
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 @@ | ||
| rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.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,26 @@ | ||
| int g[1] = {1}; | ||
| auto volatile [g1] = g; // NON_COMPLIANT | ||
knewbury01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void f(volatile int p) { // NON_COMPLIANT | ||
| volatile int x = 1; // NON_COMPLIANT | ||
| int y = 2; // COMPLIANT | ||
|
|
||
| int z[1] = {1}; | ||
| auto volatile [a] = z; // NON_COMPLIANT | ||
| } | ||
|
|
||
| volatile int f1(); // NON_COMPLIANT | ||
|
|
||
| void f2(volatile int *p); // COMPLIANT | ||
| void f3(int *volatile p); // NON_COMPLIANT | ||
|
|
||
| class C { | ||
| public: | ||
| volatile int m(); // NON_COMPLIANT | ||
| int m1(); // COMPLIANT | ||
| volatile int m2; // COMPLIANT | ||
| }; | ||
|
|
||
| struct S { | ||
| volatile int s; // COMPLIANT | ||
| }; | ||
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,27 @@ | ||
| { | ||
| "MISRA-C++-2023": { | ||
| "RULE-10-1-2": { | ||
| "properties": { | ||
| "enforcement": "decidable", | ||
| "obligation": "required" | ||
| }, | ||
| "queries": [ | ||
| { | ||
| "description": "Using the volatile qualifier on certain entities can lead to undefined behavior or code that is hard to understand.", | ||
knewbury01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "kind": "problem", | ||
| "name": "The volatile qualifier shall be used appropriately", | ||
| "precision": "very-high", | ||
| "severity": "error", | ||
| "short_name": "VolatileQualifierNotUsedAppropriately", | ||
| "tags": [ | ||
| "correctness", | ||
| "readability", | ||
| "maintainability", | ||
| "scope/single-translation-unit" | ||
| ] | ||
| } | ||
| ], | ||
| "title": "The volatile qualifier shall be used appropriately" | ||
| } | ||
| } | ||
| } | ||
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.