Skip to content

Commit cfaccb3

Browse files
committed
Re-generate package files with new names and add shared test that was missing
1 parent e682b81 commit cfaccb3

File tree

12 files changed

+128
-55
lines changed

12 files changed

+128
-55
lines changed

cpp/autosar/src/rules/A9-6-2/BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols.ql

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/autosar/bit-fields-should-not-be-declared-autosar-cpp
3+
* @name A9-6-2: Bit-fields shall be used only when interfacing to hardware or conforming to communication protocols
4+
* @description The usage of bit-fields increases code complexity and certain aspects of bit-field
5+
* manipulation can be error prone and implementation defined. Hence a bit-field usage
6+
* is reserved only when interfacing to hardware or conformance to communication
7+
* protocols.
8+
* @kind problem
9+
* @precision very-high
10+
* @problem.severity recommendation
11+
* @tags external/autosar/id/a9-6-2
12+
* maintainability
13+
* external/autosar/allocated-target/design
14+
* external/autosar/enforcement/partially-automated
15+
* external/autosar/obligation/required
16+
*/
17+
18+
import cpp
19+
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.rules.bitfieldsshallbeusedonlywheninterfacingtohardwareorconformingtocommunicationprotocols.BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols
21+
22+
module BitFieldsShouldNotBeDeclaredAutosarCppConfig implements BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig {
23+
Query getQuery() { result = RepresentationPackage::bitFieldsShouldNotBeDeclaredAutosarCppQuery() }
24+
}
25+
26+
import BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols<BitFieldsShouldNotBeDeclaredAutosarCppConfig>

cpp/autosar/test/rules/A9-6-2/BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/autosar/test/rules/A9-6-2/BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/misra/test/rules/RULE-12-2-1/BitFieldsShouldNotBeDeclared.testref renamed to cpp/autosar/test/rules/A9-6-2/BitFieldsShouldNotBeDeclaredAutosarCpp.testref

File renamed without changes.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import cpp
33
import RuleMetadata
44
import codingstandards.cpp.exclusions.RuleMetadata
55

6-
newtype Banned5Query = TBitFieldsShouldNotBeDeclaredQuery()
6+
newtype Banned5Query = TBitFieldsShouldNotBeDeclaredMisraCppQuery()
77

88
predicate isBanned5QueryMetadata(Query query, string queryId, string ruleId, string category) {
99
query =
10-
// `Query` instance for the `bitFieldsShouldNotBeDeclared` query
11-
Banned5Package::bitFieldsShouldNotBeDeclaredQuery() and
10+
// `Query` instance for the `bitFieldsShouldNotBeDeclaredMisraCpp` query
11+
Banned5Package::bitFieldsShouldNotBeDeclaredMisraCppQuery() and
1212
queryId =
13-
// `@id` for the `bitFieldsShouldNotBeDeclared` query
14-
"cpp/misra/bit-fields-should-not-be-declared" and
13+
// `@id` for the `bitFieldsShouldNotBeDeclaredMisraCpp` query
14+
"cpp/misra/bit-fields-should-not-be-declared-misra-cpp" and
1515
ruleId = "RULE-12-2-1" and
1616
category = "advisory"
1717
}
1818

