Skip to content

Commit 1d5a2a8

Browse files
authored
Merge branch 'main' into rvermeulen/fix-424
2 parents b3ff452 + 5e6a5b8 commit 1d5a2a8

28 files changed

+402
-170
lines changed

.vscode/tasks.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@
140140
},
141141
"problemMatcher": []
142142
},
143+
{
144+
"label": "🧪 Standards Automation: Build Case Test DB from test file",
145+
"type": "shell",
146+
"windows": {
147+
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}Scripts${pathSeparator}python.exe scripts${pathSeparator}build_test_database.py ${file}"
148+
},
149+
"linux": {
150+
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}bin${pathSeparator}python3 scripts${pathSeparator}build_test_database.py ${file}"
151+
},
152+
"osx": {
153+
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}bin${pathSeparator}python3 scripts${pathSeparator}build_test_database.py ${file}"
154+
},
155+
"presentation": {
156+
"reveal": "always",
157+
"panel": "new",
158+
"focus": true
159+
},
160+
"runOptions": {
161+
"reevaluateOnRerun": false
162+
},
163+
"problemMatcher": []
164+
},
143165
{
144166
"label": "📝 Standards Automation: Format CodeQL",
145167
"type": "shell",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `A2-7-3` - `UndocumentedUserDefinedType.ql`:
2+
- Excluding declarations in function scope. The rationale is that these declarations are not exposed outside the scope of the function.
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M5-3-3` - `UnaryOperatorOverloaded.ql`:
2+
- Exclude binary user defined `operator&` from this rule.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A4-7-1`: `IntegerExpressionLeadToDataLoss.ql`
2+
- Fix #368: Incorrectly reporting `/=` as a cause for data loss.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`A4-5-1`: `EnumUsedInArithmeticContexts.ql`:
2+
- Address incorrect exclusion of the binary operator `&`.
3+
- Address incorrect inclusion of the unary operator `&`.
4+
- Fix FP reported in #366.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-10-4` - `IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql`:
2+
- Fix FP reported in #385. Addresses incorrect detection of partially specialized template variables as conflicting reuses.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `M7-3-6` - `UsingDeclarationsUsedInHeaderFiles.ql`:
2+
- Address FN reported in #400. Only using-declarations are exempted from class- and function-scope.

cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class CandidateVariable extends Variable {
2020
CandidateVariable() {
2121
hasDefinition() and
2222
isStatic() and
23-
not this instanceof MemberVariable
23+
not this instanceof MemberVariable and
24+
//exclude partially specialized template variables
25+
not exists(TemplateVariable v | this = v.getAnInstantiation())
2426
}
2527
}
2628

cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
import cpp
1818
import codingstandards.cpp.autosar
1919

20+
private predicate isInFunctionScope(Declaration d) {
21+
// Type declared in function
22+
exists(d.(UserType).getEnclosingFunction())
23+
or
24+
// Member declared in type which is in function scope
25+
isInFunctionScope(d.getDeclaringType())
26+
}
27+
2028
/**
2129
* A declaration which is required to be preceded by documentation by AUTOSAR A2-7-3.
2230
*/
@@ -42,10 +50,8 @@ class DocumentableDeclaration extends Declaration {
4250
declarationType = "member variable" and
4351
// Exclude memeber variables in instantiated templates, which cannot reasonably be documented.
4452
not this.(MemberVariable).isFromTemplateInstantiation(_) and
45-
// Exclude anonymous lambda functions.
46-
// TODO: replace with the following when support is added.
47-
// not this.(MemberVariable).isCompilerGenerated()
48-
not exists(LambdaExpression lc | lc.getACapture().getField() = this)
53+
// Exclude compiler generated variables, such as those for anonymous lambda functions
54+
not this.(MemberVariable).isCompilerGenerated()
4955
}
5056

5157
/** Gets a `DeclarationEntry` for this declaration that should be documented. */
@@ -96,6 +102,7 @@ from DocumentableDeclaration d, DeclarationEntry de
96102
where
97103
not isExcluded(de, CommentsPackage::undocumentedUserDefinedTypeQuery()) and
98104
not isExcluded(d, CommentsPackage::undocumentedUserDefinedTypeQuery()) and
105+
not isInFunctionScope(d) and
99106
d.getAnUndocumentedDeclarationEntry() = de
100107
select de,
101108
"Declaration entry for " + d.getDeclarationType() + " " + d.getName() +

cpp/autosar/src/rules/A4-5-1/EnumUsedInArithmeticContexts.ql

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,26 @@
1818

1919
import cpp
2020
import codingstandards.cpp.autosar
21+
import codingstandards.cpp.Operator
22+
import codingstandards.cpp.Type
2123

22-
/*
23-
* Get an operand to all overloaded operator member functions, except:
24-
* operator[]
25-
* operator=
26-
* operator==
27-
* operator!=
28-
* operator&
29-
* operator<
30-
* operator<=
31-
* operator>
32-
* operator>=
33-
*/
34-
35-
Expr getAnOperandOfAllowedOverloadedOperator(FunctionCall fc) {
36-
fc.getAnArgument() = result and
37-
fc.getTarget().getName().regexpMatch("operator(?!\\[]$|=$|==$|!=$|&$|<$|<=$|>$|>=$).+")
38-
}
39-
40-
Expr getAnOperandOfAllowedOperation(Operation o) {
41-
o.getAnOperand() = result and
42-
not (
43-
o instanceof AssignExpr or
44-
o instanceof BitwiseAndExpr or
45-
o instanceof ComparisonOperation
46-
)
24+
class AllowedOperatorUse extends OperatorUse {
25+
AllowedOperatorUse() {
26+
this.getOperator() in ["[]", "=", "==", "!=", "<", "<=", ">", ">="]
27+
or
28+
this.(UnaryOperatorUse).getOperator() = "&"
29+
}
4730
}
4831

49-
from Expr e, Expr operand
32+
from OperatorUse operatorUse, Access access, Enum enum
5033
where
51-
not isExcluded(e, ExpressionsPackage::enumUsedInArithmeticContextsQuery()) and
34+
not isExcluded(access, ExpressionsPackage::enumUsedInArithmeticContextsQuery()) and
35+
operatorUse.getAnOperand() = access and
5236
(
53-
operand = getAnOperandOfAllowedOverloadedOperator(e)
54-
or
55-
operand = getAnOperandOfAllowedOperation(e)
37+
access.(EnumConstantAccess).getTarget().getDeclaringEnum() = enum or
38+
access.(VariableAccess).getType() = enum
5639
) and
57-
(
58-
operand instanceof EnumConstantAccess or
59-
operand.(VariableAccess).getType() instanceof Enum
60-
)
61-
select e, "Enum $@ is used as an operand of arithmetic operation.", operand, "expression"
40+
not operatorUse instanceof AllowedOperatorUse and
41+
// Enums that implement the BitmaskType trait are an exception.
42+
not enum instanceof BitmaskType
43+
select access, "Enum $@ is used as an operand of arithmetic operation.", enum, enum.getName()

cpp/autosar/src/rules/A4-7-1/IntegerExpressionLeadToDataLoss.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ where
3030
not e instanceof MulExpr and
3131
// Not covered by this query - overflow/underflow in division is rare
3232
not e instanceof DivExpr and
33-
not e instanceof RemExpr
33+
not e instanceof AssignDivExpr and
34+
not e instanceof RemExpr and
35+
not e instanceof AssignRemExpr
3436
select e, "Binary expression ..." + e.getOperator() + "... may overflow."

cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18-
import cpp
19-
import codingstandards.cpp.autosar
2018

2119
from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
2220
where

cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
import cpp
1515
import codingstandards.cpp.autosar
16+
import codingstandards.cpp.Operator
1617

17-
from Operator o
18-
where not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery()) and o.hasName("operator&")
18+
from UnaryAddressOfOperator o
19+
where not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery())
1920
select o, "The unary & operator overloaded."

