Skip to content

Commit f220399

Browse files
authored
Merge branch 'main' into knewbury01/A8-4-7-fp
2 parents da45991 + 01f8293 commit f220399

16 files changed

+165
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`:
2+
- Exclude the plain char type. Still includes `signed char` and `unsigned char`.
3+
- Include CV-qualified variable width integer types.
4+
- `A3-9-1` - `VariableWidthPlainCharTypeUsed.ql`:
5+
- New query to support fine grained deviation support for the plain char type.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M9-3-3` - `MemberFunctionConstIfPossible.ql`, `MemberFunctionStaticIfPossible.ql`:
2+
- Fixes #413. Exclude deleted member functions.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`
2+
- Fix FP reported in #372. Exclude compiler generated variables.

cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @id cpp/autosar/variable-width-integer-types-used
33
* @name A3-9-1: Use fixed-width integer types instead of basic, variable-width, integer types
4-
* @description The basic numerical types of char, int, short, long are not supposed to be used. The
5-
* specific-length types from <cstdint> header need be used instead.
4+
* @description The basic numerical types of signed/unsigned char, int, short, long are not supposed
5+
* to be used. The specific-length types from <cstdint> header need be used instead.
66
* @kind problem
77
* @precision very-high
88
* @problem.severity error
@@ -19,15 +19,16 @@ import cpp
1919
import codingstandards.cpp.autosar
2020
import codingstandards.cpp.EncapsulatingFunctions
2121
import codingstandards.cpp.BuiltInNumericTypes
22+
import codingstandards.cpp.Type
2223

23-
from Variable v
24+
from Variable v, Type typeStrippedOfSpecifiers
2425
where
2526
not isExcluded(v, DeclarationsPackage::variableWidthIntegerTypesUsedQuery()) and
27+
typeStrippedOfSpecifiers = stripSpecifiers(v.getType()) and
2628
(
27-
v.getType() instanceof BuiltInIntegerType or
28-
v.getType() instanceof PlainCharType or
29-
v.getType() instanceof UnsignedCharType or
30-
v.getType() instanceof SignedCharType
29+
typeStrippedOfSpecifiers instanceof BuiltInIntegerType or
30+
typeStrippedOfSpecifiers instanceof UnsignedCharType or
31+
typeStrippedOfSpecifiers instanceof SignedCharType
3132
) and
3233
not v instanceof ExcludedVariable
3334
select v, "Variable '" + v.getName() + "' has variable-width type."
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/autosar/variable-width-plain-char-type-used
3+
* @name A3-9-1: Use a fixed-width integer type instead of a char type
4+
* @description The basic numerical type char is not supposed to be used. The specific-length types
5+
* from <cstdint> header need be used instead.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/autosar/id/a3-9-1
10+
* correctness
11+
* security
12+
* maintainability
13+
* external/autosar/allocated-target/implementation
14+
* external/autosar/enforcement/automated
15+
* external/autosar/obligation/required
16+
*/
17+
18+
import cpp
19+
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.Type
21+
22+
from Variable variable
23+
where
24+
not isExcluded(variable, DeclarationsPackage::variableWidthPlainCharTypeUsedQuery()) and
25+
stripSpecifiers(variable.getType()) instanceof PlainCharType
26+
select variable, "Variable '" + variable.getName() + "' has variable-width char type."

cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ where
3636
else cond = " is used for an object"
3737
) and
3838
not exists(LambdaExpression lc | lc.getACapture().getField() = v) and
39-
not v.isFromUninstantiatedTemplate(_)
39+
not v.isFromUninstantiatedTemplate(_) and
40+
not v.isCompilerGenerated()
4041
select v, "Non-constant variable " + v.getName() + cond + " and is not modified."

cpp/autosar/src/rules/M9-3-3/MemberFunctionConstIfPossible.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ where
121121
not f.callsNonConstOwnMember() and
122122
not f.callsNonConstFromMemberVariable() and
123123
not f.isOverride() and
124-
not f.isFinal()
124+
not f.isFinal() and
125+
not f.isDeleted()
125126
select f, "Member function can be declared as const."

