Skip to content

Commit 6fd7c37

Browse files
committed
Add RULE-10-1-2
1 parent 69147ac commit 6fd7c37

File tree

8 files changed

+126
-1
lines changed

8 files changed

+126
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Declarations4Query = TVolatileQualifierNotUsedAppropriatelyQuery()
7+
8+
predicate isDeclarations4QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `volatileQualifierNotUsedAppropriately` query
11+
Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery() and
12+
queryId =
13+
// `@id` for the `volatileQualifierNotUsedAppropriately` query
14+
"cpp/misra/volatile-qualifier-not-used-appropriately" and
15+
ruleId = "RULE-10-1-2" and
16+
category = "required"
17+
}
18+
19+
module Declarations4Package {
20+
Query volatileQualifierNotUsedAppropriatelyQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `volatileQualifierNotUsedAppropriately` query
24+
TQueryCPP(TDeclarations4PackageQuery(TVolatileQualifierNotUsedAppropriatelyQuery()))
25+
}
26+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import DeadCode8
3333
import DeadCode9
3434
import Declarations
3535
import Declarations1
36+
<<<<<<< HEAD
37+
=======
38+
import Declarations3
39+
import Declarations4
40+
>>>>>>> bc0278c3c (Add RULE-10-1-2)
3641
import ExceptionSafety
3742
import Exceptions1
3843
import Exceptions2
@@ -129,6 +134,7 @@ newtype TCPPQuery =
129134
TDeadCode9PackageQuery(DeadCode9Query q) or
130135
TDeclarationsPackageQuery(DeclarationsQuery q) or
131136
TDeclarations1PackageQuery(Declarations1Query q) or
137+
TDeclarations4PackageQuery(Declarations4Query q) or
132138
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
133139
TExceptions1PackageQuery(Exceptions1Query q) or
134140
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -225,6 +231,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
225231
isDeadCode9QueryMetadata(query, queryId, ruleId, category) or
226232
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
227233
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
234+
isDeclarations4QueryMetadata(query, queryId, ruleId, category) or
228235
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
229236
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
230237
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @id cpp/misra/volatile-qualifier-not-used-appropriately
3+
* @name RULE-10-1-2: The volatile qualifier shall be used appropriately
4+
* @description Using the volatile qualifier on certain entities can lead to undefined behavior or
5+
* code that is hard to understand.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-10-1-2
10+
* correctness
11+
* readability
12+
* maintainability
13+
* scope/single-translation-unit
14+
* external/misra/enforcement/decidable
15+
* external/misra/obligation/required
16+
*/
17+
18+
import cpp
19+
import codingstandards.cpp.misra
20+
21+
from Declaration d
22+
where
23+
not isExcluded(d, Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery()) and
24+
d.getADeclarationEntry().getType().isVolatile() and
25+
(
26+
d instanceof LocalVariable or
27+
exists(d.(Parameter).getFunction()) or
28+
d instanceof Function or
29+
d.(Variable).isStructuredBinding()
30+
)
31+
select d, "Volatile entity declared."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| test.cpp:2:16:2:16 | g1 | Volatile entity declared. |
2+
| test.cpp:4:21:4:21 | p | Volatile entity declared. |
3+
| test.cpp:5:16:5:16 | x | Volatile entity declared. |
4+
| test.cpp:9:18:9:18 | a | Volatile entity declared. |
5+
| test.cpp:12:14:12:15 | f1 | Volatile entity declared. |
6+
| test.cpp:15:23:15:23 | p | Volatile entity declared. |
7+
| test.cpp:19:16:19:16 | m | Volatile entity declared. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-10-1-2/VolatileQualifierNotUsedAppropriately.ql
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
int g[1] = {1};
2+
auto volatile [g1] = g; // NON_COMPLIANT
3+
4+
void f(volatile int p) { // NON_COMPLIANT
5+
volatile int x = 1; // NON_COMPLIANT
6+
int y = 2; // COMPLIANT
7+
8+
int z[1] = {1};
9+
auto volatile [a] = z; // NON_COMPLIANT
10+
}
11+
12+
volatile int f1(); // NON_COMPLIANT
13+
14+
void f2(volatile int *p); // COMPLIANT
15+
void f3(int *volatile p); // NON_COMPLIANT
16+
17+
class C {
18+
public:
19+
volatile int m(); // NON_COMPLIANT
20+
int m1(); // COMPLIANT
21+
volatile int m2; // COMPLIANT
22+
};
23+
24+
struct S {
25+
volatile int s; // COMPLIANT
26+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"MISRA-C++-2023": {
3+
"RULE-10-1-2": {
4+
"properties": {
5+
"enforcement": "decidable",
6+
"obligation": "required"
7+
},
8+
"queries": [
9+
{
10+
"description": "Using the volatile qualifier on certain entities can lead to undefined behavior or code that is hard to understand.",
11+
"kind": "problem",
12+
"name": "The volatile qualifier shall be used appropriately",
13+
"precision": "very-high",
14+
"severity": "error",
15+
"short_name": "VolatileQualifierNotUsedAppropriately",
16+
"tags": [
17+
"correctness",
18+
"readability",
19+
"maintainability",
20+
"scope/single-translation-unit"
21+
]
22+
}
23+
],
24+
"title": "The volatile qualifier shall be used appropriately"
25+
}
26+
}
27+
}

rules.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ cpp,MISRA-C++-2023,RULE-9-6-4,Yes,Required,Undecidable,System,A function declare
916916
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,
917917
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,
918918
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,
919-
cpp,MISRA-C++-2023,RULE-10-1-2,Yes,Required,Decidable,Single Translation Unit,The volatile qualifier shall be used appropriately,,Declarations2,Easy,
919+
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,
920920
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,
921921
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,
922922
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,

0 commit comments

Comments
 (0)