Skip to content

Comments

Implement RULE-6-7-2 banning most kinds of global variables#1052

Merged
mbaluda merged 2 commits intomainfrom
michaelrfairhurst/banned1-global-variables
Feb 23, 2026
Merged

Implement RULE-6-7-2 banning most kinds of global variables#1052
mbaluda merged 2 commits intomainfrom
michaelrfairhurst/banned1-global-variables

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

Fairly straightforward implementation, shared initialization logic with prior rule A3-3-2.

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-6-7-2
  • Queries have been modified for the following rules:
    • A3-3-2

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 February 23, 2026 02:21
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 pull request implements MISRA C++ 2023 RULE-6-7-2, which bans the use of most kinds of global variables. The implementation shares constant initialization logic with the existing AUTOSAR rule A3-3-2 by extracting common predicates into a new shared module.

Changes:

  • Extracted constant initialization checking predicates from A3-3-2 to a shared module (Initialization.qll) to enable reuse across multiple rules
  • Implemented new query RULE-6-7-2 that flags global variables (namespace-scoped or static class members) that are either non-const or not constant-initialized
  • Added required infrastructure including package metadata, exclusion modules, and comprehensive test cases

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rules.csv Added entry for RULE-6-7-2 mapping it to the Banned1 package
rule_packages/cpp/Banned1.json New package metadata defining query properties for RULE-6-7-2
cpp/misra/test/rules/RULE-6-7-2/test.cpp Comprehensive test cases covering compliant and non-compliant global variable scenarios
cpp/misra/test/rules/RULE-6-7-2/GlobalVariableUsed.qlref Test reference file pointing to the query implementation
cpp/misra/test/rules/RULE-6-7-2/GlobalVariableUsed.expected Expected test results with 8 non-compliant cases
cpp/misra/src/rules/RULE-6-7-2/GlobalVariableUsed.ql Main query implementation detecting non-const or non-constant-initialized global variables
cpp/common/src/codingstandards/cpp/orderofevaluation/Initialization.qll Shared module containing extracted constant initialization checking logic
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Updated to register the new Banned1 package
cpp/common/src/codingstandards/cpp/exclusions/cpp/Banned1.qll Auto-generated exclusion module for the Banned1 package
cpp/autosar/src/rules/A3-3-2/StaticOrThreadLocalObjectsNonConstantInit.ql Refactored to import shared initialization logic instead of duplicating it
change_notes/2026-02-22-shared-default-initialization-logic.md Change note documenting the refactoring of A3-3-2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@mbaluda mbaluda left a comment

Choose a reason for hiding this comment

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

LGTM!

@mbaluda mbaluda added this pull request to the merge queue Feb 23, 2026
Merged via the queue into main with commit d20c643 Feb 23, 2026
25 checks passed
@mbaluda mbaluda deleted the michaelrfairhurst/banned1-global-variables branch February 23, 2026 15:56
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