Skip to content

Initial misra cpp 2023 support #586

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

Merged
merged 15 commits into from
Jul 23, 2024
Merged
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
2 changes: 2 additions & 0 deletions change_notes/2024-06-21-misra-cpp-2023-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `MISRA C++ 2023`:
- Extend the project structure and provide initial support for query writing.
1 change: 1 addition & 0 deletions cpp/common/test/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle-extractor-options:--clang -std=c++17 -nostdinc++ -I../../../../common/test/includes/standard-library -I../../../../common/test/includes/custom-library
10 changes: 10 additions & 0 deletions cpp/misra/src/codeql-suites/misra-default.qls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- description: MISRA C++ 2023 (Default)
- qlpack: codeql/misra-cpp-coding-standards
- include:
kind:
- problem
- path-problem
- exclude:
tags contain:
- external/misra/audit
- external/misra/default-disabled
12 changes: 12 additions & 0 deletions cpp/misra/src/codeql-suites/misra-single-translation-unit.qls
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- description: MISRA C++ 2023 (Single Translation Unit)
- qlpack: codeql/misra-cpp-coding-standards
- include:
kind:
- problem
- path-problem
tags contain:
- scope/single-translation-unit
- exclude:
tags contain:
- external/misra/audit
- external/misra/default-disabled
4 changes: 4 additions & 0 deletions cpp/misra/src/codingstandards/cpp/misra.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import cpp
import misra.Customizations
import codingstandards.cpp.CodingStandards
import codingstandards.cpp.exclusions.cpp.RuleMetadata
8 changes: 8 additions & 0 deletions cpp/misra/src/codingstandards/cpp/misra/Customizations.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Contains customizations to the MISRA C++ query rules.
*
* This module is imported by `misra.qll`, so any customizations defined here
* automatically apply to all MISRA C++ queries.
*/

import cpp
2 changes: 1 addition & 1 deletion cpp/misra/src/qlpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: codeql/misra-cpp-coding-standards
version: 2.33.0-dev
description: MISRA C++ 2008
description: MISRA C++ 2023
suites: codeql-suites
license: MIT
dependencies:
Expand Down
1 change: 1 addition & 0 deletions cpp/misra/test/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle-extractor-options:--clang -std=c++17 -nostdinc++ -I../../../../common/test/includes/standard-library -I../../../../common/test/includes/custom-library
2 changes: 1 addition & 1 deletion docs/design/guideline_recategorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The *effective category* is the category whose policy is applied during the eval
The policy of a category dictates if a result can be deviated from and implements the effect described in the design section.
The existing exclusion mechanism implemented in the predicate `isExcluded` defined in the `Exclusions.qll` library will be updated to consider the applicable policy of a guideline.

Note: This changes the behavior of deviations which will no longer have an impact on Mandatory guidelines! However, this will only affect MISRA C rules because there are no MISRA C++ Guidelines with a Mandatory category.
Note: This changes the behavior of deviations which will no longer have an impact on Mandatory MISRA guidelines!

### Specification validation

Expand Down
49 changes: 49 additions & 0 deletions schemas/rule-package.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,55 @@
"minProperties": 1
}
}
},
{
"properties": {
"MISRA-C++-2023": {
"description": "Rules part of the MISRA C++ 2023 standard",
"type": "object",
"patternProperties": {
"^RULE-\\d+-\\d+-\\d+": {
"description": "A coding standard rule",
"type": "object",
"properties": {
"properties": {
"type": "object",
"properties": {
"obligation": {
"type": "string",
"enum": [
"required",
"advisory",
"mandatory"
]
}
},
"required": [
"obligation"
]
},
"queries": {
"type": "array",
"uniqueItems": true,
"items": {
"$ref": "#/$defs/query"
}
},
"title": {
"type": "string"
}
},
"required": [
"properties",
"queries",
"title"
],
"additionalProperties": false
}
},
"minProperties": 1
}
}
}
],
"minProperties": 1,
Expand Down
14 changes: 12 additions & 2 deletions scripts/generate_rules/generate_package_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,24 @@ def generate_short_name(title):
print("Error: " + standard + " " + rule_id + " is marked as part of package " + package_name + " but is not marked as supportable.")
sys.exit(1)

tags = []

# Add the AUTOSAR obligation, enforcement and allocated target as query properties.
properties = {}
if obligation_level:
properties["obligation"] = obligation_level.lower()
if enforcement_level:
properties["enforcement"] = enforcement_level.lower()
if allocated_targets:
properties["allocated-target"] = [target.strip(' ').lower() for target in allocated_targets.split("/")]
if allocated_targets == "Single Translation Unit":
# MISRA C++ 2023 uses the allocated targets field for scope
tags.append("scope/single-translation-unit")
elif allocated_targets == "System":
# MISRA C++ 2023 uses the allocated targets field for scope
tags.append("scope/system")
else:
properties["allocated-target"] = [target.strip(' ').lower() for target in allocated_targets.split("/")]

if difficulty == "Audit":
properties["audit"] = ""

Expand Down Expand Up @@ -164,7 +174,7 @@ def generate_short_name(title):
"severity" : severity,
"description" : description,
"kind" : "problem",
"tags" : []
"tags" : tags
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion scripts/generate_rules/generate_package_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@
"MISRA-C-2012" : {
"standard_title" : "MISRA-C:2012 Guidelines for the use of the C language in critical systems",
"standard_url" : "https://www.misra.org.uk/"
},
"MISRA-C++-2023" : {
"standard_title" : "MISRA C++:2023 Guidelines for the use C++:17 in critical systems",
"standard_url" : "https://misra.org.uk/product/misra-cpp2023/"
}
}

# The help files of these standards cannot be distributed in our repository.
external_help_file_standards = ["AUTOSAR", "MISRA-C-2012"]
external_help_file_standards = ["AUTOSAR", "MISRA-C-2012", "MISRA-C++-2023"]

# Mapping from the QL language to source file extension used to generate a help example file.
ql_language_ext_mappings = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/reports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, sarif_results_file_path):
if standard_rule_id in self.guideline_obligation_level[standard_short_name]:
if not self.guideline_obligation_level[standard_short_name][standard_rule_id] == obligation_level:
print(
f"WARNING: Rule { rule['id'] } specifies a conflicting obligation level of { obligation_level }, was previously specified as { guideline_obligation_level[standard_short_name][standard_rule_id] }.")
f"WARNING: Rule { rule['id'] } specifies a conflicting obligation level of { obligation_level }, was previously specified as { self.guideline_obligation_level[standard_short_name][standard_rule_id] }.")
else:
self.guideline_obligation_level[standard_short_name][standard_rule_id] = obligation_level
# Add deviation counts for the rule
Expand Down
Loading