Skip to content

Fix deviations through use of deprecated isExcluded predicates #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 5, 2024
2 changes: 2 additions & 0 deletions change_notes/2023-12-07-fix-deviations.md
Original file line number Diff line number Diff line change
@@ -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`, `A23-0-2`, `CTR51-CPP`, `STR52-CPP`
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`."
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cpp/autosar/src/rules/M0-1-2/InfeasiblePath.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "."
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cpp/autosar/src/rules/M5-0-2/GratuitousUseOfParentheses.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import codingstandards.cpp.Expr

from CrementOperation cop, ArithmeticOperation op, string name
where
not isExcluded(cop) and
not isExcluded(cop,
OrderOfEvaluationPackage::incrementAndDecrementOperatorsMixedWithOtherOperatorsInExpressionQuery()) and
not isExcluded(op,
OrderOfEvaluationPackage::incrementAndDecrementOperatorsMixedWithOtherOperatorsInExpressionQuery()) and
op.getAnOperand() = cop and
Expand Down
10 changes: 0 additions & 10 deletions cpp/common/src/codingstandards/cpp/Exclusions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down