cpp/autosar/src/rules/M9-3-3/MemberFunctionStaticIfPossible.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ from NonStaticMemberFunction nonstatic
3939
where
4040
not isExcluded(nonstatic, ConstPackage::memberFunctionStaticIfPossibleQuery()) and
4141
not exists(ThisExpr t | t.getEnclosingFunction() = nonstatic) and
42-
not nonstatic.isVirtual()
42+
not nonstatic.isVirtual() and
43+
not nonstatic.isDeleted()
4344
select nonstatic, "Member function can be declared as static."

cpp/autosar/test/rules/A3-9-1/VariableWidthIntegerTypesUsed.expected

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
| test.cpp:4:8:4:8 | c | Variable 'c' has variable-width type. |
21
| test.cpp:5:17:5:18 | uc | Variable 'uc' has variable-width type. |
32
| test.cpp:6:15:6:16 | sc | Variable 'sc' has variable-width type. |
43
| test.cpp:8:7:8:7 | i | Variable 'i' has variable-width type. |
@@ -12,3 +11,29 @@
1211
| test.cpp:18:8:18:8 | l | Variable 'l' has variable-width type. |
1312
| test.cpp:19:17:19:18 | ul | Variable 'ul' has variable-width type. |
1413
| test.cpp:20:15:20:16 | sl | Variable 'sl' has variable-width type. |
14+
| test.cpp:39:23:39:25 | uc1 | Variable 'uc1' has variable-width type. |
15+
| test.cpp:40:21:40:23 | sc1 | Variable 'sc1' has variable-width type. |
16+
| test.cpp:42:13:42:14 | i1 | Variable 'i1' has variable-width type. |
17+
| test.cpp:43:22:43:24 | ui1 | Variable 'ui1' has variable-width type. |
18+
| test.cpp:44:18:44:19 | u1 | Variable 'u1' has variable-width type. |
19+
| test.cpp:45:20:45:22 | si1 | Variable 'si1' has variable-width type. |
20+
| test.cpp:46:16:46:17 | s1 | Variable 's1' has variable-width type. |
21+
| test.cpp:48:15:48:17 | sh1 | Variable 'sh1' has variable-width type. |
22+
| test.cpp:49:24:49:27 | ush1 | Variable 'ush1' has variable-width type. |
23+
| test.cpp:50:22:50:25 | ssh1 | Variable 'ssh1' has variable-width type. |
24+
| test.cpp:52:14:52:15 | l1 | Variable 'l1' has variable-width type. |
25+
| test.cpp:53:23:53:25 | ul1 | Variable 'ul1' has variable-width type. |
26+
| test.cpp:54:21:54:23 | sl1 | Variable 'sl1' has variable-width type. |
27+
| test.cpp:57:26:57:28 | uc2 | Variable 'uc2' has variable-width type. |
28+
| test.cpp:58:24:58:26 | sc2 | Variable 'sc2' has variable-width type. |
29+
| test.cpp:60:16:60:17 | i2 | Variable 'i2' has variable-width type. |
30+
| test.cpp:61:25:61:27 | ui2 | Variable 'ui2' has variable-width type. |
31+
| test.cpp:62:21:62:22 | u2 | Variable 'u2' has variable-width type. |
32+
| test.cpp:63:23:63:25 | si2 | Variable 'si2' has variable-width type. |
33+
| test.cpp:64:19:64:20 | s2 | Variable 's2' has variable-width type. |
34+
| test.cpp:66:18:66:20 | sh2 | Variable 'sh2' has variable-width type. |
35+
| test.cpp:67:27:67:30 | ush2 | Variable 'ush2' has variable-width type. |
36+
| test.cpp:68:25:68:28 | ssh2 | Variable 'ssh2' has variable-width type. |
37+
| test.cpp:70:17:70:18 | l2 | Variable 'l2' has variable-width type. |
38+
| test.cpp:71:26:71:28 | ul2 | Variable 'ul2' has variable-width type. |
39+
| test.cpp:72:24:72:26 | sl2 | Variable 'sl2' has variable-width type. |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.cpp:4:8:4:8 | c | Variable 'c' has variable-width char type. |
2+
| test.cpp:38:14:38:15 | c1 | Variable 'c1' has variable-width char type. |
3+
| test.cpp:56:17:56:18 | c2 | Variable 'c2' has variable-width char type. |

0 commit comments

Comments
 (0)