Skip to content

Commit 9bfe847

Browse files
committed
C++: Fix awful joins on bochs:
``` Evaluated relational algebra for predicate DataFlowPrivate::storeStepImpl/4#b2c79f9a@13be12rc with tuple counts: 9 ~0% {3} r1 = JOIN `FlowSummaryImpl::Private::Steps::summaryStoreStep/3#5c2d4899` WITH DataFlowUtil::TFlowSummaryNode#40da8361 ON FIRST 1 OUTPUT Lhs.2, Lhs.1, Rhs.1 9 ~0% {4} | JOIN WITH DataFlowUtil::TFlowSummaryNode#40da8361 ON FIRST 1 OUTPUT Lhs.2, Lhs.1, Rhs.1, _ 9 ~12% {4} | REWRITE WITH Out.3 := true 1853420 ~0% {3} r2 = SCAN `DataFlowPrivate::nodeHasInstruction/3#f469bb06` OUTPUT In.1, In.0, In.2 100282 ~0% {3} | JOIN WITH `Instruction::StoreInstruction.getDestinationAddressOperand/0#dispred#596a4aba` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.2 127910 ~0% {6} | JOIN WITH `DataFlowPrivate::numberOfLoadsFromOperand/4#7e555666_1023#join_rhs` ON FIRST 1 OUTPUT _, Lhs.1, Rhs.1, Rhs.3, Lhs.2, Rhs.2 127910 ~0% {4} | REWRITE WITH Tmp.0 := 1, Out.0 := (Tmp.0 + In.4 + In.5) KEEPING 4 4178182721 ~1% {4} | JOIN WITH `DataFlowUtil::FieldContent.getIndirectionIndex/0#dispred#cc69866f_10#join_rhs` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.2, Lhs.3 4290552803 ~0% {5} | JOIN WITH `DataFlowUtil::FieldContent.getAField/0#dispred#ba1c91e5` ON FIRST 1 OUTPUT Lhs.2, Lhs.1, Lhs.3, Lhs.0, Rhs.1 3033745816 ~5% {7} | JOIN WITH DataFlowUtil::PostFieldUpdateNode#b86f3a84_1023#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.2, Lhs.3, Lhs.4, Rhs.2, Rhs.3 3033745816 ~3% {9} | JOIN WITH DataFlowUtil::TPostUpdateNodeImpl#f5e76b7a_21#join_rhs ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.4, Lhs.0, Lhs.5, Lhs.6, Rhs.1, _ {8} | REWRITE WITH Tmp.8 := 1, TEST InOut.7 = Tmp.8 KEEPING 8 1516872908 ~0% {7} | SCAN OUTPUT In.4, In.5, In.6, In.0, In.1, In.2, In.3 2409090286 ~1% {6} | JOIN WITH DataFlowUtil::PostFieldUpdateNode#b86f3a84_0231#join_rhs ON FIRST 3 OUTPUT Rhs.3, Lhs.6, Lhs.3, Lhs.4, Lhs.5, Lhs.0 66016 ~45% {4} | JOIN WITH `DataFlowUtil::FieldAddress.getField/0#dispred#bdd01c1a` ON FIRST 2 OUTPUT Lhs.2, Lhs.4, Lhs.5, Lhs.3 66025 ~45% {4} r3 = r1 UNION r2 return r3 ```
1 parent 7f0fcb0 commit 9bfe847

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ predicate jumpStep(Node n1, Node n2) {
861861
n2.(FlowSummaryNode).getSummaryNode())
862862
}
863863

864+
bindingset[c]
865+
pragma[inline_late]
866+
private int getIndirectionIndexLate(Content c) { result = c.getIndirectionIndex() }
867+
864868
/**
865869
* Holds if data can flow from `node1` to `node2` via an assignment to `f`.
866870
* Thus, `node2` references an object with a field `f` that contains the
@@ -877,12 +881,13 @@ predicate storeStepImpl(Node node1, Content c, Node node2, boolean certain) {
877881
|
878882
postFieldUpdate = node2 and
879883
fc = c and
880-
nodeHasInstruction(node1, store, pragma[only_bind_into](indirectionIndex1)) and
884+
nodeHasInstruction(node1, pragma[only_bind_into](store),
885+
pragma[only_bind_into](indirectionIndex1)) and
881886
postFieldUpdate.getIndirectionIndex() = 1 and
882887
numberOfLoadsFromOperand(postFieldUpdate.getFieldAddress(),
883888
store.getDestinationAddressOperand(), numberOfLoads, certain) and
884889
fc.getAField() = postFieldUpdate.getUpdatedField() and
885-
fc.getIndirectionIndex() = 1 + indirectionIndex1 + numberOfLoads
890+
getIndirectionIndexLate(fc) = 1 + indirectionIndex1 + numberOfLoads
886891
)
887892
or
888893
// models-as-data summarized flow
@@ -968,7 +973,7 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
968973
nodeHasOperand(node1, fa1.getObjectAddressOperand(), 1) and
969974
numberOfLoadsFromOperand(fa1, operand, numberOfLoads, _) and
970975
fc.getAField() = fa1.getField() and
971-
fc.getIndirectionIndex() = indirectionIndex2 + numberOfLoads
976+
getIndirectionIndexLate(fc) = indirectionIndex2 + numberOfLoads
972977
)
973978
or
974979
// models-as-data summarized flow

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,7 @@ class NonUnionFieldContent extends FieldContent, TNonUnionContent {
21972197
override Field getAField() { result = f }
21982198

21992199
/** Gets the indirection index of this `FieldContent`. */
2200-
pragma[inline]
2201-
override int getIndirectionIndex() {
2202-
pragma[only_bind_into](result) = pragma[only_bind_out](indirectionIndex)
2203-
}
2200+
override int getIndirectionIndex() { result = indirectionIndex }
22042201

22052202
override predicate impliesClearOf(Content c) {
22062203
exists(FieldContent fc |
@@ -2230,10 +2227,7 @@ class UnionContent extends FieldContent, TUnionContent {
22302227
Union getUnion() { result = u }
22312228

22322229
/** Gets the indirection index of this `UnionContent`. */
2233-
pragma[inline]
2234-
override int getIndirectionIndex() {
2235-
pragma[only_bind_into](result) = pragma[only_bind_out](indirectionIndex)
2236-
}
2230+
override int getIndirectionIndex() { result = indirectionIndex }
22372231

22382232
override predicate impliesClearOf(Content c) {
22392233
exists(UnionContent uc |
@@ -2257,10 +2251,7 @@ class ElementContent extends Content, TElementContent {
22572251

22582252
ElementContent() { this = TElementContent(indirectionIndex) }
22592253

2260-
pragma[inline]
2261-
override int getIndirectionIndex() {
2262-
pragma[only_bind_into](result) = pragma[only_bind_out](indirectionIndex)
2263-
}
2254+
override int getIndirectionIndex() { result = indirectionIndex }
22642255

22652256
override predicate impliesClearOf(Content c) { none() }
22662257

0 commit comments

Comments
 (0)