-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Instantiate model generation library #19295
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
MathiasVP
wants to merge
5
commits into
github:main
Choose a base branch
from
MathiasVP:cpp-add-mad-generation-library
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
5 commits
Select commit
Hold shift + click to select a range
e0f62b7
C++: Instantiate model generation library.
MathiasVP e701092
C++: Add tests that will soon succeed.
MathiasVP 37e91fd
C++: Instantiate inline expectation test framework to test model gene…
MathiasVP 8283594
C++: Add copy-pasted files from C#.
MathiasVP 9b5643d
C++: Fix ql-for-ql findings.
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 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,34 @@ | ||
private import cpp | ||
private import codeql.mad.test.InlineMadTest | ||
|
||
class MadRelevantFunction extends Function { | ||
MadRelevantFunction() { not this.isFromUninstantiatedTemplate(_) } | ||
} | ||
|
||
private module InlineMadTestLang implements InlineMadTestLangSig { | ||
class Callable = MadRelevantFunction; | ||
|
||
/** | ||
* Holds if `c` is the closest `Callable` that succeeds `comment` in the file. | ||
*/ | ||
private predicate hasClosestCallable(CppStyleComment comment, Callable c) { | ||
c = | ||
min(Callable cand, int dist | | ||
// This has no good join order, but should hopefully be good enough for tests. | ||
cand.getFile() = comment.getFile() and | ||
dist = cand.getLocation().getStartLine() - comment.getLocation().getStartLine() and | ||
dist > 0 | ||
| | ||
cand order by dist | ||
) | ||
} | ||
|
||
string getComment(Callable c) { | ||
exists(CppStyleComment comment | | ||
hasClosestCallable(comment, c) and | ||
result = comment.getContents().suffix(2) | ||
) | ||
} | ||
} | ||
|
||
import InlineMadTestImpl<InlineMadTestLang> |
13 changes: 13 additions & 0 deletions
13
cpp/ql/src/utils/modelgenerator/CaptureContentSummaryModels.ql
This file contains 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,13 @@ | ||
/** | ||
* @name Capture content based summary models. | ||
* @description Finds applicable content based summary models to be used by other queries. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/contentbased-summary-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSummaryTargetApi api, string flow | ||
where flow = ContentSensitive::captureFlow(api, _) | ||
select flow order by flow |
13 changes: 13 additions & 0 deletions
13
cpp/ql/src/utils/modelgenerator/CaptureMixedNeutralModels.ql
This file contains 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,13 @@ | ||
/** | ||
* @name Capture mixed neutral models. | ||
* @description Finds neutral models to be used by other queries. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/mixed-neutral-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSummaryTargetApi api, string noflow | ||
where noflow = captureMixedNeutral(api) | ||
select noflow order by noflow |
13 changes: 13 additions & 0 deletions
13
cpp/ql/src/utils/modelgenerator/CaptureMixedSummaryModels.ql
This file contains 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,13 @@ | ||
/** | ||
* @name Capture mixed summary models. | ||
* @description Finds applicable summary models to be used by other queries. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/mixed-summary-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSummaryTargetApi api, string flow | ||
where flow = captureMixedFlow(api, _) | ||
select flow order by flow |
This file contains 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,13 @@ | ||
/** | ||
* @name Capture neutral models. | ||
* @description Finds neutral models to be used by other queries. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/neutral-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSummaryTargetApi api, string noflow | ||
where noflow = captureNoFlow(api) | ||
select noflow order by noflow |
This file contains 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,13 @@ | ||
/** | ||
* @name Capture sink models. | ||
* @description Finds public methods that act as sinks as they flow into a known sink. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/sink-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSinkTargetApi api, string sink | ||
where sink = captureSink(api) | ||
select sink order by sink |
This file contains 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,13 @@ | ||
/** | ||
* @name Capture source models. | ||
* @description Finds APIs that act as sources as they expose already known sources. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/source-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSourceTargetApi api, string source | ||
where source = captureSource(api) | ||
select source order by source |
This file contains 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,13 @@ | ||
/** | ||
* @name Capture summary models. | ||
* @description Finds applicable summary models to be used by other queries. | ||
* @kind diagnostic | ||
* @id cpp/utils/modelgenerator/summary-models | ||
* @tags modelgenerator | ||
*/ | ||
|
||
import internal.CaptureModels | ||
|
||
from DataFlowSummaryTargetApi api, string flow | ||
where flow = captureFlow(api) | ||
select flow order by flow |
This file contains 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,15 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import os.path | ||
import subprocess | ||
|
||
# Add Model as Data script directory to sys.path. | ||
gitroot = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip() | ||
madpath = os.path.join(gitroot, "misc/scripts/models-as-data/") | ||
sys.path.append(madpath) | ||
|
||
import generate_flow_model as model | ||
|
||
language = "cpp" | ||
model.Generator.make(language).run() | ||
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. The python script puts the generated models in
If you intend to use this location for generated models, maybe consider to extend the |
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.
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.
It is my intention to change the python script such that
--with-summaries
uses the mixed query instead (and correspondingly for the neutral), but for testing purposes it is nice to keep both the content based and heuristic based queries around.