Skip to content

Commit 6d9cea9

Browse files
authored
Merge pull request #7226 from MathiasVP/shorter-ir-dataflow-paths
C++: Hide some IR dataflow nodes
2 parents f9729bc + 6c7a01d commit 6d9cea9

File tree

5 files changed

+210
-505
lines changed

5 files changed

+210
-505
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,17 @@ predicate isImmutableOrUnobservable(Node n) {
299299
}
300300

301301
/** Holds if `n` should be hidden from path explanations. */
302-
predicate nodeIsHidden(Node n) { n instanceof OperandNode and not n instanceof ArgumentNode }
302+
predicate nodeIsHidden(Node n) {
303+
n instanceof OperandNode and not n instanceof ArgumentNode
304+
or
305+
StoreNodeFlow::flowThrough(n, _) and
306+
not StoreNodeFlow::flowOutOf(n, _) and
307+
not StoreNodeFlow::flowInto(_, n)
308+
or
309+
ReadNodeFlow::flowThrough(n, _) and
310+
not ReadNodeFlow::flowOutOf(n, _) and
311+
not ReadNodeFlow::flowInto(_, n)
312+
}
303313

304314
class LambdaCallKind = Unit;
305315

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,10 @@ private predicate adjacentDefUseFlow(Node nodeFrom, Node nodeTo) {
840840
)
841841
}
842842

843-
private module ReadNodeFlow {
843+
/**
844+
* INTERNAL: Do not use.
845+
*/
846+
module ReadNodeFlow {
844847
/** Holds if the read node `nodeTo` should receive flow from `nodeFrom`. */
845848
predicate flowInto(Node nodeFrom, ReadNode nodeTo) {
846849
nodeTo.isInitial() and
@@ -860,7 +863,12 @@ private module ReadNodeFlow {
860863
)
861864
}
862865

863-
/** Holds if the read node `nodeTo` should receive flow from the read node `nodeFrom`. */
866+
/**
867+
* Holds if the read node `nodeTo` should receive flow from the read node `nodeFrom`.
868+
*
869+
* This happens when `readFrom` is _not_ the source of a `readStep`, and `nodeTo` is
870+
* the `ReadNode` that represents an address that directly depends on `nodeFrom`.
871+
*/
864872
predicate flowThrough(ReadNode nodeFrom, ReadNode nodeTo) {
865873
not readStep(nodeFrom, _, _) and
866874
nodeFrom.getOuter() = nodeTo
@@ -908,11 +916,16 @@ module StoreNodeFlow {
908916
nodeTo.flowInto(Ssa::getDestinationAddress(instrFrom))
909917
}
910918

911-
/** Holds if the store node `nodeTo` should receive flow from `nodeFom`. */
912-
predicate flowThrough(StoreNode nFrom, StoreNode nodeTo) {
919+
/**
920+
* Holds if the store node `nodeTo` should receive flow from `nodeFom`.
921+
*
922+
* This happens when `nodeFrom` is _not_ the source of a `storeStep`, and `nodeFrom` is
923+
* the `Storenode` that represents an address that directly depends on `nodeTo`.
924+
*/
925+
predicate flowThrough(StoreNode nodeFrom, StoreNode nodeTo) {
913926
// Flow through a post update node that doesn't need a store step.
914-
not storeStep(nFrom, _, _) and
915-
nodeTo.getOuter() = nFrom
927+
not storeStep(nodeFrom, _, _) and
928+
nodeTo.getOuter() = nodeFrom
916929
}
917930

918931
/**

0 commit comments

Comments
 (0)