Skip to content

Commit eac5d4b

Browse files
committed
test misra23
1 parent 2ff8a68 commit eac5d4b

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ newtype DeadCodeQuery =
1919
TSingleUseLocalPODVariableQuery() or
2020
TSingleUseGlobalOrNamespacePODVariableQuery() or
2121
TSingleUseMemberPODVariableQuery() or
22-
TDeadCodeQuery()
22+
TDeadCodeQuery() or
23+
TFunctionContainUnreachableStatementsQuery()
2324

2425
predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, string category) {
2526
query =
@@ -165,6 +166,15 @@ predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, st
165166
"cpp/autosar/dead-code" and
166167
ruleId = "M0-1-9" and
167168
category = "required"
169+
or
170+
query =
171+
// `Query` instance for the `functionContainUnreachableStatements` query
172+
DeadCodePackage::functionContainUnreachableStatementsQuery() and
173+
queryId =
174+
// `@id` for the `functionContainUnreachableStatements` query
175+
"cpp/misra/function-contain-unreachable-statements" and
176+
ruleId = "RULE-0-0-1" and
177+
category = "required"
168178
}
169179

170180
module DeadCodePackage {
@@ -279,4 +289,11 @@ module DeadCodePackage {
279289
// `Query` type for `deadCode` query
280290
TQueryCPP(TDeadCodePackageQuery(TDeadCodeQuery()))
281291
}
292+
293+
Query functionContainUnreachableStatementsQuery() {
294+
//autogenerate `Query` type
295+
result =
296+
// `Query` type for `functionContainUnreachableStatements` query
297+
TQueryCPP(TDeadCodePackageQuery(TFunctionContainUnreachableStatementsQuery()))
298+
}
282299
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @id cpp/misra/function-contain-unreachable-statements
3+
* @name RULE-0-0-1: A function shall not contain unreachable statements
4+
* @description Unreachable statements can indicate a mistake on the part of the programmer.
5+
* @kind problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-0-0-1
9+
* scope/single-translation-unit
10+
* readability
11+
* maintainability
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
19+
from Expr x
20+
where not isExcluded(x, DeadCodePackage::functionContainUnreachableStatementsQuery())
21+
select x, "none"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:1:26:1:28 | arg | none |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-0-0-1/FunctionContainUnreachableStatements.ql
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int f1(int arg) { return arg; }

rule_packages/cpp/DeadCode.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,29 @@
349349
],
350350
"title": "There shall be no dead code."
351351
}
352+
},
353+
"MISRA-C++-2023": {
354+
"RULE-0-0-1": {
355+
"properties": {
356+
"enforcement": "decidable",
357+
"obligation": "required"
358+
},
359+
"queries": [
360+
{
361+
"description": "Unreachable statements can indicate a mistake on the part of the programmer.",
362+
"kind": "problem",
363+
"name": "A function shall not contain unreachable statements",
364+
"precision": "high",
365+
"severity": "error",
366+
"short_name": "FunctionContainUnreachableStatements",
367+
"tags": [
368+
"scope/single-translation-unit",
369+
"readability",
370+
"maintainability"
371+
]
372+
}
373+
],
374+
"title": "A function shall not contain unreachable statements"
375+
}
352376
}
353-
}
377+
}

rules.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ c,MISRA-C-2012,RULE-22-7,Yes,Required,,,The macro EOF shall only be compared wit
774774
c,MISRA-C-2012,RULE-22-8,Yes,Required,,,The value of errno shall be set to zero prior to a call to an errno-setting-function,ERR30-C,Contracts3,Medium,
775775
c,MISRA-C-2012,RULE-22-9,Yes,Required,,,The value of errno shall be tested against zero after calling an errno-setting-function,,Contracts3,Medium,
776776
c,MISRA-C-2012,RULE-22-10,Yes,Required,,,The value of errno shall only be tested when the last function to be called was an errno-setting-function,,Contracts3,Medium,
777-
cpp,MISRA-C++-2023,RULE-0-0-1,Yes,Required,Decidable,Single Translation Unit,A function shall not contain unreachable statements,,,Medium,
777+
cpp,MISRA-C++-2023,RULE-0-0-1,Yes,Required,Decidable,Single Translation Unit,A function shall not contain unreachable statements,,DeadCode,Medium,
778778
cpp,MISRA-C++-2023,RULE-0-0-2,Yes,Advisory,Undecidable,System,Controlling expressions should not be invariant,,,Easy,
779779
cpp,MISRA-C++-2023,RULE-0-1-1,Yes,Advisory,Undecidable,System,A value should not be unnecessarily written to a local object,,,Medium,
780780
cpp,MISRA-C++-2023,RULE-0-1-2,Yes,Required,Decidable,Single Translation Unit,The value returned by a function shall be used,,,Easy,

0 commit comments

Comments
 (0)