Skip to content

Implement package FloatingPoint #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MichaelRFairhurst
Copy link
Contributor

Description

Move DIR-4-15 to be a shared query to support DIR-0-3-1

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:
    • DIR-0-3-1
  • Queries have been modified for the following rules:
    • DIR-4-15

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 Copilot AI review requested due to automatic review settings April 15, 2025 13:50
Copy link
Contributor

@Copilot 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 implements the FloatingPoint package by refactoring the DIR‑4‑15 query to be shared with DIR‑0‑3‑1 and updating test cases to reflect improved floating point guard behavior.

  • Added cosine and sine declarations in the standard-library header.
  • Updated change notes to document modifications in infinity/NaN detection.
  • Updated test cases for misuse of NaN and infinite floating point values with revised compliance annotations.

Reviewed Changes

Copilot reviewed 15 out of 31 changed files in this pull request and generated no comments.

File Description
cpp/common/test/includes/standard-library/math.h Added overloads for cos and sin to support floating point operations.
change_notes/2025-04-14-update-infinity-nan-detection.md Documented the updated behavior for NaN and infinity detection.
c/common/test/rules/misuseofnanfloatingpointvalue/test.c Introduced tests for casting and comparisons involving NaN values.
c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c Updated test cases with revised compliance annotations for infinite and NaN scenarios.
Files not reviewed (16)
  • c/common/test/rules/misuseofinfinitefloatingpointvalue/MisuseOfInfiniteFloatingPointValue.expected: Language not supported
  • c/common/test/rules/misuseofinfinitefloatingpointvalue/MisuseOfInfiniteFloatingPointValue.ql: Language not supported
  • c/common/test/rules/misuseofnanfloatingpointvalue/MisuseOfNaNFloatingPointValue.expected: Language not supported
  • c/common/test/rules/misuseofnanfloatingpointvalue/MisuseOfNaNFloatingPointValue.ql: Language not supported
  • c/misra/src/rules/DIR-4-15/PossibleMisuseOfUndetectedInfinity.ql: Language not supported
  • c/misra/src/rules/DIR-4-15/PossibleMisuseOfUndetectedNaN.ql: Language not supported
  • c/misra/test/rules/DIR-4-15/PossibleMisuseOfUndetectedInfinity.testref: Language not supported
  • c/misra/test/rules/DIR-4-15/PossibleMisuseOfUndetectedNaN.testref: Language not supported
  • cpp/common/src/codingstandards/cpp/FloatingPoint.qll: Language not supported
  • cpp/common/src/codingstandards/cpp/RestrictedRangeAnalysis.qll: Language not supported
  • cpp/common/src/codingstandards/cpp/exclusions/cpp/FloatingPoint.qll: Language not supported
  • cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll: Language not supported
  • cpp/common/src/codingstandards/cpp/rules/misuseofinfinitefloatingpointvalue/MisuseOfInfiniteFloatingPointValue.qll: Language not supported
  • cpp/common/src/codingstandards/cpp/rules/misuseofnanfloatingpointvalue/MisuseOfNaNFloatingPointValue.qll: Language not supported
  • cpp/common/test/includes/standard-library/cmath: Language not supported
  • cpp/common/test/rules/misuseofinfinitefloatingpointvalue/MisuseOfInfiniteFloatingPointValue.expected: Language not supported
Comments suppressed due to low confidence (6)

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:36

  • The compliance annotation for casting a NaN value (for (int)l5 and similarly for (int)l6) now indicates COMPLIANT, which differs from the misuseofnanfloatingpointvalue tests. Please verify that this change reflects the intended behavior for infinite value misuse tests.
(int)l5; // COMPLIANT: Casting NaN to int

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:201

  • The annotation change for castToIntToFloatToInt with a NaN input now marks it as COMPLIANT. Please confirm this accurately reflects the intended behavior in the context of infinite floating point misuse.
castToIntToFloatToInt(0.0 / 0.0); // COMPLIANT

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:209

  • The expected compliance for casting middleNaN is now COMPLIANT. Please verify that this change aligns with the overall intended query behavior compared to similar tests in misuseofnanfloatingpointvalue.
castToInt(middleNaN);           // COMPLIANT

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:211

  • Marking addNaNThenCastToInt with middleNaN as COMPLIANT now differs from previous non-compliant annotations in related tests. Please ensure this change is intentional and consistent with the intended behavior for infinite misuse scenarios.
addNaNThenCastToInt(middleNaN); // COMPLIANT

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:161

  • The false negative annotation for (int)pow(2, p1) indicates a possible detection gap for infinity. It would be beneficial to confirm that this behavior is expected within the updated query logic.
(int)pow(2, p1);      // NON_COMPLIANT[False negative]: likely to be Infinity

c/common/test/rules/misuseofinfinitefloatingpointvalue/test.c:198

  • The false negative label for addOneThenCastToInt with an infinite input suggests a potential oversight in detecting misuse. Please double-check that this annotation is correct and aligns with the overall test expectations.
addOneThenCastToInt(1.0 / 0.0);   // NON_COMPLIANT[False negative]

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