Skip to content

Prepare MISRA C:2025 development with end-to-end examples - #1216

Open
mbaluda wants to merge 3 commits into
mainfrom
misra-c-2025-development
Open

mbaluda wants to merge 3 commits into
mainfrom
misra-c-2025-development

Conversation

@mbaluda

@mbaluda mbaluda commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR updates the project to support the development of MISRA C:2025 queries while retaining support for older editions.

Seven different categories of guideline changes are identified. For each category, this PR provides one complete end-to-end implementation with tests.
The remaining guideline work is tracked in rules-misra-c-2025.csv.

Implemented Examples By Category

Category Implemented Guidelines End-to-End Example
Renumber Rule1.2→Dir1.2 Rule21.1→Rule20.15 Rule21.2→Rule5.10 Reuse existing detectors, preserve legacy query IDs and select the appropriate identities in current/older suites. Existing product tests are reused through testref files.
Disapply Rule 15.5 Make the 2025 query Disapplied by default and support reactivation through recategorization, while preserving the legacy Advisory identity and reusing its detector/product coverage.
Clarification Rule 21.8 Extend Rule 21.8 to detect enabled assertions that call non-returning handlers such as __assert_fail, using the standard-library model. Add tests for enabled assertions, NDEBUG-disabled assertions, and unrelated non-returning calls. Existing banned-function checks remain unchanged.
Merge Rules 17.5 and 17.6 Retain Rule 17.5 array-size contract checks and remove the separate Rule 17.6 static-parameter prohibition from current suites. Older suites retain the legacy prohibition.
Expand Rule 17.3 Cover implicit declarations accepted as compiler extensions in C99 and C11. The existing detector already handles these cases.
Refine Dir 4.6 Provide the integer-only 2025 variant while retaining the legacy numerical-type query. Floating-point declarations and aliases are excluded by the 2025 variant.
New Rule 8.18 Implement detection of tentative file-scope definitions in headers, with declaration-level filtering and compliant/noncompliant cases for initializers, extern declarations, static objects, redeclarations, macros, and source-file/local controls.

The supporting changes update the rule inventory, schema, generators, suites, documentation, release metadata handling, and validation scripts. Unchanged queries keep their existing standard metadata; only new or modified variants use MISRA-C-2025.

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:
    • DIR-1-2
    • DIR-4-6
    • RULE-5-10
    • RULE-8-18
    • RULE-15-5
    • RULE-20-15

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 auto review requested due to automatic review settings November 3, 2026 17:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved rule-detection defects, ineffective test fixtures, and permissive edition-tag validation can hide violations and leave new MISRA-C-2025 coverage unverified.

8 open issues
What changed in this PR

Prepares the CodeQL coding-standards project for MISRA C:2025 development through representative end-to-end examples, while retaining older-edition suites. This establishes migration infrastructure, not complete coverage or qualification.

Changes:

  • Adds and adapts queries, metadata, and tests for seven categories of guideline changes.
  • Updates edition selection and supports reactivating guidelines that are Disapplied by default.
  • Extends generation, validation, release tooling, and documentation for the migration.
