Skip to content

Comments

Move M5-14-1 implementation into shared query with Rule 8.14.1, increase test coverage.#1050

Open
MichaelRFairhurst wants to merge 5 commits intomainfrom
michaelrfairhurst/side-effects-5-rule-8-14-1-rhs-of-and-and-should-have-no-side-effects
Open

Move M5-14-1 implementation into shared query with Rule 8.14.1, increase test coverage.#1050
MichaelRFairhurst wants to merge 5 commits intomainfrom
michaelrfairhurst/side-effects-5-rule-8-14-1-rhs-of-and-and-should-have-no-side-effects

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

Though test coverage didn't quite indicate it so, these two rules are implemented 100% compatibly.

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-8-14-1
  • Queries have been modified for the following rules:
    • M5-14-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!)

Copilot AI review requested due to automatic review settings February 22, 2026 04: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 consolidates the implementations of AUTOSAR M5-14-1 and MISRA C++:2023 RULE-8-14-1 into a single shared query, and adjusts tests/package metadata accordingly.

Changes:

  • Introduces a shared implementation ShortCircuitedPersistentSideEffectShared and rewires M5-14-1 and RULE-8-14-1 to use it.
  • Adds a new rule package/exclusions wiring for RULE-8-14-1 (SideEffects5) and updates RuleMetadata.
  • Replaces per-rule tests with shared-library-backed tests and expands shared test coverage.

Reviewed changes

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

Show a summary per file
File Description
rule_packages/cpp/SideEffects5.json Adds new package metadata for MISRA C++ RULE-8-14-1.
rule_packages/cpp/SideEffects1.json Points M5-14-1 to the new shared implementation.
cpp/misra/test/rules/RULE-8-14-1/ShortCircuitedPersistentSideEffect.testref Hooks RULE-8-14-1 tests to the shared test query.
cpp/misra/src/rules/RULE-8-14-1/ShortCircuitedPersistentSideEffect.ql Adds new MISRA query importing the shared implementation.
cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/test.cpp Adds expanded test cases for the shared implementation.
cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.ql Shared-implementation test query wrapper (generated).
cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.expected Expected results for the shared-implementation tests.
cpp/common/src/codingstandards/cpp/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.qll New shared query implementation module.
cpp/common/src/codingstandards/cpp/exclusions/cpp/SideEffects5.qll Adds exclusions metadata package module for SideEffects5.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers SideEffects5 in exclusions metadata wiring.
cpp/autosar/test/rules/M5-14-1/test.cpp Removes local test file in favor of shared tests.
cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.qlref Removes direct qlref test hook in favor of shared tests.
cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.expected Removes local expected output in favor of shared expected output.
cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperators.testref Adds shared-test hook for M5-14-1.
cpp/autosar/src/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql Replaces inline logic with shared implementation import/config.
change_notes/2026-02-21-share-implementation-of-m5-14-1.md Adds change note for the refactor to shared implementation.

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

Comment on lines +1 to +5
{
"MISRA-C++-2023": {
"RULE-8-14-1": {
"properties": {
"enforcement": "undecidable",
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

RULE-8-14-1 is mapped to package SideEffects3 in rules.csv (line 901), but this PR introduces a new package file SideEffects5.json for the rule. This mismatch will likely break package generation / rule metadata resolution. Align the package name by updating rules.csv to SideEffects5 (or, if SideEffects3 is intended, rename/regenerate the new rule package/exclusion modules accordingly).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.ql No newline at end of file
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The .testref filename is expected to be <query short_name>.testref (see scripts/generate_rules/generate_package_files.py), but this file is named RightHandOperandOfALogicalAndOperators.testref while the query short name for M5-14-1 is RightHandOperandOfALogicalAndOperatorsContainSideEffects. Rename the file to match the query short name so the test runner/generator can discover it correctly.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,27 @@
/**
* @id cpp/misra/short-circuited-persistent-side-effect
* @name RULE-8-14-1: The right-hand operand of a logical && or operator should not contain persistent side effects
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The query metadata @name says "logical && or operator" but the rule/package title and the @description mention both && and ||. Please update @name to include || as well so metadata is consistent across the rule definition.

Suggested change
* @name RULE-8-14-1: The right-hand operand of a logical && or operator should not contain persistent side effects
* @name RULE-8-14-1: The right-hand operand of a logical && or || operator should not contain persistent side effects

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,2 @@
- `M5-14-1` - `RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql`:
- Implementation has been refactor to share logic with Rule 8.14.1. No observable changes to results expected. No newline at end of file
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

Typo/grammar: "has been refactor" should be "has been refactored".

Suggested change
- Implementation has been refactor to share logic with Rule 8.14.1. No observable changes to results expected.
- Implementation has been refactored to share logic with Rule 8.14.1. No observable changes to results expected.

Copilot uses AI. Check for mistakes.
} // COMPLIANT - noexcept operands not evaluated

if (1 || (typeid(f6()) == typeid(f5()))) {
} // NON_COMPLIANT - typeid operands not evaluated, but the ==operator is
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

This comment is incomplete (ends at "but the ==operator is"). Either finish the sentence or remove it to avoid confusion when reading the test case.

Suggested change
} // NON_COMPLIANT - typeid operands not evaluated, but the ==operator is
} // NON_COMPLIANT - typeid operands are not evaluated, but the == operator is, so its operands are evaluated

Copilot uses AI. Check for mistakes.
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.

1 participant