-
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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())) | ||
| } | ||
| } |
| 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." | ||
| 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. | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.ql |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| int g[1] = {1}; | ||
| auto volatile [g1] = g; // NON_COMPLIANT | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a test for |
||
|
|
||
| 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 | ||
| }; | ||
| 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.", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding that it is often misused for multithreading and/or that the behavior for these usages of volatile aren't well defined |
||
| "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" | ||
| } | ||
| } | ||
| } | ||
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.
To help users sort through potential findings easier in line with the style guide