-
Notifications
You must be signed in to change notification settings - Fork 2k
C++: Modernize PrintIR for local dataflow
#13266
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ccc9e09
C++: Add mechanism to hide specific instructions and operands from Pr…
MathiasVP 0519cee
C++/C#: Sync identical files.
MathiasVP 8ee7694
C++: Modernize the PrintIRLocalFlow after the use-use flow changes.
MathiasVP 43459c1
C++: Modernize the PrintIRStoreSteps (and rename it to PrintIRFieldFl…
MathiasVP 4b92a2a
C++: Fix Code Scanning error.
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
38 changes: 38 additions & 0 deletions
38
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/PrintIRFieldFlowSteps.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,38 @@ | ||
| /** | ||
| * Print the dataflow local store steps in IR dumps. | ||
| */ | ||
|
|
||
| private import cpp | ||
| private import semmle.code.cpp.ir.IR | ||
| private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil | ||
| private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate | ||
| private import PrintIRUtilities | ||
|
|
||
| /** A property provider for local IR dataflow store steps. */ | ||
| class FieldFlowPropertyProvider extends IRPropertyProvider { | ||
| override string getOperandProperty(Operand operand, string key) { | ||
| exists(PostFieldUpdateNode pfun, Content content | | ||
| key = "store " + content.toString() and | ||
| operand = pfun.getPreUpdateNode().(IndirectOperand).getOperand() and | ||
| result = | ||
| strictconcat(string element, Node node | | ||
| storeStep(node, content, pfun) and | ||
| element = nodeId(node, _, _) | ||
| | | ||
| element, ", " | ||
| ) | ||
| ) | ||
| or | ||
| exists(Node node2, Content content | | ||
| key = "read " + content.toString() and | ||
| operand = node2.(IndirectOperand).getOperand() and | ||
| result = | ||
| strictconcat(string element, Node node1 | | ||
| readStep(node1, content, node2) and | ||
| element = nodeId(node1, _, _) | ||
| | | ||
| element, ", " | ||
| ) | ||
| ) | ||
| } | ||
| } |
112 changes: 21 additions & 91 deletions
112
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/PrintIRLocalFlow.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 |
|---|---|---|
| @@ -1,136 +1,66 @@ | ||
| private import cpp | ||
| // The `ValueNumbering` library has to be imported right after `cpp` to ensure | ||
| // that the cached IR gets the same checksum here as it does in queries that use | ||
| // `ValueNumbering` without `DataFlow`. | ||
| private import semmle.code.cpp.ir.ValueNumbering | ||
| private import semmle.code.cpp.ir.IR | ||
| private import semmle.code.cpp.ir.dataflow.DataFlow | ||
| private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil | ||
| private import SsaInternals as Ssa | ||
| private import PrintIRUtilities | ||
|
|
||
| /** | ||
| * Gets the local dataflow from other nodes in the same function to this node. | ||
| */ | ||
| private string getFromFlow(DataFlow::Node useNode, int order1, int order2) { | ||
| exists(DataFlow::Node defNode, string prefix | | ||
| ( | ||
| simpleLocalFlowStep(defNode, useNode) and prefix = "" | ||
| or | ||
| any(DataFlow::Configuration cfg).isAdditionalFlowStep(defNode, useNode) and | ||
| defNode.getEnclosingCallable() = useNode.getEnclosingCallable() and | ||
| prefix = "+" | ||
| ) and | ||
| if defNode.asInstruction() = useNode.asOperand().getAnyDef() | ||
| then | ||
| // Shorthand for flow from the def of this operand. | ||
| result = prefix + "def" and | ||
| order1 = -1 and | ||
| order2 = 0 | ||
| else | ||
| if defNode.asOperand().getUse() = useNode.asInstruction() | ||
| then | ||
| // Shorthand for flow from an operand of this instruction | ||
| result = prefix + defNode.asOperand().getDumpId() and | ||
| order1 = -1 and | ||
| order2 = defNode.asOperand().getDumpSortOrder() | ||
| else result = prefix + nodeId(defNode, order1, order2) | ||
| private string getFromFlow(Node node2, int order1, int order2) { | ||
| exists(Node node1 | | ||
| simpleLocalFlowStep(node1, node2) and | ||
| result = nodeId(node1, order1, order2) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the local dataflow from this node to other nodes in the same function. | ||
| */ | ||
| private string getToFlow(DataFlow::Node defNode, int order1, int order2) { | ||
| exists(DataFlow::Node useNode, string prefix | | ||
| ( | ||
| simpleLocalFlowStep(defNode, useNode) and prefix = "" | ||
| or | ||
| any(DataFlow::Configuration cfg).isAdditionalFlowStep(defNode, useNode) and | ||
| defNode.getEnclosingCallable() = useNode.getEnclosingCallable() and | ||
| prefix = "+" | ||
| ) and | ||
| if useNode.asInstruction() = defNode.asOperand().getUse() | ||
| then | ||
| // Shorthand for flow to this operand's instruction. | ||
| result = prefix + "result" and | ||
| order1 = -1 and | ||
| order2 = 0 | ||
| else result = prefix + nodeId(useNode, order1, order2) | ||
| private string getToFlow(Node node1, int order1, int order2) { | ||
| exists(Node node2 | | ||
| simpleLocalFlowStep(node1, node2) and | ||
| result = nodeId(node2, order1, order2) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the properties of the dataflow node `node`. | ||
| */ | ||
| private string getNodeProperty(DataFlow::Node node, string key) { | ||
| private string getNodeProperty(Node node, string key) { | ||
| // List dataflow into and out of this node. Flow into this node is printed as `src->@`, and flow | ||
| // out of this node is printed as `@->dest`. | ||
| key = "flow" and | ||
| result = | ||
| strictconcat(string flow, boolean to, int order1, int order2 | | ||
| flow = getFromFlow(node, order1, order2) + "->@" and to = false | ||
| flow = getFromFlow(node, order1, order2) + "->" + starsForNode(node) + "@" and to = false | ||
| or | ||
| flow = "@->" + getToFlow(node, order1, order2) and to = true | ||
| flow = starsForNode(node) + "@->" + getToFlow(node, order1, order2) and to = true | ||
| | | ||
| flow, ", " order by to, order1, order2, flow | ||
| ) | ||
| or | ||
| // Is this node a dataflow sink? | ||
| key = "sink" and | ||
| any(DataFlow::Configuration cfg).isSink(node) and | ||
| result = "true" | ||
| or | ||
| // Is this node a dataflow source? | ||
| key = "source" and | ||
| any(DataFlow::Configuration cfg).isSource(node) and | ||
| result = "true" | ||
| or | ||
| // Is this node a dataflow barrier, and if so, what kind? | ||
| key = "barrier" and | ||
| result = | ||
| strictconcat(string kind | | ||
| any(DataFlow::Configuration cfg).isBarrier(node) and kind = "full" | ||
| or | ||
| any(DataFlow::Configuration cfg).isBarrierIn(node) and kind = "in" | ||
| or | ||
| any(DataFlow::Configuration cfg).isBarrierOut(node) and kind = "out" | ||
| | | ||
| kind, ", " | ||
| ) | ||
| // or | ||
| // // Is there partial flow from a source to this node? | ||
| // // This property will only be emitted if partial flow is enabled by overriding | ||
| // // `DataFlow::Configuration::explorationLimit()`. | ||
| // key = "pflow" and | ||
| // result = | ||
| // strictconcat(DataFlow::PartialPathNode sourceNode, DataFlow::PartialPathNode destNode, int dist, | ||
| // int order1, int order2 | | ||
| // any(DataFlow::Configuration cfg).hasPartialFlow(sourceNode, destNode, dist) and | ||
| // destNode.getNode() = node and | ||
| // // Only print flow from a source in the same function. | ||
| // sourceNode.getNode().getEnclosingCallable() = node.getEnclosingCallable() | ||
| // | | ||
| // nodeId(sourceNode.getNode(), order1, order2) + "+" + dist.toString(), ", " | ||
| // order by | ||
| // order1, order2, dist desc | ||
| // ) | ||
| } | ||
|
|
||
| /** | ||
| * Property provider for local IR dataflow. | ||
| */ | ||
| class LocalFlowPropertyProvider extends IRPropertyProvider { | ||
| override string getOperandProperty(Operand operand, string key) { | ||
| exists(DataFlow::Node node | | ||
| operand = node.asOperand() and | ||
| exists(Node node | | ||
| operand = [node.asOperand(), node.(RawIndirectOperand).getOperand()] and | ||
| result = getNodeProperty(node, key) | ||
| ) | ||
| } | ||
|
|
||
| override string getInstructionProperty(Instruction instruction, string key) { | ||
| exists(DataFlow::Node node | | ||
| instruction = node.asInstruction() and | ||
| exists(Node node | | ||
| instruction = [node.asInstruction(), node.(RawIndirectInstruction).getInstruction()] | ||
| | | ||
| result = getNodeProperty(node, key) | ||
| ) | ||
| } | ||
|
|
||
| override predicate shouldPrintOperand(Operand operand) { not Ssa::ignoreOperand(operand) } | ||
|
|
||
| override predicate shouldPrintInstruction(Instruction instr) { not Ssa::ignoreInstruction(instr) } | ||
| } |
33 changes: 0 additions & 33 deletions
33
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/PrintIRStoreSteps.qll
This file was deleted.
Oops, something went wrong.
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
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.
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter