Skip to content

Commit 956f69d

Browse files
Merge pull request #1119 from github/mbaluda/perf_inappropriate-bitwise-or-shift-operands
Fix performance `RULE-6-4-2` `RULE-7-0-4`
2 parents a94cafe + 0126299 commit 956f69d

5 files changed

Lines changed: 26 additions & 10 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- `RULE-6-4-2` - `InheritedOverridableMemberFunction.ql`:
2+
- Improved evaluation performance.
3+
- `RULE-6-9-2` - `AvoidStandardIntegerTypeNames.ql`:
4+
- Fixed query name.
5+
- `RULE-7-0-4` - `InappropriateBitwiseOrShiftOperands.ql`:
6+
- Improved evaluation performance.
7+
- `A7-3-1` - `HiddenInheritedOverridableMemberFunctionQuery.ql`:
8+
- Improved evaluation performance.

cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ abstract class HiddenInheritedOverridableMemberFunctionSharedQuery extends Query
1212

1313
Query getQuery() { result instanceof HiddenInheritedOverridableMemberFunctionSharedQuery }
1414

15+
private class OverridingDeclaration extends FunctionDeclarationEntry {
16+
OverridingDeclaration() { this.getDeclaration().hasDefinition() implies not this.isDefinition() }
17+
}
18+
19+
private class HiddenDeclaration extends OverridingDeclaration {
20+
HiddenDeclaration() {
21+
// Check if we are overriding a virtual inherited member function
22+
this.getDeclaration().isVirtual() and
23+
// Exclude private member functions, which cannot be inherited.
24+
not this.getDeclaration().(MemberFunction).isPrivate()
25+
}
26+
}
27+
1528
query predicate problems(
16-
FunctionDeclarationEntry overridingDecl, string message, FunctionDeclarationEntry hiddenDecl,
29+
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
1730
string hiddenDecl_string
1831
) {
1932
not isExcluded(overridingDecl, getQuery()) and
20-
// Check if we are overriding a virtual inherited member function
21-
hiddenDecl.getDeclaration().isVirtual() and
22-
// Exclude private member functions, which cannot be inherited.
23-
not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and
2433
// The overriding declaration hides the hidden declaration if:
2534
(
2635
// 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(
4655
overridingDecl.getDeclaration().getDeclaringType().getABaseClass() =
4756
hiddenDecl.getDeclaration().getDeclaringType()
4857
) and
49-
// Limit the results to the declarations and not the definitions, if any.
50-
(overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and
51-
(hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) and
5258
message =
5359
"Declaration for member '" + overridingDecl.getName() +
5460
"' hides overridable inherited member function $@" and

cpp/misra/src/rules/RULE-6-9-2/AvoidStandardIntegerTypeNames.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @id cpp/misra/avoid-standard-integer-type-names
3-
* @name RULE-6-9-2: The names of the standard signed integer types and standard unsigned integer types should not be
3+
* @name RULE-6-9-2: The names of the standard integer types should not be used
44
* @description Using standard signed and unsigned integer type names instead of specified width
55
* types makes storage requirements unclear and implementation-dependent.
66
* @kind problem

cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ predicate isConstantExpression(Expr e) {
2222
e.isConstant()
2323
}
2424

25+
bindingset[right, leftType]
26+
pragma[inline_late]
2527
predicate isValidShiftConstantRange(Expr right, Type leftType) {
2628
exists(int value |
2729
value = right.getValue().toInt() and

rule_packages/cpp/BannedAPIs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
{
210210
"description": "Using standard signed and unsigned integer type names instead of specified width types makes storage requirements unclear and implementation-dependent.",
211211
"kind": "problem",
212-
"name": "The names of the standard signed integer types and standard unsigned integer types should not be",
212+
"name": "The names of the standard integer types should not be used",
213213
"precision": "very-high",
214214
"severity": "error",
215215
"short_name": "AvoidStandardIntegerTypeNames",

0 commit comments

Comments
 (0)