Skip to content

Conversation

lcartey
Copy link
Collaborator

@lcartey lcartey commented Aug 18, 2025

Description

Follows on from #919.

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-8-2-1
    • RULE-8-2-2
    • RULE-8-2-6
    • RULE-8-2-7
    • RULE-8-2-8
    • `RULE-9-2-1
  • Queries have been modified for the following rules:
    • RULE-1-3
    • RULE-23-3
    • RULE-23-5
    • RULE-23-6

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!)

Copy link
Contributor

@Copilot 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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

lcartey added 21 commits August 26, 2025 21:38
This shared implementation will be used for implementing MISRA C++
2023 8.2.1.
MISRA C++ Rule 8.2.2 is similar, but not identical.
Nested macro invocations do not have getExpandedElements(), but
do have getAffectedElements().
Detects C-style casts and functional notation casts that should be
replaced with explicit cast operators. Prevents unsafe type conversions
that lack clear intent and proper type checking constraints. [a]
Detects casts from integral, enumerated, or void pointer types to object
pointer types that may lead to unspecified behavior. [a]
Detects casts that convert pointer types to integral types, which can
make code harder to understand and may break pointer tracking in analysis
tools. [a]
Detects pointer-to-integral casts that use types other than
std::uintptr_t or std::intptr_t, which may not guarantee representation
of all pointer values. [a]
Detects explicit type conversions using functional notation as standalone
expression statements that create immediately-destroyed temporary
objects. [a]
 - Simplify the query implementation
 - Improve query message
 - Remove redundant code
 - Use stripSpecifiers(..) to check for use of (u)intptr_t.
@lcartey lcartey force-pushed the lcartey/cpp-conversions2 branch from 24a8098 to 6e9ee92 Compare August 26, 2025 20:45
@MichaelRFairhurst
Copy link
Collaborator

The code LGTM, however, we unfortunately have a performance issue in 8-2-2 evaluating AlertReporting::MacroUnwrapper<NoCStyleOrFunctionalCasts::MISRACPPProhibitedCStyleCasts>::getPrimaryMacroInvocation/1#1716e261/2@f69f429.

@MichaelRFairhurst
Copy link
Collaborator

Needless to say, I'll resolve the performance issue and merge. Thank you Luke! 😢

@MichaelRFairhurst
Copy link
Collaborator

[2025-08-29 08:03:26] (4s) Starting to evaluate predicate AlertReporting::MacroUnwrapper<NoCStyleOrFunctionalCasts::MISRACPPProhibitedCStyleCasts>::getPrimaryMacroInvocation/1#1716e261/2@f69f429q
[2025-08-29 08:33:27] (1804s) Tuple counts for AlertReporting::MacroUnwrapper<NoCStyleOrFunctionalCasts::MISRACPPProhibitedCStyleCasts>::getPrimaryMacroInvocation/1#1716e261/2@f69f429q after 30m1s:
                      2935649      ~2%     {3} r1 = JOIN `_Location::Location.fullLocationInfo/5#dispred#cf4c85ba_Macro::MacroAccess.getLocation/0#dispred#910__#shared` WITH `AlertReporting::MacroUnwrapper<NoCStyleOrFunctionalCasts::MISRACPPProhibitedCStyleCasts>::getAMacroInvocation/1#6e2f22a3_10#join_rhs` ON FIRST 1 OUTPUT Lhs.1, Lhs.0 'result', Rhs.1 're'
                      2908248      ~2%     {3}    | AND NOT `_AlertReporting::MacroUnwrapper<NoCStyleOrFunctionalCasts::MISRACPPProhibitedCStyleCasts>::getAMacro__#antijoin_rhs`(FIRST 3)
                      197923826670 ~4%     {3}    | JOIN WITH `Location::Location.fullLocationInfo/5#dispred#cf4c85ba_30#join_rhs` ON FIRST 1 OUTPUT Lhs.2 're', Rhs.1, Lhs.1 'result'
                      2805383      ~4%     {2}    | JOIN WITH `Element::Element.getLocation/0#dispred#6c3f5b09` ON FIRST 2 OUTPUT Lhs.0 're', Lhs.2 'result'
                                           return r1

@MichaelRFairhurst
Copy link
Collaborator

/test-performance

Copy link

🏁 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!

🏁 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.48.0
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2460575
Mean_Predicate_Execution_Time_Ms   : 45.75090178870254
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 610.2126116318541
Total_Serialized_Execution_Time_s  : 2460.575
Mean_Query_Execution_Time_s        : 0.0457509017887025
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 117.0
Number_of_Predicates               : 53782

Release                            : v2.48.0
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2837242
Mean_Predicate_Execution_Time_Ms   : 56.65645592875115
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 571.6631603044997
Total_Serialized_Execution_Time_s  : 2837.242
Mean_Query_Execution_Time_s        : 0.0566564559287511
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 150.14999999999418
Number_of_Predicates               : 50078

Release                            : v2.48.0
Platform                           : x86-windows
Language                           : c
Total_Serialized_Execution_Time_Ms : 2929819
Mean_Predicate_Execution_Time_Ms   : 54.39289692559038
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 526.0522079236116
Total_Serialized_Execution_Time_s  : 2929.819
Mean_Query_Execution_Time_s        : 0.0543928969255903
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 166.0
Number_of_Predicates               : 53864

Release                            : v2.48.0
Platform                           : x86-windows
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2740161
Mean_Predicate_Execution_Time_Ms   : 54.355332063794336
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 458.6002875269033
Total_Serialized_Execution_Time_s  : 2740.161
Mean_Query_Execution_Time_s        : 0.0543553320637943
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 167.0
Number_of_Predicates               : 50412

