Skip to content

Commit 3aaa056

Browse files
authored
Merge branch 'main' into lcartey/update-supported-docs
2 parents dadc62c + 6c8ba57 commit 3aaa056

File tree

131 files changed

+1652
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1652
-483
lines changed

.vscode/tasks.json

+22
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",

c/misra/src/rules/RULE-20-8/ControllingExpressionIfDirective.ql

+6-11
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,35 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17+
import codingstandards.cpp.PreprocessorDirective
1718

1819
/* A controlling expression is evaluated if it is not excluded (guarded by another controlling expression that is not taken). This translates to it either being taken or not taken. */
1920
predicate isEvaluated(PreprocessorBranch b) { b.wasTaken() or b.wasNotTaken() }
2021

21-
class IfOrElifPreprocessorBranch extends PreprocessorBranch {
22-
IfOrElifPreprocessorBranch() {
23-
this instanceof PreprocessorIf or this instanceof PreprocessorElif
24-
}
25-
}
26-
2722
/**
2823
* Looks like it contains a single macro, which may be undefined
2924
*/
30-
class SimpleMacroPreprocessorBranch extends IfOrElifPreprocessorBranch {
25+
class SimpleMacroPreprocessorBranch extends PreprocessorIfOrElif {
3126
SimpleMacroPreprocessorBranch() { this.getHead().regexpMatch("[a-zA-Z_][a-zA-Z0-9_]+") }
3227
}
3328

34-
class SimpleNumericPreprocessorBranch extends IfOrElifPreprocessorBranch {
29+
class SimpleNumericPreprocessorBranch extends PreprocessorIfOrElif {
3530
SimpleNumericPreprocessorBranch() { this.getHead().regexpMatch("[0-9]+") }
3631
}
3732

3833
class ZeroOrOnePreprocessorBranch extends SimpleNumericPreprocessorBranch {
3934
ZeroOrOnePreprocessorBranch() { this.getHead().regexpMatch("[0|1]") }
4035
}
4136

42-
predicate containsOnlySafeOperators(IfOrElifPreprocessorBranch b) {
37+
predicate containsOnlySafeOperators(PreprocessorIfOrElif b) {
4338
containsOnlyDefinedOperator(b)
4439
or
4540
//logic: comparison operators eval last, so they make it safe?
4641
b.getHead().regexpMatch(".*[\\&\\&|\\|\\||>|<|==].*")
4742
}
4843

4944
//all defined operators is definitely safe
50-
predicate containsOnlyDefinedOperator(IfOrElifPreprocessorBranch b) {
45+
predicate containsOnlyDefinedOperator(PreprocessorIfOrElif b) {
5146
forall(string portion |
5247
portion =
5348
b.getHead()
@@ -65,7 +60,7 @@ class BinaryValuedMacro extends Macro {
6560
BinaryValuedMacro() { this.getBody().regexpMatch("\\(?(0|1)\\)?") }
6661
}
6762

68-
from IfOrElifPreprocessorBranch b, string msg
63+
from PreprocessorIfOrElif b, string msg
6964
where
7065
not isExcluded(b, Preprocessor3Package::controllingExpressionIfDirectiveQuery()) and
7166
isEvaluated(b) and
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M8-5-2` - `AggregateLiteralEnhancements.qll`:
2+
- recognise aggregate literals initialized with parameters from variadic templates.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A2-10-1`, `RULE-5-3`:
2+
- Reduce false positives by considering point of declaration for local variables.
3+
- Reduce false negatives by considering catch block parameters to be in scope in the catch block.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `M6-5-5`:
2+
- Reduce false positives by no longer considering the taking of a const reference as a modification.
3+
- Improve detection of non-local modification of loop iteration variables to reduce false positives.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `A7-1-1` - no longer report parameters as contravening this rule. This is inline with the rule intent as described in the referenced C++ Core Guidelines rule [CON.1](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#con1-by-default-make-objects-immutable), which states "To avoid confusion and lots of false positives, don’t enforce this rule for function parameters."
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+
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `M16-1-1` - `DefinedPreProcessorOperatorGeneratedFromExpansionFound.ql`:
2+
- Optimize query to improve performance
3+
- Improve detection of macros whose body contains the `defined` operator after the start of the macro (e.g. `#define X Y || defined(Z)`).
4+
- Enable exclusions to be applied for this rule.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M5-2-10` - `IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql`:
2+
- only report use of the increment and decrement operations in conjunction with arithmetic operators, as specified by the rule. Notably we no longer report the expressions of the form `*p++`, which combine increment and dereferencing operations.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `A4-7-1` - exclude pointer increment and decrement operators from this rule.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* Exceptions are no longer propagated from calls to `noexcept` functions, or calls functions with dynamic exception specifications where the exception is not permitted. This is consistent with the default behaviour specified in `[expect.spec]` which indicates that `std::terminate` is called. This has the following impact:
2+
- `A15-4-2`, `ERR55-CPP` - reduce false positives for `noexcept` functions which call other `noexcept` function which may throw.
3+
- `A15-2-2` - reduce false positives for constructors which call `noexcept` functions.
4+
- `A15-4-5` - reduce false positives for checked exceptions that are thrown from `noexcept` functions called by the original function.
5+
- `DCL57-CPP` - do not report exceptions thrown from `noexcept` functions called by deallocation functions or destructors.
6+
- `A15-5-1`, `M15-3-1` - do not report exceptions thrown from `noexcept` functions called by special functions.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`A8-4-7` - `InParametersForCheapToCopyTypesNotPassedByValue.ql`, `InParametersForNotCheapToCopyTypesNotPassedByReference.ql`:
2+
- Fixes #397. Exclude user defined operators and move constructors.`
3+
- Exclude parameters for instantiated templates because the declaration location of the function does not contain enough information about the type used in the instantiation to make an actionable alert.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A5-0-2` - `NonBooleanIfStmt.qll`, `NonBooleanIterationStmt.qll`:
2+
- Exclude compiler generated conditions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A13-3-1` - `FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql`:
2+
- Fixes #399. Exclude functions that have different number of parameters.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- `A8-4-8` - `OutParametersUsed.ql`
2+
- Fixes #370 - Non-member user-defined assignment operator and stream insertion/extraction parameters that are required to be out parameters are excluded.
3+
- Broadens the definition of out parameter by considering assignment and crement operators as modifications to an out parameter candidate.
4+
- `FIO51-CPP` - `CloseFilesWhenTheyAreNoLongerNeeded.ql`:
5+
- Broadened definition of `IStream` and `OStream` types may result in reduced false negatives.
6+
- `A5-1-1` - `LiteralValueUsedOutsideTypeInit.ql`:
7+
- Broadened definition of `IStream` types may result in reduced false positives because more file stream function calls may be detected as logging operations that will be excluded from the results.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A16-0-1` - `PreProcessorShallOnlyBeUsedForCertainDirectivesPatterns.ql`:
2+
- Exclude all preprocessor elses and also consider elifs separately (ie do not affect valid ifs) but not valid if not meeting the same criteria as an ifdef etc.
+4
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.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`A7-1-2` - `VariableMissingConstexpr.ql`:
2+
- Fix FP reported in #466. Addresses incorrect assumption that calls to `constexpr` functions are always compile-time evaluated.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M9-3-3`: `MemberFunctionConstIfPossible.ql`:
2+
- Fix FP reported in 467. Excluding candidates in uninstantiated templates.
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.
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`:
2+
- Fix issue #7 - improve query logic to only match on exact standard library names (e.g., now excludes sys/header.h type headers from the results as those are not C standard libraries).
+2
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`A15-4-4` - `MissingNoExcept.ql`:
2+
- Fix FP reported in #424. Exclude functions calling `std::string::reserve` or `std::string::append` that may throw even if their signatures don't specify it.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `M0-1-4` - `SingleUseMemberPODVariable.ql`:
2+
- Address FP reported in #388. Include aggregrate initialization as a use of a member.
3+
- Include indirect initialization of members. For example, casting a pointer to a buffer to a struct pointer.
4+
- Reformat the alert message to adhere to the style-guide.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `M0-1-3` - `UnusedMemberVariable.ql`, `UnusedGlobalOrNamespaceVariable.ql`:
2+
- Address FP reported in #384. Exclude variables with compile time values that may have been used as a template argument.
3+
- Exclude uninstantiated template members.
4+
- Reformat the alert message to adhere to the style-guide.

cpp/autosar/src/rules/A13-3-1/FunctionThatContainsForwardingReferenceAsItsArgumentOverloaded.ql

+29-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,36 @@ class Candidate extends TemplateFunction {
2121
}
2222
}
2323

24-
from Candidate c, Function f
24+
from
25+
Candidate c, Function f, Function overload, Function overloaded, string msg,
26+
string firstMsgSegment
2527
where
2628
not isExcluded(f,
2729
OperatorsPackage::functionThatContainsForwardingReferenceAsItsArgumentOverloadedQuery()) and
2830
not f.isDeleted() and
29-
f = c.getAnOverload()
30-
select f, "Function overloads a $@ with a forwarding reference parameter.", c, "function"
31+
f = c.getAnOverload() and
32+
// allow for overloading with different number of parameters, because there is no
33+
// confusion on what function will be called.
34+
f.getNumberOfParameters() = c.getNumberOfParameters() and
35+
//build a dynamic select statement that guarantees to read that the overloading function is the explicit one
36+
if
37+
(f instanceof CopyConstructor or f instanceof MoveConstructor) and
38+
f.isCompilerGenerated()
39+
then (
40+
(
41+
f instanceof CopyConstructor and
42+
msg = "implicit copy constructor"
43+
or
44+
f instanceof MoveConstructor and
45+
msg = "implicit move constructor"
46+
) and
47+
firstMsgSegment = " with a forwarding reference parameter " and
48+
overloaded = f and
49+
overload = c
50+
) else (
51+
msg = "function with a forwarding reference parameter" and
52+
firstMsgSegment = " " and
53+
overloaded = c and
54+
overload = f
55+
)
56+
select overload, "Function" + firstMsgSegment + "overloads a $@.", overloaded, msg

cpp/autosar/src/rules/A16-0-1/PreProcessorShallOnlyBeUsedForCertainDirectivesPatterns.ql

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,26 @@ import cpp
2121
import codingstandards.cpp.autosar
2222
import codingstandards.cpp.FunctionLikeMacro
2323

24+
class PermittedInnerDirectiveType extends PreprocessorDirective {
25+
PermittedInnerDirectiveType() {
26+
//permissive listing for directives that can be used in a valid wrapper
27+
this instanceof MacroWrapper or
28+
this instanceof PreprocessorEndif or
29+
this instanceof Include or
30+
this instanceof PermittedMacro or
31+
this instanceof PreprocessorElif or
32+
this instanceof PreprocessorElse
33+
}
34+
}
35+
2436
class PermittedDirectiveType extends PreprocessorDirective {
2537
PermittedDirectiveType() {
2638
//permissive listing in case directive types modelled in ql ever expands (example non valid directives)
2739
this instanceof MacroWrapper or
2840
this instanceof PreprocessorEndif or
2941
this instanceof Include or
30-
this instanceof PermittedMacro
42+
this instanceof PermittedMacro or
43+
this instanceof PreprocessorElse
3144
}
3245
}
3346

@@ -40,9 +53,9 @@ pragma[noinline]
4053
predicate isPreprocConditionalRange(
4154
PreprocessorBranch pb, string filepath, int startLine, int endLine
4255
) {
43-
exists(PreprocessorEndif end | pb.getEndIf() = end |
44-
isPreprocFileAndLine(pb, filepath, startLine) and
45-
isPreprocFileAndLine(end, filepath, endLine)
56+
isPreprocFileAndLine(pb, filepath, startLine) and
57+
exists(PreprocessorDirective end |
58+
pb.getNext() = end and isPreprocFileAndLine(end, filepath, endLine)
4659
)
4760
}
4861

@@ -73,7 +86,7 @@ class MacroWrapper extends PreprocessorIfndef {
7386
class AcceptableWrapper extends PreprocessorBranch {
7487
AcceptableWrapper() {
7588
forall(Element inner | not inner instanceof Comment and this = getAGuard(inner) |
76-
inner instanceof PermittedDirectiveType
89+
inner instanceof PermittedInnerDirectiveType
7790
)
7891
}
7992
}

cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where
2828
* not use any of 'signal.h's facilities, for example.
2929
*/
3030

31-
filename = i.getIncludedFile().getBaseName() and
31+
filename = i.getIncludeText().substring(1, i.getIncludeText().length() - 1) and
3232
filename in [
3333
"assert.h", "ctype.h", "errno.h", "fenv.h", "float.h", "inttypes.h", "limits.h", "locale.h",
3434
"math.h", "setjmp.h", "signal.h", "stdarg.h", "stddef.h", "stdint.h", "stdio.h", "stdlib.h",

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

+3-1
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

+11-4
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() +

0 commit comments

Comments
 (0)