Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE test misra23 #588

Open
wants to merge 1 commit into
base: initial-misra-cpp-2023-support
Choose a base branch
from
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
19 changes: 18 additions & 1 deletion cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ newtype DeadCodeQuery =
TSingleUseLocalPODVariableQuery() or
TSingleUseGlobalOrNamespacePODVariableQuery() or
TSingleUseMemberPODVariableQuery() or
TDeadCodeQuery()
TDeadCodeQuery() or
TFunctionContainUnreachableStatementsQuery()

predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
Expand Down Expand Up @@ -165,6 +166,15 @@ predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, st
"cpp/autosar/dead-code" and
ruleId = "M0-1-9" and
category = "required"
or
query =
// `Query` instance for the `functionContainUnreachableStatements` query
DeadCodePackage::functionContainUnreachableStatementsQuery() and
queryId =
// `@id` for the `functionContainUnreachableStatements` query
"cpp/misra/function-contain-unreachable-statements" and
ruleId = "RULE-0-0-1" and
category = "required"
}

module DeadCodePackage {
Expand Down Expand Up @@ -279,4 +289,11 @@ module DeadCodePackage {
// `Query` type for `deadCode` query
TQueryCPP(TDeadCodePackageQuery(TDeadCodeQuery()))
}

Query functionContainUnreachableStatementsQuery() {
//autogenerate `Query` type
result =
// `Query` type for `functionContainUnreachableStatements` query
TQueryCPP(TDeadCodePackageQuery(TFunctionContainUnreachableStatementsQuery()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @id cpp/misra/function-contain-unreachable-statements
* @name RULE-0-0-1: A function shall not contain unreachable statements
* @description Unreachable statements can indicate a mistake on the part of the programmer.
* @kind problem
* @precision high
* @problem.severity error
* @tags external/misra/id/rule-0-0-1
* scope/single-translation-unit
* readability
* maintainability
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/

import cpp
import codingstandards.cpp.misra

from Expr x
where not isExcluded(x, DeadCodePackage::functionContainUnreachableStatementsQuery())
select x, "none"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| test.cpp:1:26:1:28 | arg | none |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/RULE-0-0-1/FunctionContainUnreachableStatements.ql
1 change: 1 addition & 0 deletions cpp/misra/test/rules/RULE-0-0-1/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int f1(int arg) { return arg; }
26 changes: 25 additions & 1 deletion rule_packages/cpp/DeadCode.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,29 @@
],
"title": "There shall be no dead code."
}
},
"MISRA-C++-2023": {
"RULE-0-0-1": {
"properties": {
"enforcement": "decidable",
"obligation": "required"
},
"queries": [
{
"description": "Unreachable statements can indicate a mistake on the part of the programmer.",
"kind": "problem",
"name": "A function shall not contain unreachable statements",
"precision": "high",
"severity": "error",
"short_name": "FunctionContainUnreachableStatements",
"tags": [
"scope/single-translation-unit",
"readability",
"maintainability"
]
}
],
"title": "A function shall not contain unreachable statements"
}
}
}
}
2 changes: 1 addition & 1 deletion rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ c,MISRA-C-2012,RULE-22-7,Yes,Required,,,The macro EOF shall only be compared wit
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,
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,
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,
cpp,MISRA-C++-2023,RULE-0-0-1,Yes,Required,Decidable,Single Translation Unit,A function shall not contain unreachable statements,,,Medium,
cpp,MISRA-C++-2023,RULE-0-0-1,Yes,Required,Decidable,Single Translation Unit,A function shall not contain unreachable statements,,DeadCode,Medium,
cpp,MISRA-C++-2023,RULE-0-0-2,Yes,Advisory,Undecidable,System,Controlling expressions should not be invariant,,,Easy,
cpp,MISRA-C++-2023,RULE-0-1-1,Yes,Advisory,Undecidable,System,A value should not be unnecessarily written to a local object,,,Medium,
cpp,MISRA-C++-2023,RULE-0-1-2,Yes,Required,Decidable,Single Translation Unit,The value returned by a function shall be used,,,Easy,
Expand Down
Loading