Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -33,6 +33,7 @@ import DeadCode8
import DeadCode9
import Declarations
import Declarations1
import Declarations4
import ExceptionSafety
import Exceptions1
import Exceptions2
Expand Down Expand Up @@ -129,6 +130,7 @@ newtype TCPPQuery =
TDeadCode9PackageQuery(DeadCode9Query q) or
TDeclarationsPackageQuery(DeclarationsQuery q) or
TDeclarations1PackageQuery(Declarations1Query q) or
TDeclarations4PackageQuery(Declarations4Query q) or
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
TExceptions1PackageQuery(Exceptions1Query q) or
TExceptions2PackageQuery(Exceptions2Query q) or
Expand Down Expand Up @@ -225,6 +227,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isDeadCode9QueryMetadata(query, queryId, ruleId, category) or
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
isDeclarations4QueryMetadata(query, queryId, ruleId, category) or
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @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 has behavior that is not
* well-defined and can make code harder to understand, especially as its application
* to these entities does not prevent data races or guarantee safe multithreading.
* @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 '" + d.getName() + "' declared."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| test.cpp:2:16:2:16 | g1 | Volatile entity 'g1' declared. |
| test.cpp:5:21:5:21 | p | Volatile entity 'p' declared. |
| test.cpp:6:16:6:16 | x | Volatile entity 'x' declared. |
| test.cpp:10:18:10:18 | a | Volatile entity 'a' declared. |
| test.cpp:13:14:13:15 | f1 | Volatile entity 'f1' declared. |
| test.cpp:16:23:16:23 | p | Volatile entity 'p' declared. |
| test.cpp:20:16:20:16 | m | Volatile entity 'm' declared. |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.ql
27 changes: 27 additions & 0 deletions cpp/misra/test/rules/RULE-10-1-2/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
int g[1] = {1};
auto volatile [g1] = g; // NON_COMPLIANT
volatile int g2; // COMPLIANT

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
};
27 changes: 27 additions & 0 deletions rule_packages/cpp/Declarations4.json
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 has behavior that is not well-defined and can make code harder to understand, especially as its application to these entities does not prevent data races or guarantee safe multithreading.",
"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"
}
}
}
2 changes: 1 addition & 1 deletion rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ cpp,MISRA-C++-2023,RULE-9-6-4,Yes,Required,Undecidable,System,A function declare
cpp,MISRA-C++-2023,RULE-9-6-5,Yes,Required,Decidable,Single Translation Unit,A function with non-void return type shall return a value on all paths,MSC52-CPP,ImportMisra23,Import,
cpp,MISRA-C++-2023,RULE-10-0-1,Yes,Advisory,Decidable,Single Translation Unit,A declaration should not declare more than one variable or member variable,M8-0-1,ImportMisra23,Import,
cpp,MISRA-C++-2023,RULE-10-1-1,Yes,Advisory,Decidable,Single Translation Unit,The target type of a pointer or lvalue reference parameter should be const-qualified appropriately,RULE-8-13,Declarations2,Hard,
cpp,MISRA-C++-2023,RULE-10-1-2,Yes,Required,Decidable,Single Translation Unit,The volatile qualifier shall be used appropriately,,Declarations2,Easy,
cpp,MISRA-C++-2023,RULE-10-1-2,Yes,Required,Decidable,Single Translation Unit,The volatile qualifier shall be used appropriately,A2-11-1,Declarations4,Easy,
cpp,MISRA-C++-2023,RULE-10-2-1,Yes,Required,Decidable,Single Translation Unit,An enumeration shall be defined with an explicit underlying type,A7-2-2,ImportMisra23,Import,
cpp,MISRA-C++-2023,RULE-10-2-2,Yes,Advisory,Decidable,Single Translation Unit,Unscoped enumerations should not be declared,A7-2-3,Banned2,Easy,
cpp,MISRA-C++-2023,RULE-10-2-3,Yes,Required,Decidable,Single Translation Unit,The numeric value of an unscoped enumeration with no fixed underlying type shall not be used,A4-5-1,Banned3,Easy,
Expand Down