diff --git a/change_notes/2026-04-25-fix-performance-inappropriate-bitwise-or-shift-operands.md b/change_notes/2026-04-25-fix-performance-inappropriate-bitwise-or-shift-operands.md new file mode 100644 index 0000000000..a2c9a67ade --- /dev/null +++ b/change_notes/2026-04-25-fix-performance-inappropriate-bitwise-or-shift-operands.md @@ -0,0 +1,8 @@ +- `RULE-6-4-2` - `InheritedOverridableMemberFunction.ql`: + - Improved evaluation performance. +- `RULE-6-9-2` - `AvoidStandardIntegerTypeNames.ql`: + - Fixed query name. +- `RULE-7-0-4` - `InappropriateBitwiseOrShiftOperands.ql`: + - Improved evaluation performance. +- `A7-3-1` - `HiddenInheritedOverridableMemberFunctionQuery.ql`: + - Improved evaluation performance. diff --git a/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll index ef99e01973..3604c4756c 100644 --- a/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll +++ b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll @@ -12,15 +12,24 @@ abstract class HiddenInheritedOverridableMemberFunctionSharedQuery extends Query Query getQuery() { result instanceof HiddenInheritedOverridableMemberFunctionSharedQuery } +private class OverridingDeclaration extends FunctionDeclarationEntry { + OverridingDeclaration() { this.getDeclaration().hasDefinition() implies not this.isDefinition() } +} + +private class HiddenDeclaration extends OverridingDeclaration { + HiddenDeclaration() { + // Check if we are overriding a virtual inherited member function + this.getDeclaration().isVirtual() and + // Exclude private member functions, which cannot be inherited. + not this.getDeclaration().(MemberFunction).isPrivate() + } +} + query predicate problems( - FunctionDeclarationEntry overridingDecl, string message, FunctionDeclarationEntry hiddenDecl, + OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl, string hiddenDecl_string ) { not isExcluded(overridingDecl, getQuery()) and - // Check if we are overriding a virtual inherited member function - hiddenDecl.getDeclaration().isVirtual() and - // Exclude private member functions, which cannot be inherited. - not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and // The overriding declaration hides the hidden declaration if: ( // 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration @@ -46,9 +55,6 @@ query predicate problems( overridingDecl.getDeclaration().getDeclaringType().getABaseClass() = hiddenDecl.getDeclaration().getDeclaringType() ) and - // Limit the results to the declarations and not the definitions, if any. - (overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and - (hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) and message = "Declaration for member '" + overridingDecl.getName() + "' hides overridable inherited member function $@" and diff --git a/cpp/misra/src/rules/RULE-6-9-2/AvoidStandardIntegerTypeNames.ql b/cpp/misra/src/rules/RULE-6-9-2/AvoidStandardIntegerTypeNames.ql index ff1d6f1d98..ff77c7e215 100644 --- a/cpp/misra/src/rules/RULE-6-9-2/AvoidStandardIntegerTypeNames.ql +++ b/cpp/misra/src/rules/RULE-6-9-2/AvoidStandardIntegerTypeNames.ql @@ -1,6 +1,6 @@ /** * @id cpp/misra/avoid-standard-integer-type-names - * @name RULE-6-9-2: The names of the standard signed integer types and standard unsigned integer types should not be + * @name RULE-6-9-2: The names of the standard integer types should not be used * @description Using standard signed and unsigned integer type names instead of specified width * types makes storage requirements unclear and implementation-dependent. * @kind problem diff --git a/cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql b/cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql index e1f1e21069..f0992d2f0f 100644 --- a/cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql +++ b/cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql @@ -22,6 +22,8 @@ predicate isConstantExpression(Expr e) { e.isConstant() } +bindingset[right, leftType] +pragma[inline_late] predicate isValidShiftConstantRange(Expr right, Type leftType) { exists(int value | value = right.getValue().toInt() and diff --git a/rule_packages/cpp/BannedAPIs.json b/rule_packages/cpp/BannedAPIs.json index 3bb456fdd4..42894c7add 100644 --- a/rule_packages/cpp/BannedAPIs.json +++ b/rule_packages/cpp/BannedAPIs.json @@ -209,7 +209,7 @@ { "description": "Using standard signed and unsigned integer type names instead of specified width types makes storage requirements unclear and implementation-dependent.", "kind": "problem", - "name": "The names of the standard signed integer types and standard unsigned integer types should not be", + "name": "The names of the standard integer types should not be used", "precision": "very-high", "severity": "error", "short_name": "AvoidStandardIntegerTypeNames",