Skip to content

Commit a8dda3d

Browse files
committed
Merge branch 'jeongsoolee09/MISRA-C++-2023-Banned856' of github.com:github/codeql-coding-standards into jeongsoolee09/MISRA-C++-2023-Banned856
2 parents 5ef3a9d + 6035f80 commit a8dda3d

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Declarations
3838
import Declarations1
3939
import Declarations2
4040
import Declarations3
41+
import Declarations4
4142
import ExceptionSafety
4243
import Exceptions1
4344
import Exceptions2
@@ -139,6 +140,7 @@ newtype TCPPQuery =
139140
TDeclarations1PackageQuery(Declarations1Query q) or
140141
TDeclarations2PackageQuery(Declarations2Query q) or
141142
TDeclarations3PackageQuery(Declarations3Query q) or
143+
TDeclarations4PackageQuery(Declarations4Query q) or
142144
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
143145
TExceptions1PackageQuery(Exceptions1Query q) or
144146
TExceptions2PackageQuery(Exceptions2Query q) or
@@ -240,6 +242,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
240242
isDeclarations1QueryMetadata(query, queryId, ruleId, category) or
241243
isDeclarations2QueryMetadata(query, queryId, ruleId, category) or
242244
isDeclarations3QueryMetadata(query, queryId, ruleId, category) or
245+
isDeclarations4QueryMetadata(query, queryId, ruleId, category) or
243246
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
244247
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
245248
isExceptions2QueryMetadata(query, queryId, ruleId, category) or
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 has behavior that is not
5+
* well-defined and can make code harder to understand, especially as its application
6+
* to these entities does not prevent data races or guarantee safe multithreading.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity error
10+
* @tags external/misra/id/rule-10-1-2
11+
* correctness
12+
* readability
13+
* maintainability
14+
* scope/single-translation-unit
15+
* external/misra/enforcement/decidable
16+
* external/misra/obligation/required
17+
*/
18+
19+
import cpp
20+
import codingstandards.cpp.misra
21+
22+
from Declaration d
23+
where
24+
not isExcluded(d, Declarations4Package::volatileQualifierNotUsedAppropriatelyQuery()) and
25+
d.getADeclarationEntry().getType().isVolatile() and
26+
(
27+
d instanceof LocalVariable or
28+
exists(d.(Parameter).getFunction()) or
29+
d instanceof Function or
30+
d.(Variable).isStructuredBinding()
31+
)
32+
select d, "Volatile entity '" + d.getName() + "' 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 'g1' declared. |
2+
| test.cpp:5:21:5:21 | p | Volatile entity 'p' declared. |
3+
| test.cpp:6:16:6:16 | x | Volatile entity 'x' declared. |
4+
| test.cpp:10:18:10:18 | a | Volatile entity 'a' declared. |
5+
| test.cpp:13:14:13:15 | f1 | Volatile entity 'f1' declared. |
6+
| test.cpp:16:23:16:23 | p | Volatile entity 'p' declared. |
7+
| test.cpp:20:16:20:16 | m | Volatile entity 'm' 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
int g[1] = {1};
2+
auto volatile [g1] = g; // NON_COMPLIANT
3+
volatile int g2; // COMPLIANT
4+
5+
void f(volatile int p) { // NON_COMPLIANT
6+
volatile int x = 1; // NON_COMPLIANT
7+
int y = 2; // COMPLIANT
8+
9+
int z[1] = {1};
10+
auto volatile [a] = z; // NON_COMPLIANT
11+
}
12+
13+
volatile int f1(); // NON_COMPLIANT
14+
15+
void f2(volatile int *p); // COMPLIANT
16+
void f3(int *volatile p); // NON_COMPLIANT
17+
18+
class C {
19+
public:
20+
volatile int m(); // NON_COMPLIANT
21+
int m1(); // COMPLIANT
22+
volatile int m2; // COMPLIANT
23+
};
24+
25+
struct S {
26+
volatile int s; // COMPLIANT
27+
};
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 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.",
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+
}

0 commit comments

Comments
 (0)