Skip to content

Conversation

@lcartey
Copy link
Contributor

@lcartey lcartey commented Jan 11, 2023

Description

This PR adds queries for all the rules in the DeadCode package.

Rules 2.1, 2.2, 2.3 and 2.7 are shared implementations with C++ equivalents, where the new shared implementations are direct copies of the existing equivalent C++ rules.

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 2.1
    • Rule 2.2
    • Rule 2.3
    • Rule 2.4
    • Rule 2.5
    • Rule 2.6
    • Rule 2.7
  • Queries have been modified for the following rules:
    • M0-1-9

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 - for ``M0-1-9`.
  • 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!)

lcartey added 12 commits January 8, 2023 23:27
Create shared implementations in preparation for the C queries.
Add MISRA Rule 2.1 as an import of the UnreachableCode query.
Add support for Rule 2.2 by adoptiing the DeadCode shared query. A small
modification has been made to ensure results which include macro
expansions are reported, unless the macro fully generates the statement.
Adds a query to check for unused type declarations, based on the shared
library.

Note: the expected results for the C++ test case have been updated to
include a compiler generated class. This is because shared queries do
not properly apply the exclusion mechanism. See:
https://github.com/github/coding-standards-team/issues/1126
Add a query for finding unused tags. This query uses `TypeMention`s to
identify tags that are never referenced. Note: this query tries to
exclude tags generated from macros, but this is not currently working due
to a bug in the CodeQL CLI 2.9.4.
Adds a query to find unused macro declarations. The query is mostly
straightforward, however #undefs are not connected in our database
schema with the #defines they undefine. This means that we cannot
accurately identify unused macros when there is a sequence of defs
and undefs.
Adds a query to find unused labels. We consider a label unused if we
never "goto" the label and never take the address of the label.
Adds a shared implementation query for identifying unused parameters.
@lcartey lcartey requested a review from jsinglet January 11, 2023 23:36
Copy link
Contributor

@jsinglet jsinglet left a comment

Choose a reason for hiding this comment

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

Great work Luke -- just a few items with formatting I think and then it is GTG after tests pass.

@lcartey
Copy link
Contributor Author

lcartey commented Jan 13, 2023

Comments addressed, I think.

Copy link
Contributor

@jsinglet jsinglet left a comment

Choose a reason for hiding this comment

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

Sorry about the false alarm on the formatting, looks good now! :)

@jsinglet jsinglet merged commit 48f7ef5 into main Jan 13, 2023
@jsinglet jsinglet deleted the lcartey/dead-code branch January 13, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants