Skip to content

Fix performance RULE-6-4-2 RULE-7-0-4#1119

Open
mbaluda wants to merge 12 commits intomainfrom
mbaluda/perf_inappropriate-bitwise-or-shift-operands
Open

Fix performance RULE-6-4-2 RULE-7-0-4#1119
mbaluda wants to merge 12 commits intomainfrom
mbaluda/perf_inappropriate-bitwise-or-shift-operands

Conversation

@mbaluda
Copy link
Copy Markdown
Collaborator

@mbaluda mbaluda commented Apr 25, 2026

Description

Performance and correctness improvements:

  • Improved evaluation performance for InheritedOverridableMemberFunction.ql and InappropriateBitwiseOrShiftOperands.ql by refactoring query logic and introducing more precise type definitions (OverridingDeclaration, HiddenDeclaration) in HiddenInheritedOverridableMemberFunction.qll. [1] [2] [3] [4]
  • Added bindingset and pragma annotations to isValidShiftConstantRange in InappropriateBitwiseOrShiftOperands.ql to further improve query performance.

Rule naming and documentation updates:

  • Updated the rule name and query name for AvoidStandardIntegerTypeNames.ql to clarify that all standard integer types (not just signed/unsigned) should not be used. This change is reflected in the query file, change notes, and BannedAPIs.json. [1] [2] [3]

These changes collectively enhance both the efficiency and clarity of the codebase related to C++ coding standard enforcement.

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • rule number here
  • Queries have been modified for the following rules:
    • RULE-6-4-2
    • RULE-6-9-2
    • RULE-7-0-4
    • A7-3-1

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

Query development review checklist

For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:

Author

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Copilot AI review requested due to automatic review settings April 25, 2026 13:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the MISRA C++ RULE-7-0-4 CodeQL query to improve evaluation performance by guiding CodeQL’s optimizer for shift-constant range checking.

Changes:

  • Added bindingset[right, leftType] for isValidShiftConstantRange.
  • Added pragma[inline_late] to encourage late inlining of isValidShiftConstantRange.
Show a summary per file
File Description
cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql Adds optimizer hints to the constant-shift-range predicate to improve query performance.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

@mbaluda mbaluda changed the title Fix perofmance inappropriate-bitwise-or-shift-operands Fix perofmance RULE-6-4-2 RULE-7-0-4 Apr 25, 2026
mbaluda added 2 commits April 25, 2026 16:55
Enhanced performance of the 'isValidShiftConstantRange' predicate by adding annotations for optimization.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

Comments suppressed due to low confidence (2)

change_notes/2026-04-25-fix-performance-inappropriate-bitwise-or-shift-operands.md:5

  • Change notes typically use past tense for bullet items. Please change "Remove false positives..." to "Removed false positives...".
  - Remove false positives related to the `insertion operator`.

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

  • The PR description focuses on the RULE-7-0-4 shift-range predicate, but this PR also changes the shared hidden-inherited-member-function library used by RULE-6-4-2 (and A7-3-1). Please update the PR description to mention this additional functional area so reviewers understand the full scope of the change.
