- Notifications
You must be signed in to change notification settings - Fork70
ImplementEssentialTypes#188
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 definitionswhich have been represented in this utility module.
This module calculates and reports the essential type of each givenexpression in the program, as defined in the MISRA C:2012 standard.The essential type for an expression is calculated based on the ASTtype 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 aninappropriate essential type, according to the MISRA specified rules.
Adds a query that detects inappropriate addition or subtractionoperations on operands of essentially character type.
Adds a query that finds "assignments", as defined by MISRA C 2012, toincompatible essential types.
Adds a query that finds operands to operators with the usual arithmeticconversions that are incompatible.
Adds a query that identifies explicit casts to an inappropriateessential 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 compositeexpressions that cause it to be casted to a wider essential type.
Adds a query to check for inappropriate casts of composite expressionsto wider essential types.
When computing EssentialTypeCategories, ensure we resolve any typedefsfirst.
Adds a query that finds loop counters which are essentially floatingtype.
Ensure when calculating the essential type category, we strip the typespecifiers, otherwise we will not match the correct type category.
Adds a query to find uses of memcmp with pointer types which areprohibited by MISRA C.
lcartey commentedFeb 14, 2023
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 haveworked if the user was using C++ and specified std::memcmp.Although this rule is targeted at C, it is one that a user might enablefor C++ and expect to work.
Adds a query to detect the use of memcmp to compare null-terminatedstrings, using global data flow from hard-coded string literals orarray literals.
lcartey commentedFeb 15, 2023
Updated to add Rule 21.14, which also refers to essential types. |
jsinglet left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
jsinglet commentedMar 8, 2023
🤖 Beep Boop! Matrix Testing for this PR has beencompleted. 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 typewas 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 theyrequired a statement. Added breaks to satisfy this condition.
🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop! Matrix Testing for this PR has beencompleted. If no reports were posted it means this PR does not contain things that need matrix testing! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop!gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 8, 2023
🤖 Beep Boop! Matrix Testing for this PR has beencompleted. 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. |
jsinglet commentedMar 9, 2023
🤖 Beep Boop!clang/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 9, 2023
🤖 Beep Boop!gcc/cpp/x86_64 Matrix Testing for this PR has been completed but I didn't find anything to test! |
jsinglet commentedMar 9, 2023
🤖 Beep Boop!gcc/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 9, 2023
🤖 Beep Boop!clang/c/x86_64 Matrix Testing for this PR has been completed. See below for the results! |
jsinglet commentedMar 9, 2023
🤖 Beep Boop! Matrix Testing for this PR has beencompleted. If no reports were posted it means this PR does not contain things that need matrix testing! |
Uh oh!
There was an error while loading.Please reload this page.
Description
This PR adds support for the new
EssentialTypespackage.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.qlllibrary, 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.hand common hand crafted definitions.+ - * / % + -).EssentialTypes.qlllibrary, 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,.qlsor 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 ofshared 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.