Michaelrfairhurst/rule 4 1 3 detect data races#1077
Merged
mbaluda merged 6 commits intomichaelrfairhurst/package-undefined-behaviorfrom Mar 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.qlinto a new shared libraryPossibleDataRaceBetweenThreadsShared.qllundercpp/common/src/codingstandards/cpp/rules/. - Added a new C++ MISRA 2023 query
RULE-4-1-3/PossibleDataRaceBetweenThreads.qlthat instantiates the shared library with C++ object/sub-object types. - Added test infrastructure (shared test files,
.testreffiles,.expectedfiles, 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 |
...ards/cpp/rules/possibledataracebetweenthreadsshared/PossibleDataRaceBetweenThreadsShared.qll
Show resolved
Hide resolved
cpp/misra/src/rules/RULE-4-1-3/PossibleDataRaceBetweenThreads.ql
Outdated
Show resolved
Hide resolved
…aelrfairhurst/rule-4-1-3-detect-data-races
…aelrfairhurst/rule-4-1-3-detect-data-races
…aelrfairhurst/rule-4-1-3-detect-data-races
mbaluda
approved these changes
Mar 11, 2026
d7d4769
into
michaelrfairhurst/package-undefined-behavior
18 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-4-1-3DIR-5-1Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
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.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
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
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.
Reviewer
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.