Skip to content

Conversation

@knewbury01
Copy link
Collaborator

@knewbury01 knewbury01 commented Jan 15, 2026

Description

adds a package for linkage1 - contains 2 rules which are shared implementations

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-5-1
    • RULE-6-0-2
  • Queries have been modified for the following rules:
    • A3-3-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!)

@knewbury01 knewbury01 self-assigned this Jan 15, 2026
Copilot AI review requested due to automatic review settings January 15, 2026 19:12
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 adds a new "Linkage1" package containing shared implementations for two MISRA-C++-2023 rules (RULE-6-0-2 and RULE-6-5-1). These rules share implementation with existing AUTOSAR rules (A3-1-4 and A3-3-1). The PR refactors existing code to use shared query implementations, migrates tests to common locations, and updates metadata accordingly.

Changes:

  • Adds Linkage1 package with shared implementations for external linkage array size and declaration rules
  • Refactors AUTOSAR rules A3-1-4 and A3-3-1 to use shared implementations
  • Adds MISRA-C++-2023 rules RULE-6-0-2 and RULE-6-5-1 that reuse these shared implementations

Reviewed changes

Copilot reviewed 27 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rules.csv Updates package assignments for RULE-6-0-2 and RULE-6-5-1 to use new Linkage1 package
rule_packages/cpp/Scope.json Renames short_name to include "Autosar" suffix and adds shared_implementation_short_name
rule_packages/cpp/Linkage1.json New package definition for MISRA-C++-2023 linkage rules
rule_packages/cpp/Includes.json Adds shared_implementation_short_name to existing A3-3-1 rule
cpp/misra/test/rules/RULE-6-5-1/ExternalLinkageNotDeclaredInHeaderFileMisra.testref Test reference pointing to shared test implementation
cpp/misra/test/rules/RULE-6-0-2/ExternalLinkageArrayWithoutExplicitSizeMisra.testref Test reference pointing to shared test implementation
cpp/misra/src/rules/RULE-6-5-1/ExternalLinkageNotDeclaredInHeaderFileMisra.ql New MISRA query using shared implementation
cpp/misra/src/rules/RULE-6-0-2/ExternalLinkageArrayWithoutExplicitSizeMisra.ql New MISRA query using shared implementation
cpp/common/test/rules/externallinkagenotdeclaredinheaderfile/test.hpp Shared test header file
cpp/common/test/rules/externallinkagenotdeclaredinheaderfile/test.cpp Shared test implementation with COMPLIANT/NON_COMPLIANT cases
cpp/common/test/rules/externallinkagenotdeclaredinheaderfile/ExternalLinkageNotDeclaredInHeaderFile.ql Shared test query
cpp/common/test/rules/externallinkagenotdeclaredinheaderfile/ExternalLinkageNotDeclaredInHeaderFile.expected Expected test results
cpp/common/test/rules/externallinkagearraywithoutexplicitsize/test.cpp Shared test implementation with COMPLIANT/NON_COMPLIANT cases
cpp/common/test/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.ql Shared test query
cpp/common/test/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.expected Expected test results
cpp/common/src/codingstandards/cpp/rules/externallinkagenotdeclaredinheaderfile/ExternalLinkageNotDeclaredInHeaderFile.qll Shared implementation for external linkage declaration rule
cpp/common/src/codingstandards/cpp/rules/externallinkagearraywithoutexplicitsize/ExternalLinkageArrayWithoutExplicitSize.qll Shared implementation for array size rule
cpp/common/src/codingstandards/cpp/exclusions/cpp/Scope.qll Renames query to include "Autosar" suffix
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Imports and registers new Linkage1 package
cpp/common/src/codingstandards/cpp/exclusions/cpp/Linkage1.qll New exclusions file for Linkage1 package
cpp/autosar/test/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.testref Updated to point to shared test
cpp/autosar/test/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.qlref Removed (migrated to testref)
cpp/autosar/test/rules/A3-1-4/test.cpp Removed (migrated to common tests)
cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSizeAutosar.testref Updated to point to shared test
cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.qlref Removed (migrated to testref)
cpp/autosar/test/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.expected Removed (migrated to common tests)
cpp/autosar/src/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.ql Refactored to use shared implementation
cpp/autosar/src/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSizeAutosar.ql New file using shared implementation (renamed)
cpp/autosar/src/rules/A3-1-4/ExternalLinkageArrayWithoutExplicitSize.ql Removed (renamed to ExternalLinkageArrayWithoutExplicitSizeAutosar.ql)
change_notes/2026-01-15-a3-1-4-extern-to-full.md Change note documenting the refactoring

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

