Skip to content

Commit cd095be

Browse files
committed
Add Banned5
1 parent 6fda6fa commit cd095be

File tree

11 files changed

+112
-2
lines changed

11 files changed

+112
-2
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 Banned5Query = TBitFieldsShouldNotBeDeclaredQuery()
7+
8+
predicate isBanned5QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `bitFieldsShouldNotBeDeclared` query
11+
Banned5Package::bitFieldsShouldNotBeDeclaredQuery() and
12+
queryId =
13+
// `@id` for the `bitFieldsShouldNotBeDeclared` query
14+
"cpp/misra/bit-fields-should-not-be-declared" and
15+
ruleId = "RULE-12-2-1" and
16+
category = "advisory"
17+
}
18+
19+
module Banned5Package {
20+
Query bitFieldsShouldNotBeDeclaredQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `bitFieldsShouldNotBeDeclared` query
24+
TQueryCPP(TBanned5PackageQuery(TBitFieldsShouldNotBeDeclaredQuery()))
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
@@ -4,6 +4,7 @@ import codingstandards.cpp.exclusions.RuleMetadata
44
//** Import packages for this language **/
55
import Allocations
66
import Banned1
7+
import Banned5
78
import Banned8
89
import BannedAPIs
910
import BannedFunctions
@@ -96,6 +97,7 @@ import VirtualFunctions
9697
newtype TCPPQuery =
9798
TAllocationsPackageQuery(AllocationsQuery q) or
9899
TBanned1PackageQuery(Banned1Query q) or
100+
TBanned5PackageQuery(Banned5Query q) or
99101
TBanned8PackageQuery(Banned8Query q) or
100102
TBannedAPIsPackageQuery(BannedAPIsQuery q) or
101103
TBannedFunctionsPackageQuery(BannedFunctionsQuery q) or
@@ -188,6 +190,7 @@ newtype TCPPQuery =
188190
predicate isQueryMetadata(Query query, string queryId, string ruleId, string category) {
189191
isAllocationsQueryMetadata(query, queryId, ruleId, category) or
190192
isBanned1QueryMetadata(query, queryId, ruleId, category) or
193+
isBanned5QueryMetadata(query, queryId, ruleId, category) or
191194
isBanned8QueryMetadata(query, queryId, ruleId, category) or
192195
isBannedAPIsQueryMetadata(query, queryId, ruleId, category) or
193196
isBannedFunctionsQueryMetadata(query, queryId, ruleId, category) or
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Provides a configurable module BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols with a `problems` predicate
3+
* for the following issue:
4+
* The exact layout and the order of bits resulting from bit-fields in a struct is
5+
* implementation-defined and therefore not portable.
6+
*/
7+
8+
import cpp
9+
import codingstandards.cpp.Customizations
10+
import codingstandards.cpp.Exclusions
11+
12+
signature module BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig {
13+
Query getQuery();
14+
}
15+
16+
module BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols<BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig Config> {
17+
query predicate problems(Element e, string message) {
18+
not isExcluded(e, Config::getQuery()) and message = "<replace with problem alert message for >"
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.bitfieldsshallbeusedonlywheninterfacingtohardwareorconformingtocommunicationprotocols.BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols
3+
4+
module TestFileConfig implements BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig {
5+
Query getQuery() { result instanceof TestQuery }
6+
}
7+
8+
import BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols<TestFileConfig>

cpp/common/test/rules/bitfieldsshallbeusedonlywheninterfacingtohardwareorconformingtocommunicationprotocols/test.cpp

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/bit-fields-should-not-be-declared
3+
* @name RULE-12-2-1: Bit-fields should not be declared
4+
* @description The exact layout and the order of bits resulting from bit-fields in a struct is
5+
* implementation-defined and therefore not portable.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-12-2-1
10+
* scope/single-translation-unit
11+
* correctness
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/advisory
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.bitfieldsshallbeusedonlywheninterfacingtohardwareorconformingtocommunicationprotocols.BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols
19+
20+
module BitFieldsShouldNotBeDeclaredConfig implements BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig {
21+
Query getQuery() { result = Banned5Package::bitFieldsShouldNotBeDeclaredQuery() }
22+
}
23+
24+
import BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols<BitFieldsShouldNotBeDeclaredConfig>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/bitfieldsshallbeusedonlywheninterfacingtohardwareorconformingtocommunicationprotocols/BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols.ql

rule_packages/cpp/Banned5.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-12-2-1": {
4+
"properties": {
5+
"enforcement": "decidable",
6+
"obligation": "advisory"
7+
},
8+
"queries": [
9+
{
10+
"description": "The exact layout and the order of bits resulting from bit-fields in a struct is implementation-defined and therefore not portable.",
11+
"kind": "problem",
12+
"name": "Bit-fields should not be declared",
13+
"precision": "very-high",
14+
"severity": "error",
15+
"short_name": "BitFieldsShouldNotBeDeclared",
16+
"shared_implementation_short_name": "BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols",
17+
"tags": [
18+
"scope/single-translation-unit",
19+
"correctness"
20+
]
21+
}
22+
],
23+
"title": "Bit-fields should not be declared"
24+
}
25+
}
26+
}

rule_packages/cpp/Representation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"name": "Bit-fields shall be used only when interfacing to hardware or conforming to communication protocols",
1616
"precision": "very-high",
1717
"severity": "recommendation",
18-
"short_name": "BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols",
18+
"short_name": "BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsAutosarCpp",
19+
"shared_implementation_short_name": "BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols",
1920
"tags": [
2021
"maintainability"
2122
]

0 commit comments

Comments
 (0)