Skip to content

Commit e32ee19

Browse files
committed
Implement RULE-6-0-2 by converting to (improved) shared rule with A3-1-4
1 parent fb766ef commit e32ee19

19 files changed

+226
-58
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A3-1-4` - `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql`:
2+
- `ExternalLinkageArrayWithoutExplicitSize.ql` has been renamed to `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql` to reflect shared query implementation. Additionally the query previously only detected explicit uses of `extern` to determine external linkage, and now would catch other cases that are possible where it is external linkage and an array is declared without an explicit size.

cpp/autosar/src/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.ql

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/autosar/external-linkage-array-without-explicit-size-autosar
3+
* @name A3-1-4: When an array with external linkage is declared, its size shall be stated explicitly
4+
* @description A developer can more safely access the elements of an array if the size of the array
5+
* can be explicitly determined.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/autosar/id/a3-1-4
10+
* correctness
11+
* external/autosar/allocated-target/design
12+
* external/autosar/allocated-target/implementation
13+
* external/autosar/enforcement/automated
14+
* external/autosar/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.autosar
19+
import codingstandards.cpp.rules.externallinkagearraywithoutexplicitsize.ExternalLinkageArrayWithoutExplicitSize
20+
21+
class ExternalLinkageArrayWithoutExplicitSizeAutosarQuery extends ExternalLinkageArrayWithoutExplicitSizeSharedQuery {
22+
ExternalLinkageArrayWithoutExplicitSizeAutosarQuery() {
23+
this = ScopePackage::externalLinkageArrayWithoutExplicitSizeAutosarQuery()
24+
}
25+
}

cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.expected

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

cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.ql

cpp/autosar/test/rules/A3-1-4/test.cpp

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Linkage1Query =
7+
TArrayExternalLinkageSizeExplicitQuery() or
8+
TExternalLinkageArrayWithoutExplicitSizeMisraQuery()
9+
10+
predicate isLinkage1QueryMetadata(Query query, string queryId, string ruleId, string category) {
11+
query =
12+
// `Query` instance for the `arrayExternalLinkageSizeExplicit` query
13+
Linkage1Package::arrayExternalLinkageSizeExplicitQuery() and
14+
queryId =
15+
// `@id` for the `arrayExternalLinkageSizeExplicit` query
16+
"cpp/misra/array-external-linkage-size-explicit" and
17+
ruleId = "RULE-6-0-2" and
18+
category = "advisory"
19+
or
20+
query =
21+
// `Query` instance for the `externalLinkageArrayWithoutExplicitSizeMisra` query
22+
Linkage1Package::externalLinkageArrayWithoutExplicitSizeMisraQuery() and
23+
queryId =
24+
// `@id` for the `externalLinkageArrayWithoutExplicitSizeMisra` query
25+
"cpp/misra/external-linkage-array-without-explicit-size-misra" and
26+
ruleId = "RULE-6-5-1" and
27+
category = "advisory"
28+
}
29+
30+
module Linkage1Package {
31+
Query arrayExternalLinkageSizeExplicitQuery() {
32+
//autogenerate `Query` type
33+
result =
34+
// `Query` type for `arrayExternalLinkageSizeExplicit` query
35+
TQueryCPP(TLinkage1PackageQuery(TArrayExternalLinkageSizeExplicitQuery()))
36+
}
37+
38+
Query externalLinkageArrayWithoutExplicitSizeMisraQuery() {
39+
//autogenerate `Query` type
40+
result =
41+
// `Query` type for `externalLinkageArrayWithoutExplicitSizeMisra` query
42+
TQueryCPP(TLinkage1PackageQuery(TExternalLinkageArrayWithoutExplicitSizeMisraQuery()))
43+
}
44+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import IntegerConversion
3434
import Invariants
3535
import Iterators
3636
import Lambdas
37+
import Linkage1
3738
import Literals
3839
import Loops
3940
import Macros
@@ -96,6 +97,7 @@ newtype TCPPQuery =
9697
TInvariantsPackageQuery(InvariantsQuery q) or
9798
TIteratorsPackageQuery(IteratorsQuery q) or
9899
TLambdasPackageQuery(LambdasQuery q) or
100+
TLinkage1PackageQuery(Linkage1Query q) or
99101
TLiteralsPackageQuery(LiteralsQuery q) or
100102
TLoopsPackageQuery(LoopsQuery q) or
101103
TMacrosPackageQuery(MacrosQuery q) or
@@ -158,6 +160,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
158160
isInvariantsQueryMetadata(query, queryId, ruleId, category) or
159161
isIteratorsQueryMetadata(query, queryId, ruleId, category) or
160162
isLambdasQueryMetadata(query, queryId, ruleId, category) or
163+
isLinkage1QueryMetadata(query, queryId, ruleId, category) or
161164
isLiteralsQueryMetadata(query, queryId, ruleId, category) or
162165
isLoopsQueryMetadata(query, queryId, ruleId, category) or
163166
isMacrosQueryMetadata(query, queryId, ruleId, category) or

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

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

66
newtype ScopeQuery =
77
TNonStandardEntitiesInStandardNamespacesQuery() or
8-
TExternalLinkageArrayWithoutExplicitSizeQuery() or
8+
TExternalLinkageArrayWithoutExplicitSizeAutosarQuery() or
99
THiddenInheritedNonOverridableMemberFunctionQuery() or
1010
THiddenInheritedOverridableMemberFunctionQuery() or
1111
TDefinitionNotConsideredForUnqualifiedLookupQuery() or
@@ -33,11 +33,11 @@ predicate isScopeQueryMetadata(Query query, string queryId, string ruleId, strin
3333
category = "required"
3434
or
3535
query =
36-
// `Query` instance for the `externalLinkageArrayWithoutExplicitSize` query
37-
ScopePackage::externalLinkageArrayWithoutExplicitSizeQuery() and
36+
// `Query` instance for the `externalLinkageArrayWithoutExplicitSizeAutosar` query
37+
ScopePackage::externalLinkageArrayWithoutExplicitSizeAutosarQuery() and
3838
queryId =
39-
// `@id` for the `externalLinkageArrayWithoutExplicitSize` query
40-
"cpp/autosar/external-linkage-array-without-explicit-size" and
39+
// `@id` for the `externalLinkageArrayWithoutExplicitSizeAutosar` query
40+
"cpp/autosar/external-linkage-array-without-explicit-size-autosar" and
4141
ruleId = "A3-1-4" and
4242
category = "required"
4343
or
@@ -185,11 +185,11 @@ module ScopePackage {
185185
TQueryCPP(TScopePackageQuery(TNonStandardEntitiesInStandardNamespacesQuery()))
186186
}
187187

188-
Query externalLinkageArrayWithoutExplicitSizeQuery() {
188+
Query externalLinkageArrayWithoutExplicitSizeAutosarQuery() {
189189
//autogenerate `Query` type
190190
result =
191-
// `Query` type for `externalLinkageArrayWithoutExplicitSize` query
192-
TQueryCPP(TScopePackageQuery(TExternalLinkageArrayWithoutExplicitSizeQuery()))
191+
// `Query` type for `externalLinkageArrayWithoutExplicitSizeAutosar` query
192+
TQueryCPP(TScopePackageQuery(TExternalLinkageArrayWithoutExplicitSizeAutosarQuery()))
193193
}
194194

195195
Query hiddenInheritedNonOverridableMemberFunctionQuery() {

0 commit comments

Comments
 (0)