File Description
scripts/​verify_rule_package_consistency.py Extends MISRA C tag validation.
scripts/​validate-amendments-csv.py Allows historical amendment mappings.
scripts/​release/​generate_release_notes.py Adds the 2025 release-notes category.
scripts/​release/​create_supported_rules_list.py Adds the 2025 coverage category.
scripts/​PSCodingStandards/​Get-TestDirectory.ps1 Maps 2025 queries to MISRA tests.
scripts/​PSCodingStandards/​Config.ps1 Registers the 2025 suite.
scripts/​matrix_testing/​CreateMatrixTestReport.ps1 Accepts 2025 matrix-test selection.
scripts/​generate_rules/​generate_package_files.py Supports 2025 metadata and test reuse.
scripts/​generate_rules/​coding_standards_utils.py Copies tags and reuses help templates.
schemas/​rule-package.schema.json Adds 2025 metadata and categories.
rules.csv Updates the guideline inventory.
rules-misra-c-2025.csv Tracks migration categories and progress.
rule_packages/​c/​Types1.json Registers refined and legacy type queries.
rule_packages/​c/​Static.json Marks Rule 17.6 as legacy.
rule_packages/​c/​Statements5.json Registers Disapplied Rule 15.5.
rule_packages/​c/​Preprocessor4.json Registers renumbered Rule 20.15.
rule_packages/​c/​Pointers1.json Records planned Rule 11.11.
rule_packages/​c/​Language3.json Registers renumbered Directive 1.2.
rule_packages/​c/​Declarations6.json Adds Rule 17.3 applicability.
rule_packages/​c/​Declarations5.json Registers new declaration guidelines.
rule_packages/​c/​Declarations1.json Registers renumbered Rule 5.10.
rule_packages/​c/​Contracts7.json Records planned Rule 19.3.
rule_packages/​c/​Contracts6.json Adds Rule 17.5 applicability.
rule_packages/​c/​Banned.json Adds Rule 21.8 applicability.
docs/​user_manual.md Explains edition selection and reactivation.
docs/​design/​guideline_recategorization.md Documents promotions from Disapplied.
cpp/​common/​test/​guideline_recategorizations/​DisappliedRecategorizations.ql Tests Disapplied-category promotions.
cpp/​common/​test/​guideline_recategorizations/​DisappliedRecategorizations.expected Records expected promotion results.
cpp/​common/​src/​codingstandards/​cpp/​guideline_recategorizations/​GuidelineRecategorizations.qll Implements promotions from Disapplied.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Types1.qll Registers integer-type query exclusions.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Statements5.qll Registers Disapplied query metadata.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Preprocessor4.qll Registers Rule 20.15 exclusions.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Language3.qll Registers Directive 1.2 exclusions.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Declarations5.qll Registers Rule 8.18 exclusions.
cpp/​common/​src/​codingstandards/​cpp/​exclusions/​c/​Declarations1.qll Registers Rule 5.10 exclusions.
change_notes/​2026-11-03-misra-c-2025-query-updates.md Records suite and query changes.
c/​misra/​test/​rules/​RULE-8-18/​test.c Adds source-file and local controls.
c/​misra/​test/​rules/​RULE-8-18/​sample.h Adds tentative-definition cases.
c/​misra/​test/​rules/​RULE-8-18/​DefinitionsInHeader.qlref Selects the new header query.
c/​misra/​test/​rules/​RULE-8-18/​DefinitionsInHeader.expected Records expected header alerts.
c/​misra/​test/​rules/​RULE-5-10/​ReservedIdentifierDeclared.testref References shared reserved-identifier coverage.
c/​misra/​test/​rules/​RULE-21-8/​test.c Adds enabled and disabled assertions.
c/​misra/​test/​rules/​RULE-21-8/​TerminationFunctionsOfStdlibhUsed.expected Adds the enabled-assertion result.
c/​misra/​test/​rules/​RULE-21-8/​assert.h Supplies a local assertion fixture.
c/​misra/​test/​rules/​RULE-20-15/​ReservedMacroName.testref References legacy reserved-macro coverage.
c/​misra/​test/​rules/​RULE-17-5/​UseOfArrayStatic_MISRA_C_2012.qlref Selects the legacy static-parameter query.
c/​misra/​test/​rules/​RULE-17-5/​UseOfArrayStatic_MISRA_C_2012.expected Records the legacy prohibition result.
c/​misra/​test/​rules/​RULE-17-5/​test_MISRA_C_2025.c Tests static and ordinary array contracts.
c/​misra/​test/​rules/​RULE-17-5/​ArrayFunctionArgumentNumberOfElements.expected Adds array-contract results.
c/​misra/​test/​rules/​RULE-17-3/​test_c99.c Adds C99 implicit-declaration coverage.
c/​misra/​test/​rules/​RULE-17-3/​FunctionDeclaredImplicitly.expected Adds the C99 expected alert.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​test.c Reuses the exit-count fixture.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​SinglePointOfExit.qlref Selects the unconfigured 2025 query.
c/​misra/​test/​rules/​RULE-15-5/​unconfigured/​SinglePointOfExit.expected Expects default suppression.
c/​misra/​test/​rules/​RULE-15-5/​SinglePointOfExit.testref References legacy exit-count coverage.
c/​misra/​test/​rules/​RULE-15-5/​coding-standards.yml Configures promotion to Required.
c/​misra/​test/​rules/​RULE-15-5/​coding-standards.xml Stores generated recategorization configuration.
c/​misra/​test/​rules/​DIR-4-6/​test.c Clarifies edition-specific test annotations.
c/​misra/​test/​rules/​DIR-4-6/​test_MISRA_C_2025.c Adds floating-point alias controls.
c/​misra/​test/​rules/​DIR-4-6/​PlainNumericalTypeUsedOverExplicitTypedef.expected Records legacy floating-point alias results.
c/​misra/​test/​rules/​DIR-4-6/​PlainIntegerTypeUsedOverExplicitTypedef.qlref Selects the integer-only variant.
c/​misra/​test/​rules/​DIR-4-6/​PlainIntegerTypeUsedOverExplicitTypedef.expected Records integer-only expected results.
c/​misra/​test/​rules/​DIR-1-2/​LanguageExtensionsShouldBeMinimized.testref References legacy extension coverage.
c/​misra/​src/​rules/​RULE-8-18/​DefinitionsInHeader.ql Detects tentative definitions in headers.
c/​misra/​src/​rules/​RULE-5-10/​ReservedIdentifierDeclared.ql Adds the renumbered identifier wrapper.
c/​misra/​src/​rules/​RULE-21-8/​TerminationFunctionsOfStdlibhUsed.ql Adds 2025 applicability metadata.
c/​misra/​src/​rules/​RULE-21-2/​DoNotDeclareAReservedIdentifier.ql Marks the identifier wrapper as legacy.
c/​misra/​src/​rules/​RULE-21-1/​DefineAndUndefUsedOnReservedIdentifierOrMacroName.ql Reuses reserved-macro detection as legacy.
c/​misra/​src/​rules/​RULE-20-15/​ReservedMacroName.ql Adds the renumbered macro wrapper.
c/​misra/​src/​rules/​RULE-17-6/​UseOfArrayStatic.ql Marks the prohibition as legacy.
c/​misra/​src/​rules/​RULE-17-5/​ArrayFunctionArgumentNumberOfElements.ql Adds 2025 applicability metadata.
c/​misra/​src/​rules/​RULE-17-3/​FunctionDeclaredImplicitly.ql Adds 2025 applicability metadata.
c/​misra/​src/​rules/​RULE-15-5/​SinglePointOfExit.ql Adds the Disapplied 2025 wrapper.
c/​misra/​src/​rules/​RULE-15-5/​FunctionReturnCondition.ql Reuses exit detection as legacy.
c/​misra/​src/​rules/​RULE-1-2/​LanguageExtensionsShouldNotBeUsed.ql Marks the extension wrapper as legacy.
c/​misra/​src/​rules/​DIR-4-6/​PlainNumericalTypeUsedOverExplicitTypedef.ql Reuses numerical-type detection as legacy.
c/​misra/​src/​rules/​DIR-4-6/​PlainIntegerTypeUsedOverExplicitTypedef.ql Adds the integer-only directive variant.
c/​misra/​src/​rules/​DIR-1-2/​LanguageExtensionsShouldBeMinimized.ql Adds the renumbered extension wrapper.
c/​misra/​src/​codingstandards/​c/​misra/​SinglePointOfExit.qll Extracts reusable exit detection.
c/​misra/​src/​codingstandards/​c/​misra/​ReservedMacroNames.qll Extracts reusable reserved-macro detection.
c/​misra/​src/​codingstandards/​c/​misra/​PlainNumericalTypes.qll Shares type detection and floating-type filtering.
c/​misra/​src/​codeql-suites/​misra-c-strict.qls Updates the suite description to 2025.
c/​misra/​src/​codeql-suites/​misra-c-required.qls Excludes legacy Required wrappers.
c/​misra/​src/​codeql-suites/​misra-c-mandatory.qls Excludes legacy Mandatory wrappers.
c/​misra/​src/​codeql-suites/​misra-c-default.qls Switches default selection away from legacy wrappers.
c/​misra/​src/​codeql-suites/​misra-c-audit.qls Updates the suite description to 2025.
c/​misra/​src/​codeql-suites/​misra-c-advisory.qls Excludes legacy Advisory wrappers.
c/​misra/​src/​codeql-suites/​misra-c-2023.qls Adds explicit older-edition selection.

Review effort: Max (auto)

Comment thread c/misra/test/rules/RULE-17-3/test_c99.c Resolved
Comment thread c/misra/test/rules/RULE-21-8/assert.h Resolved
mbaluda and others added 2 commits November 3, 2026 19:08
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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