Skip to content

Commit d5b8a46

Browse files
Merge pull request #1023 from github/jeongsoolee09/MISRA-C++-Memory2-Memory3
Add `Memory2` and `Memory3` package
2 parents 4f23719 + dfe986f commit d5b8a46

File tree

10 files changed

+163
-3
lines changed

10 files changed

+163
-3
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 Memory2Query = TPointerDifferenceTakenBetweenDifferentArraysQuery()
7+
8+
predicate isMemory2QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `pointerDifferenceTakenBetweenDifferentArrays` query
11+
Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery() and
12+
queryId =
13+
// `@id` for the `pointerDifferenceTakenBetweenDifferentArrays` query
14+
"cpp/misra/pointer-difference-taken-between-different-arrays" and
15+
ruleId = "RULE-8-7-2" and
16+
category = "required"
17+
}
18+
19+
module Memory2Package {
20+
Query pointerDifferenceTakenBetweenDifferentArraysQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `pointerDifferenceTakenBetweenDifferentArrays` query
24+
TQueryCPP(TMemory2PackageQuery(TPointerDifferenceTakenBetweenDifferentArraysQuery()))
25+
}
26+
}
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 Memory3Query = TPointerComparedBetweenDifferentArraysQuery()
7+
8+
predicate isMemory3QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `pointerComparedBetweenDifferentArrays` query
11+
Memory3Package::pointerComparedBetweenDifferentArraysQuery() and
12+
queryId =
13+
// `@id` for the `pointerComparedBetweenDifferentArrays` query
14+
"cpp/misra/pointer-compared-between-different-arrays" and
15+
ruleId = "RULE-8-9-1" and
16+
category = "required"
17+
}
18+
19+
module Memory3Package {
20+
Query pointerComparedBetweenDifferentArraysQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `pointerComparedBetweenDifferentArrays` query
24+
TQueryCPP(TMemory3PackageQuery(TPointerComparedBetweenDifferentArraysQuery()))
25+
}
26+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import Linkage2
4040
import Literals
4141
import Loops
4242
import Macros
43+
import Memory2
44+
import Memory3
4345
import MoveForward
4446
import Naming
4547
import Null
@@ -106,6 +108,8 @@ newtype TCPPQuery =
106108
TLiteralsPackageQuery(LiteralsQuery q) or
107109
TLoopsPackageQuery(LoopsQuery q) or
108110
TMacrosPackageQuery(MacrosQuery q) or
111+
TMemory2PackageQuery(Memory2Query q) or
112+
TMemory3PackageQuery(Memory3Query q) or
109113
TMoveForwardPackageQuery(MoveForwardQuery q) or
110114
TNamingPackageQuery(NamingQuery q) or
111115
TNullPackageQuery(NullQuery q) or
@@ -172,6 +176,8 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
172176
isLiteralsQueryMetadata(query, queryId, ruleId, category) or
173177
isLoopsQueryMetadata(query, queryId, ruleId, category) or
174178
isMacrosQueryMetadata(query, queryId, ruleId, category) or
179+
isMemory2QueryMetadata(query, queryId, ruleId, category) or
180+
isMemory3QueryMetadata(query, queryId, ruleId, category) or
175181
isMoveForwardQueryMetadata(query, queryId, ruleId, category) or
176182
isNamingQueryMetadata(query, queryId, ruleId, category) or
177183
isNullQueryMetadata(query, queryId, ruleId, category) or
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/pointer-difference-taken-between-different-arrays
3+
* @name RULE-8-7-2: Subtraction between pointers shall only be applied to ones that address elements of the same array
4+
* @description Pointer difference should be taken from pointers that belong to a same array.
5+
* @kind path-problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-8-7-2
9+
* scope/system
10+
* correctness
11+
* external/misra/enforcement/undecidable
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.donotsubtractpointersaddressingdifferentarrays.DoNotSubtractPointersAddressingDifferentArrays
18+
19+
class PointerDifferenceTakenBetweenDifferentArraysQuery extends DoNotSubtractPointersAddressingDifferentArraysSharedQuery
20+
{
21+
PointerDifferenceTakenBetweenDifferentArraysQuery() {
22+
this = Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery()
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/pointer-compared-between-different-arrays
3+
* @name RULE-8-9-1: The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type
4+
* @description Pointer comparison should be done between ones that belong to a same array.
5+
* @kind path-problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-8-9-1
9+
* scope/system
10+
* correctness
11+
* external/misra/enforcement/undecidable
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.donotuserelationaloperatorswithdifferingarrays.DoNotUseRelationalOperatorsWithDifferingArrays
18+
19+
class PointerComparedBetweenDifferentArraysQuery extends DoNotUseRelationalOperatorsWithDifferingArraysSharedQuery
20+
{
21+
PointerComparedBetweenDifferentArraysQuery() {
22+
this = Memory3Package::pointerComparedBetweenDifferentArraysQuery()
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/donotuserelationaloperatorswithdifferingarrays/DoNotUseRelationalOperatorsWithDifferingArrays.ql

rule_packages/cpp/Memory2.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"MISRA-C++-2023": {
3+
"RULE-8-7-2": {
4+
"properties": {
5+
"enforcement": "undecidable",
6+
"obligation": "required"
7+
},
8+
"queries": [
9+
{
10+
"description": "Pointer difference should be taken from pointers that belong to a same array.",
11+
"kind": "path-problem",
12+
"name": "Subtraction between pointers shall only be applied to ones that address elements of the same array",
13+
"precision": "high",
14+
"severity": "error",
15+
"short_name": "PointerDifferenceTakenBetweenDifferentArrays",
16+
"shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays",
17+
"tags": [
18+
"scope/system",
19+
"correctness"
20+
]
21+
}
22+
],
23+
"title": "Pointer difference should be taken from pointers that belong to a same array."
24+
}
25+
}
26+
}

rule_packages/cpp/Memory3.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"MISRA-C++-2023": {
3+
"RULE-8-9-1": {
4+
"properties": {
5+
"enforcement": "undecidable",
6+
"obligation": "required"
7+
},
8+
"queries": [
9+
{
10+
"description": "Pointer comparison should be done between ones that belong to a same array.",
11+
"kind": "path-problem",
12+
"name": "The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type",
13+
"precision": "high",
14+
"severity": "error",
15+
"short_name": "PointerComparedBetweenDifferentArrays",
16+
"shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays",
17+
"tags": [
18+
"scope/system",
19+
"correctness"
20+
]
21+
}
22+
],
23+
"title": "Pointer comparison should be done between ones that belong to a same array."
24+
}
25+
}
26+
}

rules.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ cpp,MISRA-C++-2023,RULE-8-2-10,Yes,Required,Undecidable,System,"Functions shall
895895
cpp,MISRA-C++-2023,RULE-8-2-11,Yes,Required,Decidable,Single Translation Unit,An argument passed via ellipsis shall have an appropriate type,,Preconditions,Easy,
896896
cpp,MISRA-C++-2023,RULE-8-3-1,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary - operator should not be applied to an expression of unsigned type,M5-3-2,ImportMisra23,Import,
897897
cpp,MISRA-C++-2023,RULE-8-3-2,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary + operator should not be used,,Banned,Easy,
898-
cpp,MISRA-C++-2023,RULE-8-7-1,Yes,Required,Undecidable,System,Pointer arithmetic shall not form an invalid pointer,ARR30-C,Memory,Easy,
899-
cpp,MISRA-C++-2023,RULE-8-7-2,Yes,Required,Undecidable,System,Subtraction between pointers shall only be applied to pointers that address elements of the same array,ARR36-C,Memory,Easy,
900-
cpp,MISRA-C++-2023,RULE-8-9-1,Yes,Required,Undecidable,System,"The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array",ARR36-C,Memory,Easy,
898+
cpp,MISRA-C++-2023,RULE-8-7-1,Yes,Required,Undecidable,System,Pointer arithmetic shall not form an invalid pointer,ARR30-C,Memory1,Easy,
899+
cpp,MISRA-C++-2023,RULE-8-7-2,Yes,Required,Undecidable,System,Subtraction between pointers shall only be applied to pointers that address elements of the same array,ARR36-C,Memory2,Easy,
900+
cpp,MISRA-C++-2023,RULE-8-9-1,Yes,Required,Undecidable,System,"The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array",ARR36-C,Memory3,Easy,
901901
cpp,MISRA-C++-2023,RULE-8-14-1,Yes,Advisory,Undecidable,System,The right-hand operand of a logical && or operator should not contain persistent side effects,"M5-14-1, RULE-13-5",SideEffects3,Medium,
902902
cpp,MISRA-C++-2023,RULE-8-18-1,Yes,Mandatory,Undecidable,System,An object or subobject must not be copied to an overlapping object,"M0-2-1, RULE-19-1",Memory,Hard,
903903
cpp,MISRA-C++-2023,RULE-8-18-2,Yes,Advisory,Decidable,Single Translation Unit,The result of an assignment operator should not be used,RULE-13-4,ImportMisra23,Import,

0 commit comments

Comments
 (0)