-
Notifications
You must be signed in to change notification settings - Fork 2k
C++: Add more alias and side effect models #17034
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
Merged
MathiasVP
merged 8 commits into
github:main
from
MathiasVP:more-alias-and-side-effect-models
Jul 25, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
999fb07
C++: Add more alias models.
MathiasVP 281212a
C++: Accept test changes.
MathiasVP c256c87
Update cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll
MathiasVP db9cd1f
C++: Fix QLDoc copy-paste fails.
MathiasVP 43df4a9
C++: Fix inconsistencies.
MathiasVP b7542ee
C++: Fix more inconsistencies (and delete unnecessary override).
MathiasVP 854a277
Merge branch 'main' into more-alias-and-side-effect-models
MathiasVP 3f5b4a8
C++: Fix more inconsistencies.
MathiasVP 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
115 changes: 115 additions & 0 deletions
115
cpp/ql/lib/semmle/code/cpp/models/implementations/StdAlgorithm.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,115 @@ | ||
| /** | ||
| * Provides models for C++ functions from the `algorithms` header. | ||
| */ | ||
|
|
||
| import semmle.code.cpp.models.interfaces.Taint | ||
| import semmle.code.cpp.models.interfaces.DataFlow | ||
| import semmle.code.cpp.models.interfaces.Iterator | ||
| import semmle.code.cpp.models.interfaces.SideEffect | ||
| import semmle.code.cpp.models.interfaces.Alias | ||
|
|
||
| private class StdPartialSort extends Function, SideEffectFunction, AliasFunction { | ||
| StdPartialSort() { this.hasGlobalOrStdName("partial_sort") } | ||
|
|
||
| override predicate hasOnlySpecificReadSideEffects() { any() } | ||
|
|
||
| override predicate hasOnlySpecificWriteSideEffects() { any() } | ||
|
|
||
| override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) { | ||
| i = this.getAnIteratorParameterIndex() and buffer = true and mustWrite = false | ||
| } | ||
|
|
||
| override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { | ||
| i = this.getAnIteratorParameterIndex() and | ||
| buffer = true and | ||
| this.getParameter(i).getUnspecifiedType() instanceof ReferenceType and | ||
| buffer = false | ||
| } | ||
|
|
||
| private int getAnIteratorParameterIndex() { | ||
| this.getParameter(result).getUnspecifiedType() instanceof Iterator | ||
| } | ||
|
|
||
| override predicate parameterNeverEscapes(int index) { | ||
| index = this.getAnIteratorParameterIndex() | ||
| or | ||
| this.getParameter(index).getUnspecifiedType() instanceof ReferenceType | ||
| } | ||
|
|
||
| override predicate parameterEscapesOnlyViaReturn(int index) { none() } | ||
| } | ||
|
|
||
| private class StdSortHeap extends Function, SideEffectFunction, AliasFunction { | ||
| StdSortHeap() { this.hasGlobalOrStdName("sort_heap") } | ||
|
|
||
| override predicate hasOnlySpecificReadSideEffects() { any() } | ||
|
|
||
| override predicate hasOnlySpecificWriteSideEffects() { any() } | ||
|
|
||
| override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) { | ||
| i = this.getAnIteratorParameterIndex() and buffer = true and mustWrite = false | ||
| } | ||
|
|
||
| override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { | ||
| i = this.getAnIteratorParameterIndex() and | ||
| buffer = true | ||
| } | ||
|
|
||
| private int getAnIteratorParameterIndex() { | ||
| this.getParameter(result).getUnspecifiedType() instanceof Iterator | ||
| } | ||
|
|
||
| override predicate parameterNeverEscapes(int index) { index = this.getAnIteratorParameterIndex() } | ||
|
|
||
| override predicate parameterEscapesOnlyViaReturn(int index) { none() } | ||
| } | ||
|
|
||
| private class StdGenerateN extends Function, SideEffectFunction, AliasFunction { | ||
| StdGenerateN() { this.hasGlobalOrStdName("generate_n") } | ||
|
|
||
| override predicate hasOnlySpecificReadSideEffects() { any() } | ||
|
|
||
| override predicate hasOnlySpecificWriteSideEffects() { any() } | ||
|
|
||
| override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) { | ||
| i = this.getAnIteratorParameterIndex() and buffer = true and mustWrite = false | ||
| } | ||
|
|
||
| override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { | ||
| this.getParameter(i).getUnspecifiedType() instanceof ReferenceType and buffer = false | ||
| } | ||
|
|
||
| private int getAnIteratorParameterIndex() { | ||
| this.getParameter(result).getUnspecifiedType() instanceof Iterator | ||
| } | ||
|
|
||
| override predicate parameterNeverEscapes(int index) { index = this.getAnIteratorParameterIndex() } | ||
|
|
||
| override predicate parameterEscapesOnlyViaReturn(int index) { none() } | ||
| } | ||
|
|
||
| private class StdFindIfOrIfNot extends Function, SideEffectFunction, AliasFunction { | ||
| StdFindIfOrIfNot() { this.hasGlobalOrStdName(["find_if", "find_if_not"]) } | ||
|
|
||
| override predicate hasOnlySpecificReadSideEffects() { any() } | ||
|
|
||
| override predicate hasOnlySpecificWriteSideEffects() { any() } | ||
|
|
||
| override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { | ||
| i = this.getAnIteratorParameterIndex() and buffer = true | ||
| or | ||
| this.getParameter(i).getUnspecifiedType() instanceof ReferenceType and buffer = false | ||
| } | ||
|
|
||
| private int getAnIteratorParameterIndex() { | ||
| this.getParameter(result).getUnspecifiedType() instanceof Iterator | ||
| } | ||
|
|
||
| override predicate parameterNeverEscapes(int index) { | ||
| this.getParameter(index).getUnspecifiedType() instanceof ReferenceType | ||
| } | ||
|
|
||
| override predicate parameterEscapesOnlyViaReturn(int index) { | ||
| index = this.getAnIteratorParameterIndex() | ||
| } | ||
| } |
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.