Skip to content

Commit 8be1bfe

Browse files
committed
C++: Add comments and accept expected dataflow sanity failures
1 parent e0cd595 commit 8be1bfe

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ private class ExplicitFieldStoreQualifierNode extends PartialDefinitionNode {
270270
override Node getPreUpdateNode() { result.asInstruction() = instr.getTotal() }
271271
}
272272

273+
/**
274+
* Not every store instruction generates a chi instruction that we can attach a PostUpdateNode to.
275+
* For instance, an update to a field of a struct containing only one field. For these cases we
276+
* attach the PostUpdateNode to the store instruction. There's no obvious pre update node for this case
277+
* (as the entire memory is updated), so `getPreUpdateNode` is implemented as `none()`.
278+
*/
273279
private class ExplicitSingleFieldStoreQualifierNode extends PartialDefinitionNode {
274280
override StoreInstruction instr;
275281

@@ -465,6 +471,7 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
465471
iTo.(LoadInstruction).getSourceValueOperand().getAnyDef() = chi
466472
)
467473
or
474+
// Flow from stores to structs with a single field to a load of that field.
468475
iTo.(LoadInstruction).getSourceValueOperand().getAnyDef() = iFrom.(StoreInstruction) and
469476
exists(Class c, Type t |
470477
c = iTo.getResultType() and

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,10 @@ unreachableNodeCCtx
788788
localCallNodes
789789
postIsNotPre
790790
postHasUniquePre
791+
| assignexpr.cpp:9:2:9:12 | Store | PostUpdateNode should have one pre-update node but has 0. |
792+
| bad_asts.cpp:15:10:15:12 | Store | PostUpdateNode should have one pre-update node but has 0. |
793+
| file://:0:0:0:0 | Store | PostUpdateNode should have one pre-update node but has 0. |
794+
| ir.cpp:531:14:531:14 | Store | PostUpdateNode should have one pre-update node but has 0. |
791795
uniquePostUpdate
792796
postIsInSameCallable
793797
reverseRead

0 commit comments

Comments
 (0)