-
Notifications
You must be signed in to change notification settings - Fork 77
Implement rule 28-6-1, only move non-const lvalues #992
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
MichaelRFairhurst
wants to merge
13
commits into
main
Choose a base branch
from
michaelrfairhurst/preconditions5-only-std-move-lvalues
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
98e981d
Add new library, backported to a small handful of queries, for resolv…
MichaelRFairhurst 3d0722e
Add qlpack, qlpack locks for qtil
MichaelRFairhurst d20e6a5
Fix typos & CvConstRef.resolve() issue detected by copilot code review
MichaelRFairhurst 9c70506
Implement preconditions rule 28-6-1, std::move of rvalue or const lva…
MichaelRFairhurst ae3ce28
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/res…
MichaelRFairhurst e955db7
Merge remote-tracking branch 'origin/michaelrfairhurst/resolves-to-ty…
MichaelRFairhurst 9bb97a9
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/res…
MichaelRFairhurst 35010f0
Merge remote-tracking branch 'origin/michaelrfairhurst/resolves-to-ty…
MichaelRFairhurst 0c34a91
Merge branch 'main' into michaelrfairhurst/resolves-to-type-lib
MichaelRFairhurst a82b0ff
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/pre…
MichaelRFairhurst a60f9b5
Merge branch 'main' into michaelrfairhurst/resolves-to-type-lib
MichaelRFairhurst 92fe391
typo fix
MichaelRFairhurst 6faa015
Merge remote-tracking branch 'origin/michaelrfairhurst/resolves-to-ty…
MichaelRFairhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| - `INT36-C` - `ConvertingAPointerToIntegerOrIntegerToPointer.ql`: | ||
| - Integrated new type resolution modules to fully handle typedefs and ignore cv-qualifiers during type comparisons, such as in detecting int types, pointer types, (u)intptr_t types, and void pointer types. | ||
| - `RULE-22-12`, `RULE-22-13`, `RULE-22-14` - `NonstandardUseOfThreadingObject.ql`, `ThreadingObjectWithInvalidStorageDuration.ql`, `MutexNotInitializedBeforeUse.ql`: | ||
| - Integrated new type resolution modules to handle typedefs when identifying threading object types. | ||
| - `RULE-9-5-1` - `LegacyForStatementsShouldBeSimple.ql`: | ||
| - Refactor to integrate new type resolution, no change in functionality expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import cpp | ||
|
|
||
| /** | ||
| * Get an expression's value category as a ValueCategory object. | ||
| * | ||
| * Note that the standard cpp library exposes `is{_}ValueCategory` predicates, but they do not | ||
| * correctly work with conversions. This function is intended to give the correct answer in the | ||
| * presence of conversions such as lvalue-to-rvalue conversion. | ||
| */ | ||
| ValueCategory getValueCategory(Expr e) { | ||
| not exists(e.getConversion()) and | ||
| result = getDirectValueCategory(e) | ||
| or | ||
| if e.getConversion() instanceof ReferenceToExpr | ||
| then result = getDirectValueCategory(e) | ||
| else result = getDirectValueCategory(e.getConversion()) | ||
| } | ||
|
|
||
| private ValueCategory getDirectValueCategory(Expr e) { | ||
| if e.isLValueCategory() | ||
| then result = LValue(e.getValueCategoryString()) | ||
| else | ||
| if e.isPRValueCategory() | ||
| then result = PRValue(e.getValueCategoryString()) | ||
| else | ||
| if e.isXValueCategory() | ||
| then result = XValue(e.getValueCategoryString()) | ||
| else none() | ||
| } | ||
|
|
||
| newtype TValueCategory = | ||
| LValue(string descr) { | ||
| exists(Expr e | e.isLValueCategory() and descr = e.getValueCategoryString()) | ||
| } or | ||
| PRValue(string descr) { | ||
| exists(Expr e | e.isPRValueCategory() and descr = e.getValueCategoryString()) | ||
| } or | ||
| XValue(string descr) { | ||
| exists(Expr e | e.isXValueCategory() and descr = e.getValueCategoryString()) | ||
| } | ||
|
|
||
| class ValueCategory extends TValueCategory { | ||
| string description; | ||
|
|
||
| ValueCategory() { | ||
| this = LValue(description) or this = PRValue(description) or this = XValue(description) | ||
| } | ||
|
|
||
| predicate isLValue() { this instanceof LValue } | ||
|
|
||
| predicate isPRValue() { this instanceof PRValue } | ||
|
|
||
| predicate isXValue() { this instanceof XValue } | ||
|
|
||
| predicate isRValue() { this instanceof PRValue or this instanceof XValue } | ||
|
|
||
| predicate isGlvalue() { this instanceof LValue or this instanceof XValue } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more consistent pascal-casing would be |
||
|
|
||
| string toString() { result = description } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Preconditions5.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
|
|
||
| newtype Preconditions5Query = TStdMoveWithNonConstLvalueQuery() | ||
|
|
||
| predicate isPreconditions5QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `stdMoveWithNonConstLvalue` query | ||
| Preconditions5Package::stdMoveWithNonConstLvalueQuery() and | ||
| queryId = | ||
| // `@id` for the `stdMoveWithNonConstLvalue` query | ||
| "cpp/misra/std-move-with-non-const-lvalue" and | ||
| ruleId = "RULE-28-6-1" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module Preconditions5Package { | ||
| Query stdMoveWithNonConstLvalueQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `stdMoveWithNonConstLvalue` query | ||
| TQueryCPP(TPreconditions5PackageQuery(TStdMoveWithNonConstLvalueQuery())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 have noticed that
getValueCategory(expr)yields the same answer asExpr.is___ValueCategory(expr)that the argumentxoff(x)is aprvalue(load)in the code below:This is because of this line here:
Surprisingly, the argument
xto the callf(x)does not have a conversion. I have dived more into the issue because it does not match common sense; it turns outExpr::getConversion/0andExpr::hasLValueToRValueConversion/0depend on different dbscheme tables.(
exprconv/2is whatExpr::hasConversion/0,Expr::hasImplicitConversion/0,Expr::hasExplicitConversion/0depend on as well.hasLValueToRValueConversionis an outlier; it is the only predicate in all ofcpp-allthat usesexpr_isload.)The result is that the argument of
f(x)is still detected asprvalue(load). All the other argumentsxin the example is detected correctly aslvalueandglvaluebecause those have conversions. Thef(x)problem may have not surfaced during development againsttest.cpp, becausestd::move's parameter is a forwarding reference, similar tohabove.So, to make this predicate more perfect (to at least cover the
f(x)case above, we need an additional check onexpr.hasLValueToRValueConversion:(The code is not elegant; but you get the idea.)
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.
The A side of the diff includes
getDirectValueCategory; that's not intended.