Skip to content

Add lifetime package#1024

Merged
MichaelRFairhurst merged 15 commits intogithub:mainfrom
knewbury01:knewbury01/Lifetime
Mar 19, 2026
Merged

Add lifetime package#1024
MichaelRFairhurst merged 15 commits intogithub:mainfrom
knewbury01:knewbury01/Lifetime

Conversation

@knewbury01
Copy link
Collaborator

@knewbury01 knewbury01 commented Feb 3, 2026

Description

add rules for lifetime package, two shared rules, one with improvements upon previous, one as simple shared

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-11-6-2
    • RULE-6-8-3
  • Queries have been modified for the following rules:
    • rule number here

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

also adjust formatting on prev changenote which was incorrect
@knewbury01 knewbury01 self-assigned this Feb 3, 2026
Copy link
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.

The test cases look great Kristen, thank you!

@knewbury01 knewbury01 marked this pull request as ready for review March 10, 2026 16:38
Copilot AI review requested due to automatic review settings March 10, 2026 16:38
Copy link
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

This PR adds a new "Lifetime" rule package for MISRA C++ 2023, implementing two new rules: RULE-11-6-2 (reading uninitialized objects) and RULE-6-8-3 (automatic storage assigned to wider lifetime). It also enhances the shared ReadOfUninitializedMemory query to detect uninitialized reads through new expressions without value initialization, and extends the AllocatedObjectIdentity class to recognize new/new[] expressions as allocated storage.

Changes:

  • Adds the Lifetime rule package with RULE-11-6-2 and RULE-6-8-3, including exclusion metadata, query files, test references, and supporting infrastructure.
  • Enhances the ReadOfUninitializedMemory shared library to detect uninitialized memory accessed via new expressions (without value initialization), incorporating a copied InitializationFunctions.qll from the CodeQL standard library.
  • Extends AllocatedObjectIdentity in CppObjects.qll to include new/new[] expressions (excluding placement new) for storage duration tracking.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rules.csv Updates RULE-11-6-2 to reference the Lifetime package
rule_packages/cpp/Lifetime.json New rule package definition for RULE-11-6-2 and RULE-6-8-3
cpp/common/src/codingstandards/cpp/exclusions/cpp/Lifetime.qll Autogenerated exclusion module for Lifetime package
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Integrates Lifetime package into rule metadata
cpp/misra/src/rules/RULE-11-6-2/ValueOfAnObjectMustNotBeReadBeforeItHasBeenSet.ql New query for RULE-11-6-2 using shared ReadOfUninitializedMemory
cpp/misra/src/rules/RULE-6-8-3/AutomaticStorageAssignedToObjectGreaterLifetime.ql New query for RULE-6-8-3 using shared DoNotCopyAddressOfAutoStorage
cpp/common/src/codingstandards/cpp/rules/readofuninitializedmemory/ReadOfUninitializedMemory.qll Enhanced to handle new without value init
cpp/common/src/codingstandards/cpp/rules/readofuninitializedmemory/InitializationFunctions.qll Copied from CodeQL standard library for init function tracking
cpp/common/src/codingstandards/cpp/lifetimes/CppObjects.qll Extended AllocatedObjectIdentity for new/new[] expressions
cpp/common/test/rules/readofuninitializedmemory/test.cpp Added test cases for new uninitialized memory scenarios
cpp/common/test/rules/readofuninitializedmemory/ReadOfUninitializedMemory.expected Updated expected results for new test cases
cpp/common/test/rules/donotcopyaddressofautostorageobjecttootherobject/test.cpp Added test cases for auto-storage address escape
cpp/common/test/rules/donotcopyaddressofautostorageobjecttootherobject/DoNotCopyAddressOfAutoStorageObjectToOtherObject.expected Updated expected results for new test cases
cpp/misra/test/rules/RULE-6-8-3/AutomaticStorageAssignedToObjectGreaterLifetime.testref Test reference for RULE-6-8-3
cpp/misra/test/rules/RULE-11-6-2/ValueOfAnObjectMustNotBeReadBeforeItHasBeenSet.testref Test reference for RULE-11-6-2
change_notes/2026-02-03-uninitialized-mem-improve.md Change note for shared query modifications
.vscode/tasks.json Added Lifetime to VS Code task configuration
Comments suppressed due to low confidence (1)

cpp/common/src/codingstandards/cpp/rules/readofuninitializedmemory/ReadOfUninitializedMemory.qll:207

  • Typo in docstring: "Get a access" should be "Gets an access".
   * Get a access of the variable that is assumed to initialize the variable.

@mbaluda mbaluda removed their request for review March 12, 2026 16:58
Copy link
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.

OK, there's a lot of text here, but I think it boils down to actually pretty simple changes, its just complicated to think through and fully explain the implications of X vs Y 😕 I would have written less if I olny had more time! :)

I'm 100% glad that you pursued the approach. I think with a small few tweaks this implementation will be very precise, and handling new int without a major overhaul was absolutely the correct choice. 🎉

Let me know if anything here is unclear or if I missed anything!

Copy link
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.

Awesome!

Just some minor questions really, I think the findings and FPs/FNs look mostly good, and about ready to ship!

Copy link
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.

🚀 LGTM! Very nice work 🚀

@MichaelRFairhurst MichaelRFairhurst added this pull request to the merge queue Mar 19, 2026
Merged via the queue into github:main with commit 1487ba0 Mar 19, 2026
21 checks passed
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