Skip to content

Commit 6cfeb24

Browse files
committed
Swift: More comments.
1 parent 946b8c6 commit 6cfeb24

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,17 +1349,21 @@ module Exprs {
13491349
}
13501350
}
13511351

1352+
/** Control-flow for a `TapExpr`. See the QLDoc for `TapExpr` for the semantics of a `TapExpr`. */
13521353
private class TapExprTree extends AstStandardPostOrderTree {
13531354
override TapExpr ast;
13541355

13551356
final override ControlFlowElement getChildElement(int i) {
1357+
// We first visit the local variable declaration.
13561358
i = 0 and
13571359
result.asAstNode() = ast.getVar()
13581360
or
1361+
// Then we visit the expression that gives the local variable its initial value.
13591362
i = 1 and
13601363
result.asAstNode() = ast.getSubExpr().getFullyConverted()
13611364
or
1362-
// Note: The CFG for the body will skip the first element in the
1365+
// And finally, we visit the body that potentially mutates the local variable.
1366+
// Note that the CFG for the body will skip the first element in the
13631367
// body because it's guarenteed to be the variable declaration
13641368
// that we've already visited at i = 0. See the explanation
13651369
// in `BraceStmtTree` for why this is necessary.

swift/ql/lib/codeql/swift/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ private module Cached {
2020
cached
2121
predicate defaultAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
2222
// Flow through one argument of `appendLiteral` and `appendInterpolation` and to the second argument.
23+
// This is needed for string interpolation generated by the compiler. An interpolated string
24+
// like `"I am \(n) years old."` is represented as
25+
// ```
26+
// $interpolated = ""
27+
// appendLiteral(&$interpolated, "I am ")
28+
// appendInterpolation(&$interpolated, n)
29+
// appendLiteral(&$interpolated, " years old.")
30+
// ```
2331
exists(ApplyExpr apply1, ApplyExpr apply2, ExprCfgNode e |
2432
nodeFrom.asExpr() = [apply1, apply2].getAnArgument().getExpr() and
2533
apply1.getFunction() = apply2 and
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.expr.TapExpr
32

3+
/**
4+
* A `TapExpr` is an internal expression generated by the Swift compiler.
5+
*
6+
* If `e` is a `TapExpr`, the semantics of evaluating `e` is:
7+
* 1. Create a local variable `e.getVar()` and assign it the value `e.getSubExpr()`.
8+
* 2. Execute `e.getBody()` which potentially modifies the local variable.
9+
* 3. Return the value of the local variable.
10+
*/
411
class TapExpr extends TapExprBase { }

0 commit comments

Comments
 (0)