github / codeql-coding-standards

This repository contains CodeQL queries and libraries which support various Coding Standards.
MIT License
129 stars 59 forks source link

A0-1-1: Fix useless assignment false positive on constexpr array size #732

Closed fjatWbyT closed 1 month ago

fjatWbyT commented 1 month ago

Description

Addresses false positive like the one in #690 in another AUTOSAR ule.

Change request type

Rules with added or modified queries

Release 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

Reviewer

fjatWbyT commented 1 month ago

Hello @lcartey,

I looked for unit tests analogous to the one updated in #690, in this case for A0-1-1 "useless assignment", in contrast with M0-1-9 "no dead code", but couldn't find any already existing. I run locally the (153) tests in cpp/common/test/rules after applying the change and all pass. I could find tests for useless assignment in deviations, but I doubt those need updating for this change since there's no new deviation.

Does it make sense to add explicit coverage for A0-1-1? I wonder if it would be sensible to (a) add a new directory cpp/common/uselessassignment, (b) update configuration so that the ones in cpp/common/deadcode are also run against A0-1-1, or (c) something else :) On the one hand, I think that covering these other isUselessSsaDefinition predicate and InterestingStackVariable class (assuming they aren't already) would be an improvement. On the other hand, since they are (at least partially) used by the dead code qll, it might not be worth further updates.

lcartey commented 1 month ago

Hi @fjatWbyT! Thanks for the PR.

The test cases for A0-1-1 live here: https://github.com/github/codeql-coding-standards/tree/main/cpp/autosar/test/rules/A0-1-1

The tests live in a common directory when one query implementation is shared by multiple rules - for example, where an AUTOSAR and CERT C++ rule cover the same issue. A0-1-1 is only required to be reported to AUTOSAR, so the tests live in the AUTOSAR test directory, under the rule ID.

fjatWbyT commented 1 month ago

Aaah, it is clear now. Thank you very much for the explanation. I will update the PR with extra coverage for this case in that file.