Skip to content

Commit a49d22e

Browse files
committed
C++: Fix join ordering
1 parent 8be1bfe commit a49d22e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
423423
simpleInstructionLocalFlowStep(nodeFrom.asInstruction(), nodeTo.asInstruction())
424424
}
425425

426+
pragma[noinline]
427+
private predicate getFieldSizeOfClass(Class c, Type type, int size) {
428+
exists(Field f |
429+
f.getDeclaringType() = c and
430+
f.getType() = type and
431+
type.getSize() = size
432+
)
433+
}
434+
426435
cached
427436
private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction iTo) {
428437
iTo.(CopyInstruction).getSourceValue() = iFrom
@@ -472,12 +481,11 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
472481
)
473482
or
474483
// Flow from stores to structs with a single field to a load of that field.
475-
iTo.(LoadInstruction).getSourceValueOperand().getAnyDef() = iFrom.(StoreInstruction) and
476-
exists(Class c, Type t |
477-
c = iTo.getResultType() and
478-
t = iFrom.getResultType() and
479-
c.getAField().getUnspecifiedType() = t and
480-
c.getSize() = t.getSize()
484+
iTo.(LoadInstruction).getSourceValueOperand().getAnyDef() = iFrom and
485+
exists(int size, Type type |
486+
type = iFrom.getResultType() and
487+
iTo.getResultType().getSize() = size and
488+
getFieldSizeOfClass(iTo.getResultType(), type, size)
481489
)
482490
or
483491
// Flow through modeled functions

0 commit comments

Comments
 (0)