Release                            : v2.49.0
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2292787
Mean_Predicate_Execution_Time_Ms   : 46.19294852422686
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 447.3501657458543
Total_Serialized_Execution_Time_s  : 2292.787
Mean_Query_Execution_Time_s        : 0.0461929485242268
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 131.0
Number_of_Predicates               : 49635

Release                            : v2.49.0
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2617585
Mean_Predicate_Execution_Time_Ms   : 56.77442793623251
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 496.9154104341087
Total_Serialized_Execution_Time_s  : 2617.585
Mean_Query_Execution_Time_s        : 0.0567744279362325
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 160.0
Number_of_Predicates               : 46105

Release                            : v2.49.0
Platform                           : x86-windows
Language                           : c
Total_Serialized_Execution_Time_Ms : 3002630
Mean_Predicate_Execution_Time_Ms   : 60.11030589365791
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 444.0858923209042
Total_Serialized_Execution_Time_s  : 3002.63
Mean_Query_Execution_Time_s        : 0.0601103058936579
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 186.0
Number_of_Predicates               : 49952

Release                            : v2.49.0
Platform                           : x86-windows
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 3157846
Mean_Predicate_Execution_Time_Ms   : 68.44646263221779
Median_Predicate_Execution_Time_Ms : 1.0
Standard_Deviation_Ms              : 475.591552583925
Total_Serialized_Execution_Time_s  : 3157.846
Mean_Query_Execution_Time_s        : 0.0684464626322177
Median_Predicate_Execution_Time_s  : 0.001
Percentile95_Ms                    : 214.0
Number_of_Predicates               : 46136

Release                            : 946
Platform                           : x86-linux
Language                           : cpp
Total_Serialized_Execution_Time_Ms : 2818237
Mean_Predicate_Execution_Time_Ms   : 61.01136560443367
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 530.8007448098363
Total_Serialized_Execution_Time_s  : 2818.237
Mean_Query_Execution_Time_s        : 0.0610113656044336
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 166.4499999999971
Number_of_Predicates               : 46192

Release                            : 946
Platform                           : x86-linux
Language                           : c
Total_Serialized_Execution_Time_Ms : 2449369
Mean_Predicate_Execution_Time_Ms   : 49.16437173825773
Median_Predicate_Execution_Time_Ms : 0.0
Standard_Deviation_Ms              : 494.4308792508496
Total_Serialized_Execution_Time_s  : 2449.369
Mean_Query_Execution_Time_s        : 0.0491643717382577
Median_Predicate_Execution_Time_s  : 0.0
Percentile95_Ms                    : 132.0
Number_of_Predicates               : 49820

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


Release           : v2.49.0
Run               : 2025-08-18_14-04-37
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 : 33082

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 30776

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
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 : 29005

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : c
Suite             : cert-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 21596

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 22133

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
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 : 26536

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
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 : 27098

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 25724

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : #select
Execution_Time_Ms : 18426

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : OrderingPredicateMustBeStrictlyWeak::IsStrictlyWeaklyOrderedComment#07390086
Execution_Time_Ms : 18066

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 16505

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : HardwareOrProtocolInterface::HardwareOrProtocolInterfaceComment#dbbd8a01
Execution_Time_Ms : 18876

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : VirtualDispatchPrototype::VirtualDispatch::cannotInheritHelper/4#7c75bd87
Execution_Time_Ms : 20619

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 22729

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : cpp
Suite             : autosar-default
Predicate         : Dependency::dependsOnTransitive/2#cbda84a0
Execution_Time_Ms : 28181

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-windows
Language          : c
Suite             : cert-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 19318

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CheckedException::CheckedException#b0aa5ec8
Execution_Time_Ms : 24355

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : FunctionEquivalence::typeSig/1#194ac728
Execution_Time_Ms : 21744

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 26902

Release           : v2.49.0
Run               : 2025-08-18_14-04-37
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 30437

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CharacterOutsideTheLanguageStandardBasicSourceCharacterSetUsedInTheSourceCode::getUniversalCharacterName/1#36dbaa42
Execution_Time_Ms : 27814

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTable/5#79217c12
Execution_Time_Ms : 23916

Release           : 946
Run               : 2025-08-29_23-42-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 : 26992

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : OutOfBounds::OOB::libraryFunctionNameParamTableSimpleString/5#6de8614f#cpe#1236
Execution_Time_Ms : 31228

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : #select
Execution_Time_Ms : 21826

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : HardwareOrProtocolInterface::HardwareOrProtocolInterfaceComment#dbbd8a01
Execution_Time_Ms : 22504

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : CheckedException::CheckedException#b0aa5ec8
Execution_Time_Ms : 26608

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : cpp
Suite             : autosar-default
Predicate         : QualifiedName::getUserTypeNameWithoutArgs/1#8cfc98e9
Execution_Time_Ms : 30189

Release           : 946
Run               : 2025-08-29_23-42-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 : 32833

Release           : 946
Run               : 2025-08-29_23-42-00
Platform          : x86-linux
Language          : c
Suite             : misra-default
Predicate         : Macro::MacroInvocation.getAnAffectedElement/0#dispred#d1462297_10#join_rhs
Execution_Time_Ms : 31963

@MichaelRFairhurst
Copy link
Collaborator

Adding @knewbury01 just to verify that this performance difference looks OK, and to review my contributed performance fix 0124f5e

@MichaelRFairhurst
Copy link
Collaborator

cc @jeongsoolee09 to stay in the loop regarding coding standards performance!

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.

2 participants