Skip to content

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

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

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

Conversation

@mbaluda
Copy link
Copy Markdown
Collaborator

@mbaluda mbaluda commented Apr 25, 2026

Description

This pull request introduces a new predicate to help validate constant ranges for shift operations in the InappropriateBitwiseOrShiftOperands.ql rule. The main change is the addition of the isValidShiftConstantRange predicate, which checks the range of constant values used in shift expressions.

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-7-0-4

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

Comment thread cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql Outdated
@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
Copy link
Copy Markdown
Collaborator Author

mbaluda commented Apr 26, 2026

/test-performance

@github-actions
Copy link
Copy Markdown

🏁 Beep Boop! Performance testing for this PR has been initiated. Please check back later for results. Note that the query package generation step must complete before testing will start so it might be a minute.

💡 If you do not hear back from me please check my status! I will report even if I fail!

@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 : 2606021
Mean_Predicate_Execution_Time_Ms   : 51.19079515989628
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 518.7331021147838
Total_Serialized_Execution_Time_s  : 2606.021
Mean_Query_Execution_Time_s        : 0.0511907951598962
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 135.0
Number_of_Predicates               : 50908

Release                            : 1119
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2975223
Mean_Predicate_Execution_Time_Ms   : 63.14810569882203
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 555.4428162572788
Total_Serialized_Execution_Time_s  : 2975.223
Mean_Query_Execution_Time_s        : 0.063148105698822
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 163.29999999999563
Number_of_Predicates               : 47115

🏁 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-26_10-01-00
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 : 28485

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : HardwareOrProtocolInterface::HardwareOrProtocolInterfaceComment#dbbd8a01
Execution_Time_Ms : 23780

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CheckedException::CheckedException#b0aa5ec8
Execution_Time_Ms : 27509

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : VirtualDispatchPrototype::VirtualDispatch::cannotInheritHelper/4#7c75bd87
Execution_Time_Ms : 27855

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 29718

Release           : 1119
Run               : 2026-04-26_10-01-00
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 : 29753

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 30563

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 24896

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 31354

Release           : 1119
Run               : 2026-04-26_10-01-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 33483

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.

3 participants