Comment on lines +3 to +4
* Introducing a function or object with external linkage outside of a header file can
* cause developer confusion about its translation unit access semantics.
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The documentation comment describes the wrong issue. This file is about arrays with external linkage declared without explicit size, but the comment describes "Introducing a function or object with external linkage outside of a header file" which is actually the description for the other rule (ExternalLinkageNotDeclaredInHeaderFile). The comment should describe the array size issue instead.

Suggested change
* Introducing a function or object with external linkage outside of a header file can
* cause developer confusion about its translation unit access semantics.
* Declaring an array with external linkage without explicitly specifying its size
* can lead to unclear or inconsistent expectations about the array's bounds.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems copilot is right here

"' with external linkage doesn't specify the size explicitly." and
hasExternalLinkage(v) and
not arrayType.hasArraySize() and
// Holds is if declEntry is an array variable declaration (not a definition)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

Grammatical error: "Holds is if" should be "Holds if". Remove the word "is".

Suggested change
// Holds is if declEntry is an array variable declaration (not a definition)
// Holds if declEntry is an array variable declaration (not a definition)

Copilot uses AI. Check for mistakes.
@knewbury01 knewbury01 requested review from MichaelRFairhurst, jeongsoolee09, jketema and mbaluda and removed request for jketema January 15, 2026 19:16
Copy link
Collaborator

@MichaelRFairhurst MichaelRFairhurst left a comment

Choose a reason for hiding this comment

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

Just small suggestions!

This looks great!

And ❗ great find ❗ that, not only could this logic be shared, but also, it could be improved!! 🎉

@@ -0,0 +1,2 @@
- `A3-1-4` - `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql`:
- `ExternalLinkageArrayWithoutExplicitSize.ql` has been renamed to `ExternalLinkageArrayWithoutExplicitSizeAutosar.ql` to reflect shared query implementation. Additionally the query previously only detected explicit uses of `extern` to determine external linkage, and now would catch other cases that are possible where it is external linkage and an array is declared without an explicit size.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very nice to catch and fix this!

Comment on lines +3 to +4
* Introducing a function or object with external linkage outside of a header file can
* cause developer confusion about its translation unit access semantics.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems copilot is right here

// Structs must have at least one non-flexible array member.
int foo;

// static data members have external linkage - but not currently detected in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a case for this?

static int[] x; // NON_COMPLIANT[False negative]

"The declared array '" + declEntry.getName() +
"' with external linkage doesn't specify the size explicitly." and
hasExternalLinkage(v) and
not arrayType.hasArraySize() and
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised that hasArraySize was working before..!

Below are a bunch of thoughts that kind of go down a rabbit hole. Consider it 100% up to you how you want to proceed -- you could file a bug and copy my comment, or you can explore it, add tests, etc.

We may not be able to do much about it, but it may be worth adding some .hpp test cases to see if the following are FNs:

// test.hpp
int header_only[]; // NON_COMPLIANT
int header_and_cpp[]; // NON_COMPLIANT

// test.cpp
#include "test.hpp"
// definition associated with a declaration from test.hpp
int header_and_cpp[10] = ...

Basically, I fear that header_and_cpp[] will be a false negative. It should be extracted as one Variable, with one Type -- that type probably being an int array of size 10.

If this is a FN we can write NON_COMPLIANT[False negative] along with an explanatory comment, and I'm not sure if we have any recourse to fix it if so. However, we likely don't have to fix it.....if it is a FN, we probably also want to add a test like:

// test.hpp
// an array declaration that's defined in test1.cpp but not test2.cpp
int defined_in_test1_cpp[]; // NON_COMPLIANT

// test1.cpp
int defined_in_test1_cpp[10] = ...;

// test2.cpp
// This file exists to _not_ do the following:
// int defined_in_test1_cpp[10] = ...;
// So that we can test that a violation of the One Definition Rule is caught in this case

My guess is that this will be correctly reported as non compliant because we would have two variables (a violation of ODR), and one would have no size. This would means the NON_COMPLIANT[False negative] is low impact.

Let me know if any of this is unclear, feel free to reach out via chat etc. Up to you what next steps you think may be best!

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