Skip to content

Commit 1423ea0

Browse files
author
Dave Bartolomeo
committed
C++: More IR.qll QLDoc
1 parent 98348a9 commit 1423ea0

File tree

1 file changed

+45
-1
lines changed
  • cpp/ql/src/semmle/code/cpp/ir

1 file changed

+45
-1
lines changed

cpp/ql/src/semmle/code/cpp/ir/IR.qll

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
/**
2+
* Provides classes that describe the Intermediate Representation (IR) of the program.
3+
*
4+
* The IR is a representation of the semantics of the program, with very little dependence on the
5+
* syntax that was used to write the program. For example, in C++, the statements `i += 1;`, `i++`,
6+
* and `++i` all have the same semantic effect, but appear in the AST as three different types of
7+
* `Expr` node. In the IR, all three statements are broken down into a sequence of fundamental
8+
* operations similar to:
9+
*
10+
* ```
11+
* r1(int*) = VariableAddress[i] // Compute the address of variable `i`
12+
* r2(int) = Load &:r1, m0 // Load the value of `i`
13+
* r3(int) = Constant[1] // An integer constant with the value `1`
14+
* r4(int) = Add r2, r3 // Add `1` to the value of `i`
15+
* r5(int) = Store &r1, r4 // Store the new value back into the variable `i`
16+
* ```
17+
*
18+
* This allows IR-based analysis to focus on the fundamental operations, rather than having to be
19+
* concerned with the various ways of expressing those operations in source code.
20+
*
21+
* The key classes in the IR are:
22+
*
23+
* - `IRFunction` - Contains the IR for an entire function definition, including all of that
24+
* function's `Instruction`s, `IRBlock`s, and `IRVariables`.
25+
* - `Instruction` - A single operation in the IR. An instruction specifies the operation to be
26+
* performed, the operands that produce the inputs to that operation, and the type of the result
27+
* of the operation. Control flows from an `Instruction` to one of a set of successor
28+
* `Instruction`s.
29+
* - `Operand` - An input value of an `Instruction`. All inputs of an `Instruction` are explicitly
30+
* represented as `Operand`s, even if the input was implicit in the source code. An `Operand` has
31+
* a link to the `Instruction` that consumes its value (its "use") and a link to the `Instruction`
32+
* that produces its value (its "definition").
33+
* - `IRVariable` - A variable accessed by the IR for a particular function. An `IRVariable` is
34+
* created for each variable directly accessed by the function. In addition, `IRVariable`s are
35+
* created to represent certain temporary storage locations that do not have explicitly declared
36+
* variables in the source code, such as the return value of the function.
37+
* - `IRBlock` - A "basic block" in the control flow graph of a function. An `IRBlock` contains a
38+
* sequence of instructions such that control flow can only enter the block at the first
39+
* instruction, and can only leave the block from the last instruction.
40+
* - `IRType` - The type of a value accessed in the IR. Unlike the `Type` class in the AST, `IRType`
41+
* is language-neutral. For example, in C++, `unsigned int`, `char32_t`, and `wchar_t` might all
42+
* be represented as the `IRType` `uint4`, a four-byte unsigned integer.
43+
*/
44+
145
// Most queries should operate on the aliased SSA IR, so that's what we expose
2-
// publically as the "IR".
46+
// publicly as the "IR".
347
import implementation.aliased_ssa.IR

0 commit comments

Comments
 (0)