query predicate problems(
  OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
  string hiddenDecl_string
) {
  • Files reviewed: 3/3 changed files
  • Comments generated: 3

@mbaluda

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@codeql-coding-standards-automation

This comment was marked as off-topic.

@codeql-coding-standards-automation
Copy link
Copy Markdown

🏁 Beep Boop! Performance testing complete! See below for performance of the last 3 runs vs your PR. Times are based on predicate performance. You can find full graphs and stats in the PR that was created for this test in the release engineering repo.


Release                            : v2.57.0
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2666818
Mean_Predicate_Execution_Time_Ms   : 52.28337287039034
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 531.8686023207812
Total_Serialized_Execution_Time_s  : 2666.818
Mean_Query_Execution_Time_s        : 0.0522833728703903
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 137.0
Number_of_Predicates               : 51007

Release                            : v2.57.0
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2915738
Mean_Predicate_Execution_Time_Ms   : 61.75971701510241
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 552.8909886535025
Total_Serialized_Execution_Time_s  : 2915.738
Mean_Query_Execution_Time_s        : 0.0617597170151024
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 164.0
Number_of_Predicates               : 47211

Release                            : v2.57.0
Platform                           : x86-windows
Language                           : c
Total_Serialized_Execution_Time_Ms : 3221628
Mean_Predicate_Execution_Time_Ms   : 63.17165379034472
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 506.436091082282
Total_Serialized_Execution_Time_s  : 3221.628
Mean_Query_Execution_Time_s        : 0.0631716537903447
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 190.0
Number_of_Predicates               : 50998

Release                            : v2.57.0
Platform                           : x86-windows
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 3073194
Mean_Predicate_Execution_Time_Ms   : 65.11832012543968
Median_Predicate_Execution_Time_Ms : 1.0
Standard_Deviation_Ms              : 434.3629768649453
Total_Serialized_Execution_Time_s  : 3073.194
Mean_Query_Execution_Time_s        : 0.0651183201254396
Median_Predicate_Execution_Time_s  : 0.001
Percentile95_Ms                    : 205.0
Number_of_Predicates               : 47194

Release                            : v2.58.0
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2671769
Mean_Predicate_Execution_Time_Ms   : 52.42463307432698
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 540.6377631036331
Total_Serialized_Execution_Time_s  : 2671.769
Mean_Query_Execution_Time_s        : 0.0524246330743269
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 141.0
Number_of_Predicates               : 50964

Release                            : v2.58.0
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2966042
Mean_Predicate_Execution_Time_Ms   : 62.959923583103375
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 551.9899853287171
Total_Serialized_Execution_Time_s  : 2966.042
Mean_Query_Execution_Time_s        : 0.0629599235831033
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 163.0
Number_of_Predicates               : 47110

Release                            : v2.58.0
Platform                           : x86-windows
Language                           : c
Total_Serialized_Execution_Time_Ms : 3346313
Mean_Predicate_Execution_Time_Ms   : 65.73384799732847
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 510.1650699100149
Total_Serialized_Execution_Time_s  : 3346.313
Mean_Query_Execution_Time_s        : 0.0657338479973284
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 188.0
Number_of_Predicates               : 50907

Release                            : v2.58.0
Platform                           : x86-windows
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 3126619
Mean_Predicate_Execution_Time_Ms   : 66.04323856195344
Median_Predicate_Execution_Time_Ms : 1.0
Standard_Deviation_Ms              : 421.48236881546416
Total_Serialized_Execution_Time_s  : 3126.619
Mean_Query_Execution_Time_s        : 0.0660432385619534
Median_Predicate_Execution_Time_s  : 0.001
Percentile95_Ms                    : 209.0
Number_of_Predicates               : 47342

Release                            : 1119
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2628904
Mean_Predicate_Execution_Time_Ms   : 51.47749123734555
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 541.4773839514766
Total_Serialized_Execution_Time_s  : 2628.904
Mean_Query_Execution_Time_s        : 0.0514774912373455
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 133.0
Number_of_Predicates               : 51069

Release                            : 1119
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 4274359
Mean_Predicate_Execution_Time_Ms   : 60.937784240765296
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 543.2562819754833
Total_Serialized_Execution_Time_s  : 4274.359
Mean_Query_Execution_Time_s        : 0.0609377842407653
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 161.0
Number_of_Predicates               : 70143

🏁 Below are the slowest predicates for the last 2 releases vs this PR.


Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : _Class::Class.getALinkTarget/0#dispred#29b2b38a#bf_Class::Class.getALinkTarget/0#dispred#29b2b38a#bf__#shared
Execution_Time_Ms : 29462

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : _Macro::Macro.getName/0#dispred#e28b3699_Preprocessor::PreprocessorBranchDirective#bcd2bde4#b_Prepro__#antijoin_rhs
Execution_Time_Ms : 31637

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 31017

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 35019

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : _Macro::Macro.getName/0#dispred#e28b3699_Preprocessor::PreprocessorBranchDirective#bcd2bde4#b_Prepro__#antijoin_rhs
Execution_Time_Ms : 33475

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : c
Suite             : cert-default
Predicate         : IncompatibleFunctionDeclaration::interestedInFunctions/4#95575433
Execution_Time_Ms : 27439

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : c
Suite             : cert-default
Predicate         : IncompatibleFunctionDeclaration::interestedInFunctions/4#95575433
Execution_Time_Ms : 22723

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 17287

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : num#FunctionEquivalence::TParameter#9a1b3813
Execution_Time_Ms : 23098

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : _Class::Class.getALinkTarget/0#dispred#29b2b38a#bf_Class::Class.getALinkTarget/0#dispred#29b2b38a#bf__#shared
Execution_Time_Ms : 26741

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : FunctionEquivalence::typeSig/1#194ac728
Execution_Time_Ms : 18349

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : Dependency::dependsOnTransitive/2#cbda84a0
Execution_Time_Ms : 19129

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : VirtualDispatchPrototype::VirtualDispatch::cannotInheritHelper/4#7c75bd87
Execution_Time_Ms : 28563

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 15641

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 30474

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 25036

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 30188

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CheckedException::CheckedException#b0aa5ec8
Execution_Time_Ms : 29359

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 32874

Release           : v2.58.0
Run               : 2026-04-21_22-22-15
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : HardwareOrProtocolInterface::HardwareOrProtocolInterfaceComment#dbbd8a01
Execution_Time_Ms : 24237

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 30468

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CheckedException::CheckedException#b0aa5ec8
Execution_Time_Ms : 26947

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : VirtualDispatchPrototype::VirtualDispatch::cannotInheritHelper/4#7c75bd87
Execution_Time_Ms : 27488

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 29542

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 30276

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 34519

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : cpp
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 33982

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : c
Suite             : cert-default
Predicate         : IncompatibleFunctionDeclaration::interestedInFunctions/4#95575433
Execution_Time_Ms : 27785

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : _Class::Class.getALinkTarget/0#dispred#29b2b38a#bf_Class::Class.getALinkTarget/0#dispred#29b2b38a#bf__#shared
Execution_Time_Ms : 34728

Release           : 1119
Run               : 2026-04-27_14-47-26
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : _Macro::Macro.getName/0#dispred#e28b3699_Preprocessor::PreprocessorBranchDirective#bcd2bde4#b_Prepro__#antijoin_rhs
Execution_Time_Ms : 37115

@mbaluda mbaluda changed the title Fix perofmance RULE-6-4-2 RULE-7-0-4 Fix performance RULE-6-4-2 RULE-7-0-4 Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@MichaelRFairhurst MichaelRFairhurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing!!

Comment thread cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Comment on lines 211 to 215
"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",
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within this RULE-6-9-2 entry, the query name was updated, but the rule-level title (later in the same object) still uses the old wording about "standard signed"/"standard unsigned" integer types. To avoid inconsistent rule naming in downstream consumers, please update the title string to match the new query name (or otherwise align them intentionally).

Copilot uses AI. Check for mistakes.
Comment on lines +29 to 31
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
string hiddenDecl_string
) {
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

problems is a public query predicate, but its parameters are now typed as OverridingDeclaration/HiddenDeclaration, which are declared private in this module. That effectively makes problems hard/impossible to call from other modules (they cannot name these types) and is inconsistent with other shared-query libraries that keep public signatures in terms of public CodeQL types. Consider either making these classes non-private, or keeping the problems signature in terms of FunctionDeclarationEntry and moving the extra constraints into helper predicates/classes used internally.

Suggested change
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
string hiddenDecl_string
) {
FunctionDeclarationEntry overridingDecl, string message,
FunctionDeclarationEntry hiddenDecl, string hiddenDecl_string
) {
overridingDecl instanceof OverridingDeclaration and
hiddenDecl instanceof HiddenDeclaration and

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants