-
Notifications
You must be signed in to change notification settings - Fork 43
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
Implement EssentialTypes
#188
Conversation
Update the rules.csv to identify a new package dealing with the "essential" types identified by MISRA C 2012.
The essential types rules refer to a number of shared MISRA definitions which have been represented in this utility module.
This module calculates and reports the essential type of each given expression in the program, as defined in the MISRA C:2012 standard. The essential type for an expression is calculated based on the AST type of the expression. Where it differs from the standard type, the calculation is overridden to implement the MISRA definition. Various utility methods related to essential types are included.
Adds queries to identify operators where the operands are of an inappropriate essential type, according to the MISRA specified rules.
Adds a query that detects inappropriate addition or subtraction operations on operands of essentially character type.
Adds a query that finds "assignments", as defined by MISRA C 2012, to incompatible essential types.
Adds a query that finds operands to operators with the usual arithmetic conversions that are incompatible.
Adds a query that identifies explicit casts to an inappropriate essential type, according to the conditions set by MISRA C 2012.
Adds a query which identifies "assignments" (as defined by MISRA C 2012) from composite expressions to objects of a wider essential type.
Adds a query which identifies implicit conversions of composite expressions that cause it to be casted to a wider essential type.
Adds a query to check for inappropriate casts of composite expressions to wider essential types.
When computing EssentialTypeCategories, ensure we resolve any typedefs first.
Adds a query that finds loop counters which are essentially floating type.
Ensure when calculating the essential type category, we strip the type specifiers, otherwise we will not match the correct type category.
Adds a query to find uses of memcmp with pointer types which are prohibited by MISRA C.
Updated with final two rules, improved metadata and addressing some bugs related to typedefs and specifiers. Moving out of draft. |
This query looks for use of memcmp, but previously it would not have worked if the user was using C++ and specified std::memcmp. Although this rule is targeted at C, it is one that a user might enable for C++ and expect to work.
Adds a query to detect the use of memcmp to compare null-terminated strings, using global data flow from hard-coded string literals or array literals.
Updated to add Rule 21.14, which also refers to essential types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find anything to pick on here -- great work Luke! I think you just have a failing unit test to take care of.
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
The computation of essential type category was incorrect when the type was a typedef of a boolean.
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
Compiler testing showed that the switch cases were not valid as they required a statement. Added breaks to satisfy this condition.
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
🤖 Beep Boop! clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
🤖 Beep Boop! gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results!
|
🤖 Beep Boop! Matrix Testing for this PR has been completed. If no reports were posted it means this PR does not contain things that need matrix testing! |
Description
This PR adds support for the new
EssentialTypes
package.MISRA C 2012 defines its own a type system on top of C that is more restrictive - in order to identify, in particular, implicit conversions which are surprising or undesirable.
MisraExpressions.qll
library, which provides some utility definitions from both MISRA and the C Standard to help implement the rules. This includes CodeQL classes and predicates representing:stdbool.h
and common hand crafted definitions.+ - * / % + -
).EssentialTypes.qll
library, which provides the following key interfaces:EssentialTypeCategory
- each essential type is part of an essential type category, which we represent here with anewtype
.getEssentialType(Expr e)
- gets the essential type of an expression, if any. Essential types are focused on arithmetic and related types - integrals, floats, booleans and enums.getEssentialTypeCategory(Type essentialType)
- given an essential type, provides the type category.isAssignmentToEssentialType
- use to identify "assignments" to a particular essential type. Note: "assignment" is very broadly defined by Appendix J of MISRA C 2012, and includes function calls, initializers etc.These utilities are used to implement each of the rules. The implementation of the rules is comparatively straight forward given the library, as mostly it's verifying equality or difference of type categories or essential types.
Change request type
.ql
,.qll
,.qls
or unit tests)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
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.
Reviewer
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.