File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
swift/ql/lib/codeql/swift Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1349,17 +1349,21 @@ module Exprs {
1349
1349
}
1350
1350
}
1351
1351
1352
+ /** Control-flow for a `TapExpr`. See the QLDoc for `TapExpr` for the semantics of a `TapExpr`. */
1352
1353
private class TapExprTree extends AstStandardPostOrderTree {
1353
1354
override TapExpr ast ;
1354
1355
1355
1356
final override ControlFlowElement getChildElement ( int i ) {
1357
+ // We first visit the local variable declaration.
1356
1358
i = 0 and
1357
1359
result .asAstNode ( ) = ast .getVar ( )
1358
1360
or
1361
+ // Then we visit the expression that gives the local variable its initial value.
1359
1362
i = 1 and
1360
1363
result .asAstNode ( ) = ast .getSubExpr ( ) .getFullyConverted ( )
1361
1364
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
1363
1367
// body because it's guarenteed to be the variable declaration
1364
1368
// that we've already visited at i = 0. See the explanation
1365
1369
// in `BraceStmtTree` for why this is necessary.
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ private module Cached {
20
20
cached
21
21
predicate defaultAdditionalTaintStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
22
22
// 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
+ // ```
23
31
exists ( ApplyExpr apply1 , ApplyExpr apply2 , ExprCfgNode e |
24
32
nodeFrom .asExpr ( ) = [ apply1 , apply2 ] .getAnArgument ( ) .getExpr ( ) and
25
33
apply1 .getFunction ( ) = apply2 and
Original file line number Diff line number Diff line change 1
- // generated by codegen/codegen.py, remove this comment if you wish to edit this file
2
1
private import codeql.swift.generated.expr.TapExpr
3
2
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
+ */
4
11
class TapExpr extends TapExprBase { }
You can’t perform that action at this time.
0 commit comments