cpp/autosar/src/rules/M7-3-6/UsingDeclarationsUsedInHeaderFiles.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ predicate isInClassScope(UsingEntry u) { exists(Class c | u.getEnclosingElement(
2828
from UsingEntry u
2929
where
3030
not isExcluded(u, BannedSyntaxPackage::usingDeclarationsUsedInHeaderFilesQuery()) and
31-
(isInHeaderFile(u) and not isInFunctionScope(u) and not isInClassScope(u))
31+
isInHeaderFile(u) and
32+
(
33+
u instanceof UsingDeclarationEntry
34+
implies
35+
(
36+
not isInFunctionScope(u) and
37+
not isInClassScope(u)
38+
)
39+
)
3240
select u, "Using directive or declaration used in a header file " + u.getFile() + "."

cpp/autosar/test/rules/A2-10-4/test1a.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ namespace ns3 {
1313
static void f1() {}
1414

1515
void f2() {}
16+
17+
// Variable templates can cause false positives
18+
template <int x> static int number_one = 0; // COMPLIANT
19+
20+
template <> static int number_one<1> = 1; // COMPLIANT
21+
template <> static int number_one<2> = 2; // COMPLIANT
1622
} // namespace ns3

cpp/autosar/test/rules/A2-7-3/test.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,19 @@ template <typename T> class A2_7_3 final {
160160
const std::string kBar{"bar"}; // NON_COMPLIANT
161161
};
162162
/// @brief This is the instantiateA2_7_3 documentation
163-
void instantiateA2_7_3() { A2_7_3<int> instance; }
163+
void instantiateA2_7_3() { A2_7_3<int> instance; }
164+
165+
/// Test documentation
166+
void testFunctionScope() {
167+
using my_float = float;
168+
class ClassF { // COMPLIANT - in function scope
169+
public:
170+
int m_x; // COMPLIANT - in function scope
171+
void fTest(); // COMPLIANT - in function scope
172+
class ClassFNested {
173+
public:
174+
int m_nested_x; // COMPLIANT - in function scope
175+
void fNestedTest(); // COMPLIANT - in function scope
176+
};
177+
};
178+
}

0 commit comments

Comments
 (0)