From f88964c3f44c724c0691d1d2bc4b834d5b14aad5 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 7 Dec 2023 10:07:45 +0000 Subject: [PATCH 1/5] Remove uses of isExcluded/1. --- .../A18-5-11/OperatorNewAndOperatorDeleteNotDefinedLocally.ql | 3 ++- .../A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql | 4 ++-- ...NonConstRawPointersOrReferencesToPrivateOrProtectedData.ql | 3 ++- cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql | 2 +- cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql | 2 +- .../M3-2-1/DeclarationsOfAFunctionShallHaveCompatibleTypes.ql | 2 +- cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql | 2 +- .../src/rules/M3-9-1/TypesNotIdenticalInObjectDeclarations.ql | 2 +- .../src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql | 2 +- .../M4-5-3/CharUsedAsOperandsToDisallowedBuiltInOperators.ql | 2 +- cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql | 2 +- ...ndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql | 3 ++- 12 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cpp/autosar/src/rules/A18-5-11/OperatorNewAndOperatorDeleteNotDefinedLocally.ql b/cpp/autosar/src/rules/A18-5-11/OperatorNewAndOperatorDeleteNotDefinedLocally.ql index 485837073a..5d4cd71c79 100644 --- a/cpp/autosar/src/rules/A18-5-11/OperatorNewAndOperatorDeleteNotDefinedLocally.ql +++ b/cpp/autosar/src/rules/A18-5-11/OperatorNewAndOperatorDeleteNotDefinedLocally.ql @@ -19,7 +19,8 @@ import codingstandards.cpp.autosar from MemberFunction operator_new, Class c where - not isExcluded(operator_new) and + not isExcluded(operator_new, + DeclarationsPackage::operatorNewAndOperatorDeleteNotDefinedLocallyQuery()) and not isExcluded(c, DeclarationsPackage::operatorNewAndOperatorDeleteNotDefinedLocallyQuery()) and operator_new.hasName("operator new") and operator_new.getDeclaringType() = c and diff --git a/cpp/autosar/src/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql b/cpp/autosar/src/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql index 5a45cbc9d6..d67058868c 100644 --- a/cpp/autosar/src/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql +++ b/cpp/autosar/src/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql @@ -40,8 +40,8 @@ import codingstandards.cpp.Iterators from ConstIteratorVariable v, STLContainer c, Expr e where - not isExcluded(v) and - not isExcluded(e) and + not isExcluded(v, IteratorsPackage::iteratorImplicitlyConvertedToConstIteratorQuery()) and + not isExcluded(e, IteratorsPackage::iteratorImplicitlyConvertedToConstIteratorQuery()) and e = v.getAnAssignedValue() and e.getAChild*() = /* see note at top of query */ c.getANonConstIteratorFunctionCall() select e, "Non-const version of container call immediately converted to a `const_iterator`." diff --git a/cpp/autosar/src/rules/A9-3-1/ReturnsNonConstRawPointersOrReferencesToPrivateOrProtectedData.ql b/cpp/autosar/src/rules/A9-3-1/ReturnsNonConstRawPointersOrReferencesToPrivateOrProtectedData.ql index dfa402bd1e..f40faad3dd 100644 --- a/cpp/autosar/src/rules/A9-3-1/ReturnsNonConstRawPointersOrReferencesToPrivateOrProtectedData.ql +++ b/cpp/autosar/src/rules/A9-3-1/ReturnsNonConstRawPointersOrReferencesToPrivateOrProtectedData.ql @@ -57,7 +57,8 @@ class AccessAwareMemberFunction extends MemberFunction { from Class c, AccessAwareMemberFunction mf, FieldAccess a, ReturnStmt rs where - not isExcluded(c) and + not isExcluded(c, + ClassesPackage::returnsNonConstRawPointersOrReferencesToPrivateOrProtectedDataQuery()) and not isExcluded(mf, ClassesPackage::returnsNonConstRawPointersOrReferencesToPrivateOrProtectedDataQuery()) and // Find all of the methods within this class diff --git a/cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql b/cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql index d8a5c07d95..645e05c920 100644 --- a/cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql +++ b/cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql @@ -158,6 +158,6 @@ predicate hasInfeasiblePath( from ConditionalControlFlowNode cond, boolean infeasiblePath, string explanation where - not isExcluded(cond) and + not isExcluded(cond, DeadCodePackage::infeasiblePathQuery()) and hasInfeasiblePath(cond, infeasiblePath, explanation) select cond, "The " + infeasiblePath + " path is infeasible because " + explanation + "." diff --git a/cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql b/cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql index 5cfc679596..87d9af147b 100644 --- a/cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql +++ b/cpp/autosar/src/rules/M3-1-2/FunctionsDeclaredAtBlockScope.ql @@ -20,7 +20,7 @@ import codingstandards.cpp.autosar from DeclStmt decl, Function f where - not isExcluded(decl) and + not isExcluded(decl, DeclarationsPackage::functionsDeclaredAtBlockScopeQuery()) and not isExcluded(f, DeclarationsPackage::functionsDeclaredAtBlockScopeQuery()) and decl.getADeclaration() = f select f, "Function " + f.getName() + " is declared at block scope." diff --git a/cpp/autosar/src/rules/M3-2-1/DeclarationsOfAFunctionShallHaveCompatibleTypes.ql b/cpp/autosar/src/rules/M3-2-1/DeclarationsOfAFunctionShallHaveCompatibleTypes.ql index 2aa8535a35..68e948e0ce 100644 --- a/cpp/autosar/src/rules/M3-2-1/DeclarationsOfAFunctionShallHaveCompatibleTypes.ql +++ b/cpp/autosar/src/rules/M3-2-1/DeclarationsOfAFunctionShallHaveCompatibleTypes.ql @@ -22,7 +22,7 @@ import codingstandards.cpp.Typehelpers from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2 where - not isExcluded(f1) and + not isExcluded(f1, DeclarationsPackage::declarationsOfAFunctionShallHaveCompatibleTypesQuery()) and not isExcluded(f2, DeclarationsPackage::declarationsOfAFunctionShallHaveCompatibleTypesQuery()) and not f1 = f2 and f1.getDeclaration() = f2.getDeclaration() and diff --git a/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql b/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql index 3af15858ca..30d94facb1 100644 --- a/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql +++ b/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql @@ -20,7 +20,7 @@ import codingstandards.cpp.Scope from DeclarationEntry de, DeclarationEntry otherDeclaration, string kind where - not isExcluded(de) and + not isExcluded(de, ScopePackage::multipleDeclarationViolationQuery()) and exists(Declaration d | de.getDeclaration() = d and otherDeclaration.getDeclaration() = d and diff --git a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInObjectDeclarations.ql b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInObjectDeclarations.ql index 7fa5f6078d..7e27160690 100644 --- a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInObjectDeclarations.ql +++ b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInObjectDeclarations.ql @@ -18,7 +18,7 @@ import codingstandards.cpp.autosar from VariableDeclarationEntry decl1, VariableDeclarationEntry decl2 where - not isExcluded(decl1) and + not isExcluded(decl1, DeclarationsPackage::typesNotIdenticalInObjectDeclarationsQuery()) and not isExcluded(decl2, DeclarationsPackage::typesNotIdenticalInObjectDeclarationsQuery()) and decl1.getDeclaration() = decl2.getDeclaration() and not decl1.getType() = decl2.getType() diff --git a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql index b99c656692..1d691ba76a 100644 --- a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql +++ b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql @@ -20,7 +20,7 @@ import codingstandards.cpp.autosar from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2 where - not isExcluded(f1) and + not isExcluded(f1, DeclarationsPackage::typesNotIdenticalInReturnDeclarationsQuery()) and not isExcluded(f2, DeclarationsPackage::typesNotIdenticalInReturnDeclarationsQuery()) and f1.getDeclaration() = f2.getDeclaration() and not f1.getType() = f2.getType() diff --git a/cpp/autosar/src/rules/M4-5-3/CharUsedAsOperandsToDisallowedBuiltInOperators.ql b/cpp/autosar/src/rules/M4-5-3/CharUsedAsOperandsToDisallowedBuiltInOperators.ql index 7df022ba37..100d9f5d76 100644 --- a/cpp/autosar/src/rules/M4-5-3/CharUsedAsOperandsToDisallowedBuiltInOperators.ql +++ b/cpp/autosar/src/rules/M4-5-3/CharUsedAsOperandsToDisallowedBuiltInOperators.ql @@ -22,7 +22,7 @@ import codingstandards.cpp.autosar from Operation o where - not isExcluded(o) and + not isExcluded(o, ExpressionsPackage::charUsedAsOperandsToDisallowedBuiltInOperatorsQuery()) and not ( o instanceof EqualityOperation or o instanceof BitwiseAndExpr or diff --git a/cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql b/cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql index 1cb823fc5b..41d3eb6944 100644 --- a/cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql +++ b/cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql @@ -84,7 +84,7 @@ predicate isGratuitousUseOfParentheses(ParenthesisExpr pe) { from ParenthesisExpr p where - not isExcluded(p) and + not isExcluded(p, OrderOfEvaluationPackage::gratuitousUseOfParenthesesQuery()) and isGratuitousUseOfParentheses(p) and not p.isInMacroExpansion() select p, "Gratuitous use of parentheses around $@.", p.getExpr(), p.getExpr().toString() diff --git a/cpp/autosar/src/rules/M5-2-10/IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql b/cpp/autosar/src/rules/M5-2-10/IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql index fea2a90398..ece302490e 100644 --- a/cpp/autosar/src/rules/M5-2-10/IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql +++ b/cpp/autosar/src/rules/M5-2-10/IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql @@ -19,7 +19,8 @@ import codingstandards.cpp.autosar from CrementOperation cop, Operation op, string name where - not isExcluded(cop) and + not isExcluded(cop, + OrderOfEvaluationPackage::incrementAndDecrementOperatorsMixedWithOtherOperatorsInExpressionQuery()) and not isExcluded(op, OrderOfEvaluationPackage::incrementAndDecrementOperatorsMixedWithOtherOperatorsInExpressionQuery()) and op.getAnOperand() = cop and From bd0cb8e8b5e2c4da17e5fef8a3c822631f780f73 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 7 Dec 2023 10:09:08 +0000 Subject: [PATCH 2/5] Remove outdated `isExcluded` query predicate. --- cpp/common/src/codingstandards/cpp/Exclusions.qll | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/Exclusions.qll b/cpp/common/src/codingstandards/cpp/Exclusions.qll index bdc11eeb43..b718f6535d 100644 --- a/cpp/common/src/codingstandards/cpp/Exclusions.qll +++ b/cpp/common/src/codingstandards/cpp/Exclusions.qll @@ -14,16 +14,6 @@ private class ExcludeOutsideSourceLocation extends ExcludedFile { ExcludeOutsideSourceLocation() { not exists(getRelativePath()) } } -/** Holds if the element should be excluded. */ -predicate isExcluded(Element e) { - e instanceof ExcludedElement - or - e.getFile() instanceof ExcludedFile - or - // Compiler generated - not exists(e.getFile()) -} - bindingset[e, query] predicate isExcluded(Element e, Query query) { isExcluded(e, query, _) } From 563b0c0cc874c48839e64777bcc5f746c6907cde Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Thu, 7 Dec 2023 10:16:23 +0000 Subject: [PATCH 3/5] Add change note --- change_notes/2023-12-07-fix-deviations.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 change_notes/2023-12-07-fix-deviations.md diff --git a/change_notes/2023-12-07-fix-deviations.md b/change_notes/2023-12-07-fix-deviations.md new file mode 100644 index 0000000000..4e3816a425 --- /dev/null +++ b/change_notes/2023-12-07-fix-deviations.md @@ -0,0 +1,2 @@ + * The following queries have been updated to address issues with applying deviations: + - `A18-5-11`, `A23-0-1`, `A9-3-1`, `M0-1-2`, `M3-1-2`, `M3-2-1`, `M3-2-3`, `M3-9-1`, `M4-5-3`, `M5-0-2`, `M5-2-10` \ No newline at end of file From 93e1c7007ee869deb1c98fee6bcd9fad0e8a7892 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 8 Dec 2023 10:11:49 +0000 Subject: [PATCH 4/5] Remove final uses of `isExcluded`. --- change_notes/2023-12-07-fix-deviations.md | 2 +- .../validcontainerelementaccess/ValidContainerElementAccess.qll | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/change_notes/2023-12-07-fix-deviations.md b/change_notes/2023-12-07-fix-deviations.md index 4e3816a425..e26845d34c 100644 --- a/change_notes/2023-12-07-fix-deviations.md +++ b/change_notes/2023-12-07-fix-deviations.md @@ -1,2 +1,2 @@ * The following queries have been updated to address issues with applying deviations: - - `A18-5-11`, `A23-0-1`, `A9-3-1`, `M0-1-2`, `M3-1-2`, `M3-2-1`, `M3-2-3`, `M3-9-1`, `M4-5-3`, `M5-0-2`, `M5-2-10` \ No newline at end of file + - `A18-5-11`, `A23-0-1`, `A9-3-1`, `M0-1-2`, `M3-1-2`, `M3-2-1`, `M3-2-3`, `M3-9-1`, `M4-5-3`, `M5-0-2`, `M5-2-10`, `A23-0-2`, `CTR51-CPP`, `STR52-CPP` \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/validcontainerelementaccess/ValidContainerElementAccess.qll b/cpp/common/src/codingstandards/cpp/rules/validcontainerelementaccess/ValidContainerElementAccess.qll index 74c6b4f707..93e121d44c 100644 --- a/cpp/common/src/codingstandards/cpp/rules/validcontainerelementaccess/ValidContainerElementAccess.qll +++ b/cpp/common/src/codingstandards/cpp/rules/validcontainerelementaccess/ValidContainerElementAccess.qll @@ -36,7 +36,7 @@ query predicate problems( ContainerInvalidationOperation cio, string actionType ) { not isExcluded(cio, getQuery()) and - not isExcluded(ca) and + not isExcluded(ca, getQuery()) and // The definition of an invalidation is slightly different // for references vs iterators -- this check ensures that the conditions // under which a call should be an invalidator are considered correctly. From 426e886e9eb92630bcf2f3ead829fccf90c21369 Mon Sep 17 00:00:00 2001 From: Luke Cartey <5377966+lcartey@users.noreply.github.com> Date: Tue, 27 Feb 2024 00:05:50 +0000 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Remco Vermeulen --- change_notes/2023-12-06-m16-1-1-perf.md | 2 +- change_notes/2023-12-07-fix-deviations.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/change_notes/2023-12-06-m16-1-1-perf.md b/change_notes/2023-12-06-m16-1-1-perf.md index c8d8eab614..16fa3d5ef8 100644 --- a/change_notes/2023-12-06-m16-1-1-perf.md +++ b/change_notes/2023-12-06-m16-1-1-perf.md @@ -1,4 +1,4 @@ - * `M16-1-1` + - `M16-1-1`: - Optimize query to improve performance - Improve detection of macros whose body contains the `defined` operator after the start of the macro (e.g. `#define X Y || defined(Z)`). - Enable exclusions to be applied for this rule. \ No newline at end of file diff --git a/change_notes/2023-12-07-fix-deviations.md b/change_notes/2023-12-07-fix-deviations.md index e26845d34c..a0f1b1fcfb 100644 --- a/change_notes/2023-12-07-fix-deviations.md +++ b/change_notes/2023-12-07-fix-deviations.md @@ -1,2 +1,2 @@ - * The following queries have been updated to address issues with applying deviations: + - The following queries have been updated to address issues with applying deviations: - `A18-5-11`, `A23-0-1`, `A9-3-1`, `M0-1-2`, `M3-1-2`, `M3-2-1`, `M3-2-3`, `M3-9-1`, `M4-5-3`, `M5-0-2`, `M5-2-10`, `A23-0-2`, `CTR51-CPP`, `STR52-CPP` \ No newline at end of file