Skip to content

Commit 11683fa

Browse files
committed
C++: add mapping between models and instructions
1 parent 5af351e commit 11683fa

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Provides predicates for mapping the `FunctionInput` and `FunctionOutput`
3+
* classes used in function models to the corresponding instructions.
4+
*/
5+
private import semmle.code.cpp.ir.IR
6+
private import semmle.code.cpp.ir.dataflow.DataFlow
7+
8+
/**
9+
* Gets the instruction that goes into `input` for `call`.
10+
*/
11+
Instruction callInput(CallInstruction call, FunctionInput input) {
12+
// A positional argument
13+
exists(int index |
14+
result = call.getPositionalArgument(index) and
15+
input.isParameter(index)
16+
)
17+
or
18+
// A value pointed to by a positional argument
19+
exists(ReadSideEffectInstruction read |
20+
result = read and
21+
read.getPrimaryInstruction() = call and
22+
input.isParameterDeref(read.getIndex())
23+
)
24+
or
25+
// The qualifier pointer
26+
result = call.getThisArgument() and
27+
input.isQualifierAddress()
28+
//TODO: qualifier deref
29+
}
30+
31+
/**
32+
* Gets the instruction that holds the `output` for `call`.
33+
*/
34+
Instruction callOutput(CallInstruction call, FunctionOutput output) {
35+
// The return value
36+
result = call and
37+
output.isReturnValue()
38+
or
39+
// The side effect of a call on the value pointed to by a positional argument
40+
exists(WriteSideEffectInstruction effect |
41+
result = effect and
42+
effect.getPrimaryInstruction() = call and
43+
output.isParameterDeref(effect.getIndex())
44+
)
45+
// TODO: qualifiers, return value dereference
46+
}

0 commit comments

Comments
 (0)