Skip to content

Commit 57f5b97

Browse files
committed
C++: Instantiate the new shared library for C++.
1 parent f514753 commit 57f5b97

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import cpp
2+
3+
/**
4+
* Provides classes for performing global (inter-procedural) control flow analyses.
5+
*/
6+
module ControlFlow {
7+
private import internal.ControlFlowSpecific
8+
private import shared.ControlFlow
9+
import ControlFlowMake<Location, CppControlFlow>
10+
import Public
11+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
private import semmle.code.cpp.ir.IR
2+
private import cpp as Cpp
3+
private import ControlFlowPublic
4+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate as DataFlowPrivate
5+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
6+
7+
predicate edge(Node n1, Node n2) { n1.asInstruction().getASuccessor() = n2.asInstruction() }
8+
9+
predicate callTarget(CallNode call, Callable target) {
10+
exists(DataFlowPrivate::DataFlowCall dfCall | dfCall.asCallInstruction() = call.asInstruction() |
11+
DataFlowImplCommon::viableCallableCached(dfCall).asSourceCallable() = target
12+
or
13+
DataFlowImplCommon::viableCallableLambda(dfCall, _).asSourceCallable() = target
14+
)
15+
}
16+
17+
predicate flowEntry(Callable c, Node entry) {
18+
entry.asInstruction().(EnterFunctionInstruction).getEnclosingFunction() = c
19+
}
20+
21+
predicate flowExit(Callable c, Node exitNode) {
22+
exitNode.asInstruction().(ExitFunctionInstruction).getEnclosingFunction() = c
23+
}
24+
25+
Callable getEnclosingCallable(Node n) { n.getEnclosingFunction() = result }
26+
27+
predicate hiddenNode(Node n) { n.asInstruction() instanceof PhiInstruction }
28+
29+
private newtype TSplit = TNone() { none() }
30+
31+
class Split extends TSplit {
32+
abstract string toString();
33+
34+
abstract Cpp::Location getLocation();
35+
36+
abstract predicate entry(Node n1, Node n2);
37+
38+
abstract predicate exit(Node n1, Node n2);
39+
40+
abstract predicate blocked(Node n1, Node n2);
41+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
private import semmle.code.cpp.ir.IR
2+
private import cpp
3+
4+
private newtype TNode = TInstructionNode(Instruction i)
5+
6+
abstract private class NodeImpl extends TNode {
7+
/** Gets the `Instruction` associated with this node, if any. */
8+
Instruction asInstruction() { result = this.(InstructionNode).getInstruction() }
9+
10+
/** Gets the `Expr` associated with this node, if any. */
11+
Expr asExpr() { result = this.(ExprNode).getExpr() }
12+
13+
/** Gets the `Parameter` associated with this node, if any. */
14+
Parameter asParameter() { result = this.(ParameterNode).getParameter() }
15+
16+
/** Gets the location of this node. */
17+
Location getLocation() { none() }
18+
19+
/**
20+
* Holds if this element is at the specified location.
21+
* The location spans column `startcolumn` of line `startline` to
22+
* column `endcolumn` of line `endline` in file `filepath`.
23+
* For more information, see
24+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
25+
*/
26+
final predicate hasLocationInfo(
27+
string filepath, int startline, int startcolumn, int endline, int endcolumn
28+
) {
29+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
30+
}
31+
32+
/** Gets a textual representation of this node. */
33+
abstract string toString();
34+
35+
/** Gets the enclosing callable of this node. */
36+
abstract Callable getEnclosingFunction();
37+
}
38+
39+
final class Node = NodeImpl;
40+
41+
private class InstructionNode extends NodeImpl {
42+
Instruction instr;
43+
44+
InstructionNode() { this = TInstructionNode(instr) }
45+
46+
/** Gets the `Instruction` associated with this node. */
47+
Instruction getInstruction() { result = instr }
48+
49+
final override Location getLocation() { result = instr.getLocation() }
50+
51+
final override string toString() { result = instr.getAst().toString() }
52+
53+
final override Callable getEnclosingFunction() { result = instr.getEnclosingFunction() }
54+
}
55+
56+
private class ExprNode extends InstructionNode {
57+
Expr e;
58+
59+
ExprNode() { e = this.getInstruction().getConvertedResultExpression() }
60+
61+
/** Gets the `Expr` associated with this node. */
62+
Expr getExpr() { result = e }
63+
}
64+
65+
private class ParameterNode extends InstructionNode {
66+
override InitializeParameterInstruction instr;
67+
Parameter p;
68+
69+
ParameterNode() { p = instr.getParameter() }
70+
71+
/** Gets the `Parameter` associated with this node. */
72+
Parameter getParameter() { result = p }
73+
}
74+
75+
class CallNode extends InstructionNode {
76+
override CallInstruction instr;
77+
}
78+
79+
class Callable = Function;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Provides IR-specific definitions for use in the data flow library.
3+
*/
4+
5+
private import cpp
6+
private import semmle.code.cpp.interproccontrolflow.shared.ControlFlow
7+
8+
module Private {
9+
import ControlFlowPrivate
10+
}
11+
12+
module Public {
13+
import ControlFlowPublic
14+
}
15+
16+
module CppControlFlow implements InputSig<Location> {
17+
import Private
18+
import Public
19+
}

0 commit comments

Comments
 (0)