1919
module Banned5Package {
20-
Query bitFieldsShouldNotBeDeclaredQuery() {
20+
Query bitFieldsShouldNotBeDeclaredMisraCppQuery() {
2121
//autogenerate `Query` type
2222
result =
23-
// `Query` type for `bitFieldsShouldNotBeDeclared` query
24-
TQueryCPP(TBanned5PackageQuery(TBitFieldsShouldNotBeDeclaredQuery()))
23+
// `Query` type for `bitFieldsShouldNotBeDeclaredMisraCpp` query
24+
TQueryCPP(TBanned5PackageQuery(TBitFieldsShouldNotBeDeclaredMisraCppQuery()))
2525
}
2626
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import RuleMetadata
44
import codingstandards.cpp.exclusions.RuleMetadata
55

66
newtype RepresentationQuery =
7-
TBitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsQuery() or
7+
TBitFieldsShouldNotBeDeclaredAutosarCppQuery() or
88
TAuditPossibleHardwareInterfaceDueToBitFieldUsageInDataTypeDefinitionQuery() or
99
TObjectAssignedToAnOverlappingObjectAutosarCppQuery() or
1010
TDoNotPassAliasedPointerToParamQuery() or
@@ -16,11 +16,11 @@ newtype RepresentationQuery =
1616

1717
predicate isRepresentationQueryMetadata(Query query, string queryId, string ruleId, string category) {
1818
query =
19-
// `Query` instance for the `bitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols` query
20-
RepresentationPackage::bitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsQuery() and
19+
// `Query` instance for the `bitFieldsShouldNotBeDeclaredAutosarCpp` query
20+
RepresentationPackage::bitFieldsShouldNotBeDeclaredAutosarCppQuery() and
2121
queryId =
22-
// `@id` for the `bitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols` query
23-
"cpp/autosar/bit-fields-shall-be-used-only-when-interfacing-to-hardware-or-conforming-to-communication-protocols" and
22+
// `@id` for the `bitFieldsShouldNotBeDeclaredAutosarCpp` query
23+
"cpp/autosar/bit-fields-should-not-be-declared-autosar-cpp" and
2424
ruleId = "A9-6-2" and
2525
category = "required"
2626
or
@@ -98,11 +98,11 @@ predicate isRepresentationQueryMetadata(Query query, string queryId, string rule
9898
}
9999

100100
module RepresentationPackage {
101-
Query bitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsQuery() {
101+
Query bitFieldsShouldNotBeDeclaredAutosarCppQuery() {
102102
//autogenerate `Query` type
103103
result =
104-
// `Query` type for `bitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols` query
105-
TQueryCPP(TRepresentationPackageQuery(TBitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsQuery()))
104+
// `Query` type for `bitFieldsShouldNotBeDeclaredAutosarCpp` query
105+
TQueryCPP(TRepresentationPackageQuery(TBitFieldsShouldNotBeDeclaredAutosarCppQuery()))
106106
}
107107

108108
Query auditPossibleHardwareInterfaceDueToBitFieldUsageInDataTypeDefinitionQuery() {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
typedef int MYINT;
2+
3+
/**
4+
* @HardwareOrProtocolInterface
5+
*/
6+
class HW_A {};
7+
8+
/**
9+
* @HardwareOrProtocolInterface
10+
*/
11+
class HW_A1 : HW_A {
12+
public:
13+
int a1;
14+
int a2;
15+
};
16+
17+
/**
18+
* @HardwareOrProtocolInterface
19+
*/
20+
class HW_A2 : HW_A {
21+
public:
22+
int a1 : 2; // NON_COMPLIANT
23+
int a2;
24+
};
25+
26+
/**
27+
* @HardwareOrProtocolInterface
28+
*/
29+
class HW_B {};
30+
31+
class B {};
32+
33+
/**
34+
* @HardwareOrProtocolInterface
35+
*/
36+
class HW_B1 : HW_B {
37+
public:
38+
int a;
39+
};
40+
41+
/**
42+
* @HardwareOrProtocolInterface
43+
*/
44+
class HW_B2 : HW_B {
45+
public:
46+
int a1;
47+
MYINT a2 : 2; // NON_COMPLIANT
48+
49+
char b1;
50+
char c1 : 2; // NON_COMPLIANT
51+
};
52+
53+
class B2 : B {
54+
public:
55+
int a;
56+
char b;
57+
char c : 2; // NON_COMPLIANT
58+
};
59+
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-misra-cpp
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 BitFieldsShouldNotBeDeclaredMisraCppConfig implements BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocolsConfigSig {
21+
Query getQuery() { result = Banned5Package::bitFieldsShouldNotBeDeclaredMisraCppQuery() }
22+
}
23+
24+
import BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols<BitFieldsShouldNotBeDeclaredMisraCppConfig>
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

0 commit comments

Comments
 (0)