Skip to content

Michaelrfairhurst/rule 4 1 3 detect data races#1077

Merged
mbaluda merged 6 commits intomichaelrfairhurst/package-undefined-behaviorfrom
michaelrfairhurst/rule-4-1-3-detect-data-races
Mar 11, 2026
Merged

Michaelrfairhurst/rule 4 1 3 detect data races#1077
mbaluda merged 6 commits intomichaelrfairhurst/package-undefined-behaviorfrom
michaelrfairhurst/rule-4-1-3-detect-data-races

Conversation

@MichaelRFairhurst
Copy link
Collaborator

@MichaelRFairhurst MichaelRFairhurst commented Mar 10, 2026

Description

One commonly referred to kind of undefined behavior in the standard is data races. We can import this from our c query.

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-4-1-3
  • Queries have been modified for the following rules:
    • DIR-5-1

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

@MichaelRFairhurst MichaelRFairhurst marked this pull request as ready for review March 10, 2026 00:59
Copilot AI review requested due to automatic review settings March 10, 2026 00:59
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 refactors the existing C MISRA DIR-5-1 data race detection query into a shared library (PossibleDataRaceBetweenThreadsShared.qll) and adds a new C++ MISRA 2023 RULE-4-1-3 query that reuses the same shared implementation. The shared library uses a parameterized module pattern with a config signature to support different object identity and sub-object models for C vs C++.

Changes:

  • Extracted the inline data race detection logic from c/misra/src/rules/DIR-5-1/PossibleDataRaceBetweenThreads.ql into a new shared library PossibleDataRaceBetweenThreadsShared.qll under cpp/common/src/codingstandards/cpp/rules/.
  • Added a new C++ MISRA 2023 query RULE-4-1-3/PossibleDataRaceBetweenThreads.ql that instantiates the shared library with C++ object/sub-object types.
  • Added test infrastructure (shared test files, .testref files, .expected files, exclusions, and metadata) for both the C and C++ variants.

Reviewed changes

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

Show a summary per file
File Description
rule_packages/cpp/Undefined.json Adds new PossibleDataRaceBetweenThreads query entry under RULE-4-1-3
rule_packages/c/Concurrency9.json Adds shared_implementation_short_name to DIR-5-1 query
cpp/misra/src/rules/RULE-4-1-3/PossibleDataRaceBetweenThreads.ql New C++ query file using the shared library
cpp/misra/test/rules/RULE-4-1-3/PossibleDataRaceBetweenThreads.testref Points to shared C++ test
cpp/common/src/codingstandards/cpp/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.qll New shared library with parameterized module
cpp/common/test/rules/possibledataracebetweenthreadsshared/test.cpp C++ test file with compliant and non-compliant cases
cpp/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql C++ shared test query
cpp/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.expected Expected results for C++ test
cpp/common/src/codingstandards/cpp/exclusions/cpp/Undefined.qll Exclusion definitions for the Undefined package
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers Undefined package in metadata
change_notes/2026-03-09-possible-data-race-between-threads-shared.md Change note for the refactoring
c/misra/src/rules/DIR-5-1/PossibleDataRaceBetweenThreads.ql Refactored to use shared library
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.qlref Deleted (replaced by .testref)
c/misra/test/rules/DIR-5-1/PossibleDataRaceBetweenThreads.testref Points to shared C test
c/common/test/rules/possibledataracebetweenthreadsshared/test.c C test file with compliant and non-compliant cases
c/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.ql C shared test query
c/common/test/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.expected Expected results for C test

@mbaluda mbaluda merged commit d7d4769 into michaelrfairhurst/package-undefined-behavior Mar 11, 2026
18 checks passed
@mbaluda mbaluda deleted the michaelrfairhurst/rule-4-1-3-detect-data-races branch March 11, 2026 11:09
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