diff --git a/swift/ql/.generated.list b/swift/ql/.generated.list index fd75bc1ade4..a62640aace8 100644 --- a/swift/ql/.generated.list +++ b/swift/ql/.generated.list @@ -184,7 +184,6 @@ ql/lib/codeql/swift/elements/expr/OverloadedDeclRefExprConstructor.qll 2cf79b483 ql/lib/codeql/swift/elements/expr/ParenExprConstructor.qll 6baaa592db57870f5ecd9be632bd3f653c44d72581efd41e8a837916e1590f9e 6f28988d04b2cb69ddcb63fba9ae3166b527803a61c250f97e48ff39a28379f6 ql/lib/codeql/swift/elements/expr/PointerToPointerExpr.qll 921645a373443d050dbc29b9f6bc4a734163c75aeffce453a4f8334b34077d30 54089de77845f6b0e623c537bc25a010ecf1b5c7630b1b4060d2b378abc07f4e ql/lib/codeql/swift/elements/expr/PointerToPointerExprConstructor.qll 95cc8003b9a3b2101afb8f110ec4cbd29e380fc048ee080f5047bcf0e14a06c7 114d487a1bb2cd33b27a9c3a47ad1d7254766e169512642f8b09b9c32cf3dc86 -ql/lib/codeql/swift/elements/expr/PostfixUnaryExpr.qll a67abdf379f04f1aeee0795cd3ebeb28ed8dfe0efad15b128d44cc9e30b32cbd cbb2b2d54c8e316dc71388ea4ff6bb5d0a6204b4e9d9ce2888e1877a54e85e8f ql/lib/codeql/swift/elements/expr/PostfixUnaryExprConstructor.qll c26326e2703b9a8b077ea9f132ae86a76b4010a108b8dcde29864f4206096231 70e45fbe365b63226d0132158cdd453e2e00d740a31c1fb0f7bfb3b2dedfd928 ql/lib/codeql/swift/elements/expr/PrefixUnaryExprConstructor.qll 6d4c915baf460691cc22681154b1129852c26f1bd9fe3e27b4e162f819d934f5 7971698433bc03dbff2fec34426a96a969fab1a5a575aaf91f10044819e16f6d ql/lib/codeql/swift/elements/expr/PropertyWrapperValuePlaceholderExpr.qll 35a61a7f68e71165690127b445fff39780028cb6be5e7b5eadaafa8aeb6b2321 f9e32f65e6d453d3fa857a4d3ca19700be1f8ea2f3d13534656bc21a2fc5f0b0 diff --git a/swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll b/swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll index 82332b4c47d..67aba2155db 100644 --- a/swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll +++ b/swift/ql/lib/codeql/swift/dataflow/internal/DataFlowPrivate.qll @@ -148,11 +148,29 @@ private module Cached { // flow through `!` nodeFrom.asExpr() = nodeTo.asExpr().(ForceValueExpr).getSubExpr() or - // flow through `?` + // flow through `?` and `?.` nodeFrom.asExpr() = nodeTo.asExpr().(BindOptionalExpr).getSubExpr() or nodeFrom.asExpr() = nodeTo.asExpr().(OptionalEvaluationExpr).getSubExpr() or + // flow through nil-coalescing operator `??` + exists(BinaryExpr nco | + nco.getOperator().(FreeFunctionDecl).getName() = "??(_:_:)" and + nodeTo.asExpr() = nco + | + // value argument + nodeFrom.asExpr() = nco.getAnOperand() + or + // unpack closure (the second argument is an `AutoClosureExpr` argument) + nodeFrom.asExpr() = nco.getAnOperand().(AutoClosureExpr).getExpr() + ) + or + // flow through ternary operator `? :` + exists(IfExpr ie | + nodeTo.asExpr() = ie and + nodeFrom.asExpr() = ie.getBranch(_) + ) + or // flow through a flow summary (extension of `SummaryModelCsv`) FlowSummaryImpl::Private::Steps::summaryLocalStep(nodeFrom, nodeTo, true) } diff --git a/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExpr.qll b/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExpr.qll index 6098a1e04cc..aab42ca0af7 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExpr.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExpr.qll @@ -1,9 +1,29 @@ private import codeql.swift.generated.expr.AutoClosureExpr private import codeql.swift.elements.stmt.ReturnStmt +private import codeql.swift.elements.expr.Expr +/** + * A Swift autoclosure expression, that is, a closure automatically generated + * around an argument when the parameter has the `@autoclosure` attribute. For + * example, there is an `AutoClosureExpr` around the value `0` in: + * ``` + * func myFunction(_ expr: @autoclosure () -> Int) { + * ... + * } + * + * myFunction(0) + * ``` + */ class AutoClosureExpr extends Generated::AutoClosureExpr { - /** Gets the implicit return statement generated by this autoclosure expression. */ + /** + * Gets the implicit return statement generated by this autoclosure expression. + */ ReturnStmt getReturn() { result = unique( | | this.getBody().getAnElement()) } + /** + * Gets the expression returned by this autoclosure expression. + */ + Expr getExpr() { result = this.getReturn().getResult() } + override string toString() { result = this.getBody().toString() } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/BinaryExpr.qll b/swift/ql/lib/codeql/swift/elements/expr/BinaryExpr.qll index b75704bc1b1..29b86fa2adf 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/BinaryExpr.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/BinaryExpr.qll @@ -1,11 +1,33 @@ private import codeql.swift.generated.expr.BinaryExpr private import codeql.swift.elements.expr.Expr +private import codeql.swift.elements.decl.AbstractFunctionDecl +/** + * A Swift binary expression, that is, an expression that appears between its + * two operands. For example: + * ``` + * x + y + * ``` + */ class BinaryExpr extends Generated::BinaryExpr { + /** + * Gets the left operand (left expression) of this binary expression. + */ Expr getLeftOperand() { result = this.getArgument(0).getExpr() } + /** + * Gets the right operand (right expression) of this binary expression. + */ Expr getRightOperand() { result = this.getArgument(1).getExpr() } + /** + * Gets the operator of this binary expression (the function that is called). + */ + AbstractFunctionDecl getOperator() { result = this.getStaticTarget() } + + /** + * Gets an operand of this binary expression (left or right). + */ Expr getAnOperand() { result = [this.getLeftOperand(), this.getRightOperand()] } override string toString() { result = "... " + this.getFunction().toString() + " ..." } diff --git a/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExpr.qll b/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExpr.qll index 46742454650..77150da54a1 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExpr.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExpr.qll @@ -1,4 +1,22 @@ -// generated by codegen/codegen.py, remove this comment if you wish to edit this file private import codeql.swift.generated.expr.PostfixUnaryExpr +private import codeql.swift.elements.expr.Expr +private import codeql.swift.elements.decl.AbstractFunctionDecl -class PostfixUnaryExpr extends Generated::PostfixUnaryExpr { } +/** + * A Swift postfix unary expression, that is, a unary expression that appears + * after its operand. For example: + * ``` + * x! + * ``` + */ +class PostfixUnaryExpr extends Generated::PostfixUnaryExpr { + /** + * Gets the operand (expression) of this postfix unary expression. + */ + Expr getOperand() { result = this.getAnArgument().getExpr() } + + /** + * Gets the operator of this postfix unary expression (the function that is called). + */ + AbstractFunctionDecl getOperator() { result = this.getStaticTarget() } +} diff --git a/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExpr.qll b/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExpr.qll index b9a1ecd4ee9..0cd1e25ad6b 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExpr.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExpr.qll @@ -1,6 +1,22 @@ private import codeql.swift.generated.expr.PrefixUnaryExpr private import codeql.swift.elements.expr.Expr +private import codeql.swift.elements.decl.AbstractFunctionDecl +/** + * A Swift prefix unary expression, that is, a unary expression that appears + * before its operand. For example: + * ``` + * -x + * ``` + */ class PrefixUnaryExpr extends Generated::PrefixUnaryExpr { + /** + * Gets the operand (expression) of this prefix unary expression. + */ Expr getOperand() { result = this.getAnArgument().getExpr() } + + /** + * Gets the operator of this prefix unary expression (the function that is called). + */ + AbstractFunctionDecl getOperator() { result = this.getStaticTarget() } } diff --git a/swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected b/swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected index c4e0a7a01e6..1277d30cdc2 100644 --- a/swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected +++ b/swift/ql/test/library-tests/dataflow/dataflow/DataFlow.expected @@ -100,29 +100,36 @@ edges | test.swift:225:14:225:21 | call to source() : | test.swift:235:13:235:15 | .source_value | | test.swift:225:14:225:21 | call to source() : | test.swift:238:13:238:15 | .source_value | | test.swift:259:12:259:19 | call to source() : | test.swift:263:13:263:28 | call to optionalSource() : | -| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:264:15:264:16 | ...! | -| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:266:15:266:16 | ...? : | -| test.swift:265:15:265:22 | call to source() : | file://:0:0:0:0 | [summary param] this in signum() : | -| test.swift:265:15:265:22 | call to source() : | test.swift:265:15:265:31 | call to signum() | -| test.swift:266:15:266:16 | ...? : | file://:0:0:0:0 | [summary param] this in signum() : | -| test.swift:266:15:266:16 | ...? : | test.swift:266:15:266:25 | call to signum() : | -| test.swift:266:15:266:25 | call to signum() : | test.swift:266:15:266:25 | OptionalEvaluationExpr | -| test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | -| test.swift:277:18:277:25 | call to source() : | test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | -| test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | test.swift:281:15:281:18 | .1 | -| test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : | test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | -| test.swift:289:12:289:19 | call to source() : | test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : | -| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | test.swift:292:15:292:18 | .0 | -| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:302:15:302:15 | t1 [Tuple element at index 0] : | -| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | test.swift:306:15:306:15 | t2 [Tuple element at index 0] : | -| test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | test.swift:303:15:303:15 | t1 [Tuple element at index 1] : | -| test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | test.swift:307:15:307:15 | t2 [Tuple element at index 1] : | -| test.swift:297:18:297:25 | call to source() : | test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | -| test.swift:297:31:297:38 | call to source() : | test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | -| test.swift:302:15:302:15 | t1 [Tuple element at index 0] : | test.swift:302:15:302:18 | .0 | -| test.swift:303:15:303:15 | t1 [Tuple element at index 1] : | test.swift:303:15:303:18 | .1 | -| test.swift:306:15:306:15 | t2 [Tuple element at index 0] : | test.swift:306:15:306:18 | .0 | -| test.swift:307:15:307:15 | t2 [Tuple element at index 1] : | test.swift:307:15:307:18 | .1 | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:265:15:265:15 | x | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:267:15:267:16 | ...! | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:271:15:271:16 | ...? : | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:274:15:274:20 | ... ??(_:_:) ... | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:275:15:275:27 | ... ??(_:_:) ... | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:279:15:279:31 | ... ? ... : ... | +| test.swift:263:13:263:28 | call to optionalSource() : | test.swift:280:15:280:38 | ... ? ... : ... | +| test.swift:270:15:270:22 | call to source() : | file://:0:0:0:0 | [summary param] this in signum() : | +| test.swift:270:15:270:22 | call to source() : | test.swift:270:15:270:31 | call to signum() | +| test.swift:271:15:271:16 | ...? : | file://:0:0:0:0 | [summary param] this in signum() : | +| test.swift:271:15:271:16 | ...? : | test.swift:271:15:271:25 | call to signum() : | +| test.swift:271:15:271:25 | call to signum() : | test.swift:271:15:271:25 | OptionalEvaluationExpr | +| test.swift:280:31:280:38 | call to source() : | test.swift:280:15:280:38 | ... ? ... : ... | +| test.swift:282:31:282:38 | call to source() : | test.swift:282:15:282:38 | ... ? ... : ... | +| test.swift:302:14:302:26 | (...) [Tuple element at index 1] : | test.swift:306:15:306:15 | t1 [Tuple element at index 1] : | +| test.swift:302:18:302:25 | call to source() : | test.swift:302:14:302:26 | (...) [Tuple element at index 1] : | +| test.swift:306:15:306:15 | t1 [Tuple element at index 1] : | test.swift:306:15:306:18 | .1 | +| test.swift:314:5:314:5 | [post] t1 [Tuple element at index 0] : | test.swift:317:15:317:15 | t1 [Tuple element at index 0] : | +| test.swift:314:12:314:19 | call to source() : | test.swift:314:5:314:5 | [post] t1 [Tuple element at index 0] : | +| test.swift:317:15:317:15 | t1 [Tuple element at index 0] : | test.swift:317:15:317:18 | .0 | +| test.swift:322:14:322:45 | (...) [Tuple element at index 0] : | test.swift:327:15:327:15 | t1 [Tuple element at index 0] : | +| test.swift:322:14:322:45 | (...) [Tuple element at index 0] : | test.swift:331:15:331:15 | t2 [Tuple element at index 0] : | +| test.swift:322:14:322:45 | (...) [Tuple element at index 1] : | test.swift:328:15:328:15 | t1 [Tuple element at index 1] : | +| test.swift:322:14:322:45 | (...) [Tuple element at index 1] : | test.swift:332:15:332:15 | t2 [Tuple element at index 1] : | +| test.swift:322:18:322:25 | call to source() : | test.swift:322:14:322:45 | (...) [Tuple element at index 0] : | +| test.swift:322:31:322:38 | call to source() : | test.swift:322:14:322:45 | (...) [Tuple element at index 1] : | +| test.swift:327:15:327:15 | t1 [Tuple element at index 0] : | test.swift:327:15:327:18 | .0 | +| test.swift:328:15:328:15 | t1 [Tuple element at index 1] : | test.swift:328:15:328:18 | .1 | +| test.swift:331:15:331:15 | t2 [Tuple element at index 0] : | test.swift:331:15:331:18 | .0 | +| test.swift:332:15:332:15 | t2 [Tuple element at index 1] : | test.swift:332:15:332:18 | .1 | nodes | file://:0:0:0:0 | .a [x] : | semmle.label | .a [x] : | | file://:0:0:0:0 | .x : | semmle.label | .x : | @@ -237,32 +244,40 @@ nodes | test.swift:238:13:238:15 | .source_value | semmle.label | .source_value | | test.swift:259:12:259:19 | call to source() : | semmle.label | call to source() : | | test.swift:263:13:263:28 | call to optionalSource() : | semmle.label | call to optionalSource() : | -| test.swift:264:15:264:16 | ...! | semmle.label | ...! | -| test.swift:265:15:265:22 | call to source() : | semmle.label | call to source() : | -| test.swift:265:15:265:31 | call to signum() | semmle.label | call to signum() | -| test.swift:266:15:266:16 | ...? : | semmle.label | ...? : | -| test.swift:266:15:266:25 | OptionalEvaluationExpr | semmle.label | OptionalEvaluationExpr | -| test.swift:266:15:266:25 | call to signum() : | semmle.label | call to signum() : | -| test.swift:277:14:277:26 | (...) [Tuple element at index 1] : | semmle.label | (...) [Tuple element at index 1] : | -| test.swift:277:18:277:25 | call to source() : | semmle.label | call to source() : | -| test.swift:281:15:281:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : | -| test.swift:281:15:281:18 | .1 | semmle.label | .1 | -| test.swift:289:5:289:5 | [post] t1 [Tuple element at index 0] : | semmle.label | [post] t1 [Tuple element at index 0] : | -| test.swift:289:12:289:19 | call to source() : | semmle.label | call to source() : | -| test.swift:292:15:292:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : | -| test.swift:292:15:292:18 | .0 | semmle.label | .0 | -| test.swift:297:14:297:45 | (...) [Tuple element at index 0] : | semmle.label | (...) [Tuple element at index 0] : | -| test.swift:297:14:297:45 | (...) [Tuple element at index 1] : | semmle.label | (...) [Tuple element at index 1] : | -| test.swift:297:18:297:25 | call to source() : | semmle.label | call to source() : | -| test.swift:297:31:297:38 | call to source() : | semmle.label | call to source() : | -| test.swift:302:15:302:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : | -| test.swift:302:15:302:18 | .0 | semmle.label | .0 | -| test.swift:303:15:303:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : | -| test.swift:303:15:303:18 | .1 | semmle.label | .1 | -| test.swift:306:15:306:15 | t2 [Tuple element at index 0] : | semmle.label | t2 [Tuple element at index 0] : | -| test.swift:306:15:306:18 | .0 | semmle.label | .0 | -| test.swift:307:15:307:15 | t2 [Tuple element at index 1] : | semmle.label | t2 [Tuple element at index 1] : | -| test.swift:307:15:307:18 | .1 | semmle.label | .1 | +| test.swift:265:15:265:15 | x | semmle.label | x | +| test.swift:267:15:267:16 | ...! | semmle.label | ...! | +| test.swift:270:15:270:22 | call to source() : | semmle.label | call to source() : | +| test.swift:270:15:270:31 | call to signum() | semmle.label | call to signum() | +| test.swift:271:15:271:16 | ...? : | semmle.label | ...? : | +| test.swift:271:15:271:25 | OptionalEvaluationExpr | semmle.label | OptionalEvaluationExpr | +| test.swift:271:15:271:25 | call to signum() : | semmle.label | call to signum() : | +| test.swift:274:15:274:20 | ... ??(_:_:) ... | semmle.label | ... ??(_:_:) ... | +| test.swift:275:15:275:27 | ... ??(_:_:) ... | semmle.label | ... ??(_:_:) ... | +| test.swift:279:15:279:31 | ... ? ... : ... | semmle.label | ... ? ... : ... | +| test.swift:280:15:280:38 | ... ? ... : ... | semmle.label | ... ? ... : ... | +| test.swift:280:31:280:38 | call to source() : | semmle.label | call to source() : | +| test.swift:282:15:282:38 | ... ? ... : ... | semmle.label | ... ? ... : ... | +| test.swift:282:31:282:38 | call to source() : | semmle.label | call to source() : | +| test.swift:302:14:302:26 | (...) [Tuple element at index 1] : | semmle.label | (...) [Tuple element at index 1] : | +| test.swift:302:18:302:25 | call to source() : | semmle.label | call to source() : | +| test.swift:306:15:306:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : | +| test.swift:306:15:306:18 | .1 | semmle.label | .1 | +| test.swift:314:5:314:5 | [post] t1 [Tuple element at index 0] : | semmle.label | [post] t1 [Tuple element at index 0] : | +| test.swift:314:12:314:19 | call to source() : | semmle.label | call to source() : | +| test.swift:317:15:317:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : | +| test.swift:317:15:317:18 | .0 | semmle.label | .0 | +| test.swift:322:14:322:45 | (...) [Tuple element at index 0] : | semmle.label | (...) [Tuple element at index 0] : | +| test.swift:322:14:322:45 | (...) [Tuple element at index 1] : | semmle.label | (...) [Tuple element at index 1] : | +| test.swift:322:18:322:25 | call to source() : | semmle.label | call to source() : | +| test.swift:322:31:322:38 | call to source() : | semmle.label | call to source() : | +| test.swift:327:15:327:15 | t1 [Tuple element at index 0] : | semmle.label | t1 [Tuple element at index 0] : | +| test.swift:327:15:327:18 | .0 | semmle.label | .0 | +| test.swift:328:15:328:15 | t1 [Tuple element at index 1] : | semmle.label | t1 [Tuple element at index 1] : | +| test.swift:328:15:328:18 | .1 | semmle.label | .1 | +| test.swift:331:15:331:15 | t2 [Tuple element at index 0] : | semmle.label | t2 [Tuple element at index 0] : | +| test.swift:331:15:331:18 | .0 | semmle.label | .0 | +| test.swift:332:15:332:15 | t2 [Tuple element at index 1] : | semmle.label | t2 [Tuple element at index 1] : | +| test.swift:332:15:332:18 | .1 | semmle.label | .1 | subpaths | test.swift:75:21:75:22 | &... : | test.swift:65:16:65:28 | arg1 : | test.swift:65:1:70:1 | arg2[return] : | test.swift:75:31:75:32 | [post] &... : | | test.swift:114:19:114:19 | arg : | test.swift:109:9:109:14 | arg : | test.swift:110:12:110:12 | arg : | test.swift:114:12:114:22 | call to ... : | @@ -289,8 +304,8 @@ subpaths | test.swift:218:11:218:18 | call to source() : | test.swift:169:12:169:22 | value : | test.swift:170:5:170:5 | [post] self [x] : | test.swift:218:3:218:5 | [post] getter for .a [x] : | | test.swift:219:13:219:13 | b [a, x] : | test.swift:185:7:185:7 | self [a, x] : | file://:0:0:0:0 | .a [x] : | test.swift:219:13:219:15 | .a [x] : | | test.swift:219:13:219:15 | .a [x] : | test.swift:163:7:163:7 | self [x] : | file://:0:0:0:0 | .x : | test.swift:219:13:219:17 | .x | -| test.swift:265:15:265:22 | call to source() : | file://:0:0:0:0 | [summary param] this in signum() : | file://:0:0:0:0 | [summary] to write: return (return) in signum() : | test.swift:265:15:265:31 | call to signum() | -| test.swift:266:15:266:16 | ...? : | file://:0:0:0:0 | [summary param] this in signum() : | file://:0:0:0:0 | [summary] to write: return (return) in signum() : | test.swift:266:15:266:25 | call to signum() : | +| test.swift:270:15:270:22 | call to source() : | file://:0:0:0:0 | [summary param] this in signum() : | file://:0:0:0:0 | [summary] to write: return (return) in signum() : | test.swift:270:15:270:31 | call to signum() | +| test.swift:271:15:271:16 | ...? : | file://:0:0:0:0 | [summary param] this in signum() : | file://:0:0:0:0 | [summary] to write: return (return) in signum() : | test.swift:271:15:271:25 | call to signum() : | #select | test.swift:7:15:7:15 | t1 | test.swift:6:19:6:26 | call to source() : | test.swift:7:15:7:15 | t1 | result | | test.swift:9:15:9:15 | t1 | test.swift:6:19:6:26 | call to source() : | test.swift:9:15:9:15 | t1 | result | @@ -320,12 +335,19 @@ subpaths | test.swift:219:13:219:17 | .x | test.swift:218:11:218:18 | call to source() : | test.swift:219:13:219:17 | .x | result | | test.swift:235:13:235:15 | .source_value | test.swift:225:14:225:21 | call to source() : | test.swift:235:13:235:15 | .source_value | result | | test.swift:238:13:238:15 | .source_value | test.swift:225:14:225:21 | call to source() : | test.swift:238:13:238:15 | .source_value | result | -| test.swift:264:15:264:16 | ...! | test.swift:259:12:259:19 | call to source() : | test.swift:264:15:264:16 | ...! | result | -| test.swift:265:15:265:31 | call to signum() | test.swift:265:15:265:22 | call to source() : | test.swift:265:15:265:31 | call to signum() | result | -| test.swift:266:15:266:25 | OptionalEvaluationExpr | test.swift:259:12:259:19 | call to source() : | test.swift:266:15:266:25 | OptionalEvaluationExpr | result | -| test.swift:281:15:281:18 | .1 | test.swift:277:18:277:25 | call to source() : | test.swift:281:15:281:18 | .1 | result | -| test.swift:292:15:292:18 | .0 | test.swift:289:12:289:19 | call to source() : | test.swift:292:15:292:18 | .0 | result | -| test.swift:302:15:302:18 | .0 | test.swift:297:18:297:25 | call to source() : | test.swift:302:15:302:18 | .0 | result | -| test.swift:303:15:303:18 | .1 | test.swift:297:31:297:38 | call to source() : | test.swift:303:15:303:18 | .1 | result | -| test.swift:306:15:306:18 | .0 | test.swift:297:18:297:25 | call to source() : | test.swift:306:15:306:18 | .0 | result | -| test.swift:307:15:307:18 | .1 | test.swift:297:31:297:38 | call to source() : | test.swift:307:15:307:18 | .1 | result | +| test.swift:265:15:265:15 | x | test.swift:259:12:259:19 | call to source() : | test.swift:265:15:265:15 | x | result | +| test.swift:267:15:267:16 | ...! | test.swift:259:12:259:19 | call to source() : | test.swift:267:15:267:16 | ...! | result | +| test.swift:270:15:270:31 | call to signum() | test.swift:270:15:270:22 | call to source() : | test.swift:270:15:270:31 | call to signum() | result | +| test.swift:271:15:271:25 | OptionalEvaluationExpr | test.swift:259:12:259:19 | call to source() : | test.swift:271:15:271:25 | OptionalEvaluationExpr | result | +| test.swift:274:15:274:20 | ... ??(_:_:) ... | test.swift:259:12:259:19 | call to source() : | test.swift:274:15:274:20 | ... ??(_:_:) ... | result | +| test.swift:275:15:275:27 | ... ??(_:_:) ... | test.swift:259:12:259:19 | call to source() : | test.swift:275:15:275:27 | ... ??(_:_:) ... | result | +| test.swift:279:15:279:31 | ... ? ... : ... | test.swift:259:12:259:19 | call to source() : | test.swift:279:15:279:31 | ... ? ... : ... | result | +| test.swift:280:15:280:38 | ... ? ... : ... | test.swift:259:12:259:19 | call to source() : | test.swift:280:15:280:38 | ... ? ... : ... | result | +| test.swift:280:15:280:38 | ... ? ... : ... | test.swift:280:31:280:38 | call to source() : | test.swift:280:15:280:38 | ... ? ... : ... | result | +| test.swift:282:15:282:38 | ... ? ... : ... | test.swift:282:31:282:38 | call to source() : | test.swift:282:15:282:38 | ... ? ... : ... | result | +| test.swift:306:15:306:18 | .1 | test.swift:302:18:302:25 | call to source() : | test.swift:306:15:306:18 | .1 | result | +| test.swift:317:15:317:18 | .0 | test.swift:314:12:314:19 | call to source() : | test.swift:317:15:317:18 | .0 | result | +| test.swift:327:15:327:18 | .0 | test.swift:322:18:322:25 | call to source() : | test.swift:327:15:327:18 | .0 | result | +| test.swift:328:15:328:18 | .1 | test.swift:322:31:322:38 | call to source() : | test.swift:328:15:328:18 | .1 | result | +| test.swift:331:15:331:18 | .0 | test.swift:322:18:322:25 | call to source() : | test.swift:331:15:331:18 | .0 | result | +| test.swift:332:15:332:18 | .1 | test.swift:322:31:322:38 | call to source() : | test.swift:332:15:332:18 | .1 | result | diff --git a/swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected b/swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected index a4a883a2808..721505ee087 100644 --- a/swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected +++ b/swift/ql/test/library-tests/dataflow/dataflow/LocalFlow.expected @@ -184,52 +184,102 @@ | test.swift:247:9:247:9 | [post] self | test.swift:246:5:248:5 | self[return] | | test.swift:247:9:247:9 | self | test.swift:246:5:248:5 | self[return] | | test.swift:252:23:252:23 | value | test.swift:252:23:252:23 | SSA def(value) | -| test.swift:263:9:263:9 | SSA def(x) | test.swift:264:15:264:15 | x | +| test.swift:262:21:262:27 | SSA def(y) | test.swift:266:15:266:15 | y | +| test.swift:262:21:262:27 | y | test.swift:262:21:262:27 | SSA def(y) | +| test.swift:263:9:263:9 | SSA def(x) | test.swift:265:15:265:15 | x | | test.swift:263:13:263:28 | call to optionalSource() | test.swift:263:9:263:9 | SSA def(x) | -| test.swift:264:15:264:15 | x | test.swift:264:15:264:16 | ...! | -| test.swift:264:15:264:15 | x | test.swift:266:15:266:15 | x | -| test.swift:266:15:266:15 | x | test.swift:266:15:266:16 | ...? | -| test.swift:266:15:266:15 | x | test.swift:267:15:267:15 | x | -| test.swift:266:15:266:25 | call to signum() | test.swift:266:15:266:25 | OptionalEvaluationExpr | -| test.swift:267:15:267:15 | x | test.swift:268:16:268:16 | x | -| test.swift:277:9:277:9 | SSA def(t1) | test.swift:279:15:279:15 | t1 | -| test.swift:277:14:277:26 | (...) | test.swift:277:9:277:9 | SSA def(t1) | -| test.swift:279:15:279:15 | t1 | test.swift:280:15:280:15 | t1 | -| test.swift:280:15:280:15 | [post] t1 | test.swift:281:15:281:15 | t1 | -| test.swift:280:15:280:15 | t1 | test.swift:281:15:281:15 | t1 | -| test.swift:281:15:281:15 | [post] t1 | test.swift:283:5:283:5 | t1 | -| test.swift:281:15:281:15 | t1 | test.swift:283:5:283:5 | t1 | -| test.swift:283:5:283:5 | [post] t1 | test.swift:285:15:285:15 | t1 | -| test.swift:283:5:283:5 | t1 | test.swift:285:15:285:15 | t1 | -| test.swift:285:15:285:15 | t1 | test.swift:286:15:286:15 | t1 | -| test.swift:286:15:286:15 | [post] t1 | test.swift:287:15:287:15 | t1 | -| test.swift:286:15:286:15 | t1 | test.swift:287:15:287:15 | t1 | -| test.swift:287:15:287:15 | [post] t1 | test.swift:289:5:289:5 | t1 | -| test.swift:287:15:287:15 | t1 | test.swift:289:5:289:5 | t1 | -| test.swift:289:5:289:5 | [post] t1 | test.swift:291:15:291:15 | t1 | -| test.swift:289:5:289:5 | t1 | test.swift:291:15:291:15 | t1 | -| test.swift:291:15:291:15 | t1 | test.swift:292:15:292:15 | t1 | -| test.swift:292:15:292:15 | [post] t1 | test.swift:293:15:293:15 | t1 | -| test.swift:292:15:292:15 | t1 | test.swift:293:15:293:15 | t1 | -| test.swift:297:9:297:9 | SSA def(t1) | test.swift:298:14:298:14 | t1 | -| test.swift:297:14:297:45 | (...) | test.swift:297:9:297:9 | SSA def(t1) | -| test.swift:298:9:298:9 | SSA def(t2) | test.swift:305:15:305:15 | t2 | -| test.swift:298:14:298:14 | t1 | test.swift:298:9:298:9 | SSA def(t2) | -| test.swift:298:14:298:14 | t1 | test.swift:299:21:299:21 | t1 | -| test.swift:299:9:299:17 | SSA def(a) | test.swift:309:15:309:15 | a | -| test.swift:299:9:299:17 | SSA def(b) | test.swift:310:15:310:15 | b | -| test.swift:299:9:299:17 | SSA def(c) | test.swift:311:15:311:15 | c | -| test.swift:299:21:299:21 | t1 | test.swift:299:9:299:17 | SSA def(a) | -| test.swift:299:21:299:21 | t1 | test.swift:299:9:299:17 | SSA def(b) | -| test.swift:299:21:299:21 | t1 | test.swift:299:9:299:17 | SSA def(c) | -| test.swift:299:21:299:21 | t1 | test.swift:301:15:301:15 | t1 | -| test.swift:301:15:301:15 | t1 | test.swift:302:15:302:15 | t1 | -| test.swift:302:15:302:15 | [post] t1 | test.swift:303:15:303:15 | t1 | -| test.swift:302:15:302:15 | t1 | test.swift:303:15:303:15 | t1 | -| test.swift:303:15:303:15 | [post] t1 | test.swift:304:15:304:15 | t1 | -| test.swift:303:15:303:15 | t1 | test.swift:304:15:304:15 | t1 | -| test.swift:305:15:305:15 | t2 | test.swift:306:15:306:15 | t2 | -| test.swift:306:15:306:15 | [post] t2 | test.swift:307:15:307:15 | t2 | -| test.swift:306:15:306:15 | t2 | test.swift:307:15:307:15 | t2 | -| test.swift:307:15:307:15 | [post] t2 | test.swift:308:15:308:15 | t2 | -| test.swift:307:15:307:15 | t2 | test.swift:308:15:308:15 | t2 | +| test.swift:265:15:265:15 | x | test.swift:267:15:267:15 | x | +| test.swift:266:15:266:15 | y | test.swift:268:15:268:15 | y | +| test.swift:267:15:267:15 | x | test.swift:267:15:267:16 | ...! | +| test.swift:267:15:267:15 | x | test.swift:271:15:271:15 | x | +| test.swift:268:15:268:15 | y | test.swift:268:15:268:16 | ...! | +| test.swift:268:15:268:15 | y | test.swift:272:15:272:15 | y | +| test.swift:271:15:271:15 | x | test.swift:271:15:271:16 | ...? | +| test.swift:271:15:271:15 | x | test.swift:274:15:274:15 | x | +| test.swift:271:15:271:25 | call to signum() | test.swift:271:15:271:25 | OptionalEvaluationExpr | +| test.swift:272:15:272:15 | y | test.swift:272:15:272:16 | ...? | +| test.swift:272:15:272:15 | y | test.swift:276:15:276:15 | y | +| test.swift:272:15:272:25 | call to signum() | test.swift:272:15:272:25 | OptionalEvaluationExpr | +| test.swift:274:15:274:15 | x | test.swift:274:15:274:20 | ... ??(_:_:) ... | +| test.swift:274:15:274:15 | x | test.swift:275:15:275:15 | x | +| test.swift:274:20:274:20 | { ... } | test.swift:274:15:274:20 | ... ??(_:_:) ... | +| test.swift:275:15:275:15 | x | test.swift:275:15:275:27 | ... ??(_:_:) ... | +| test.swift:275:15:275:15 | x | test.swift:279:15:279:15 | x | +| test.swift:275:20:275:27 | { ... } | test.swift:275:15:275:27 | ... ??(_:_:) ... | +| test.swift:276:15:276:15 | y | test.swift:276:15:276:20 | ... ??(_:_:) ... | +| test.swift:276:15:276:15 | y | test.swift:277:15:277:15 | y | +| test.swift:276:20:276:20 | { ... } | test.swift:276:15:276:20 | ... ??(_:_:) ... | +| test.swift:277:15:277:15 | y | test.swift:277:15:277:27 | ... ??(_:_:) ... | +| test.swift:277:15:277:15 | y | test.swift:281:15:281:15 | y | +| test.swift:277:20:277:27 | { ... } | test.swift:277:15:277:27 | ... ??(_:_:) ... | +| test.swift:279:15:279:15 | x | test.swift:279:26:279:26 | x | +| test.swift:279:15:279:15 | x | test.swift:280:15:280:15 | x | +| test.swift:279:26:279:26 | x | test.swift:279:26:279:27 | ...! | +| test.swift:279:26:279:26 | x | test.swift:280:15:280:15 | x | +| test.swift:279:26:279:27 | ...! | test.swift:279:15:279:31 | ... ? ... : ... | +| test.swift:279:31:279:31 | 0 | test.swift:279:15:279:31 | ... ? ... : ... | +| test.swift:280:15:280:15 | x | test.swift:280:26:280:26 | x | +| test.swift:280:15:280:15 | x | test.swift:284:16:284:16 | x | +| test.swift:280:26:280:26 | x | test.swift:280:26:280:27 | ...! | +| test.swift:280:26:280:26 | x | test.swift:284:16:284:16 | x | +| test.swift:280:26:280:27 | ...! | test.swift:280:15:280:38 | ... ? ... : ... | +| test.swift:280:31:280:38 | call to source() | test.swift:280:15:280:38 | ... ? ... : ... | +| test.swift:281:15:281:15 | y | test.swift:281:26:281:26 | y | +| test.swift:281:15:281:15 | y | test.swift:282:15:282:15 | y | +| test.swift:281:26:281:26 | y | test.swift:281:26:281:27 | ...! | +| test.swift:281:26:281:26 | y | test.swift:282:15:282:15 | y | +| test.swift:281:26:281:27 | ...! | test.swift:281:15:281:31 | ... ? ... : ... | +| test.swift:281:31:281:31 | 0 | test.swift:281:15:281:31 | ... ? ... : ... | +| test.swift:282:15:282:15 | y | test.swift:282:26:282:26 | y | +| test.swift:282:15:282:15 | y | test.swift:287:16:287:16 | y | +| test.swift:282:26:282:26 | y | test.swift:282:26:282:27 | ...! | +| test.swift:282:26:282:26 | y | test.swift:287:16:287:16 | y | +| test.swift:282:26:282:27 | ...! | test.swift:282:15:282:38 | ... ? ... : ... | +| test.swift:282:31:282:38 | call to source() | test.swift:282:15:282:38 | ... ? ... : ... | +| test.swift:284:16:284:16 | x | test.swift:290:16:290:16 | x | +| test.swift:287:16:287:16 | y | test.swift:293:16:293:16 | y | +| test.swift:290:16:290:16 | x | test.swift:290:16:290:17 | ...? | +| test.swift:290:16:290:26 | call to signum() | test.swift:290:16:290:26 | OptionalEvaluationExpr | +| test.swift:293:16:293:16 | y | test.swift:293:16:293:17 | ...? | +| test.swift:293:16:293:26 | call to signum() | test.swift:293:16:293:26 | OptionalEvaluationExpr | +| test.swift:302:9:302:9 | SSA def(t1) | test.swift:304:15:304:15 | t1 | +| test.swift:302:14:302:26 | (...) | test.swift:302:9:302:9 | SSA def(t1) | +| test.swift:304:15:304:15 | t1 | test.swift:305:15:305:15 | t1 | +| test.swift:305:15:305:15 | [post] t1 | test.swift:306:15:306:15 | t1 | +| test.swift:305:15:305:15 | t1 | test.swift:306:15:306:15 | t1 | +| test.swift:306:15:306:15 | [post] t1 | test.swift:308:5:308:5 | t1 | +| test.swift:306:15:306:15 | t1 | test.swift:308:5:308:5 | t1 | +| test.swift:308:5:308:5 | [post] t1 | test.swift:310:15:310:15 | t1 | +| test.swift:308:5:308:5 | t1 | test.swift:310:15:310:15 | t1 | +| test.swift:310:15:310:15 | t1 | test.swift:311:15:311:15 | t1 | +| test.swift:311:15:311:15 | [post] t1 | test.swift:312:15:312:15 | t1 | +| test.swift:311:15:311:15 | t1 | test.swift:312:15:312:15 | t1 | +| test.swift:312:15:312:15 | [post] t1 | test.swift:314:5:314:5 | t1 | +| test.swift:312:15:312:15 | t1 | test.swift:314:5:314:5 | t1 | +| test.swift:314:5:314:5 | [post] t1 | test.swift:316:15:316:15 | t1 | +| test.swift:314:5:314:5 | t1 | test.swift:316:15:316:15 | t1 | +| test.swift:316:15:316:15 | t1 | test.swift:317:15:317:15 | t1 | +| test.swift:317:15:317:15 | [post] t1 | test.swift:318:15:318:15 | t1 | +| test.swift:317:15:317:15 | t1 | test.swift:318:15:318:15 | t1 | +| test.swift:322:9:322:9 | SSA def(t1) | test.swift:323:14:323:14 | t1 | +| test.swift:322:14:322:45 | (...) | test.swift:322:9:322:9 | SSA def(t1) | +| test.swift:323:9:323:9 | SSA def(t2) | test.swift:330:15:330:15 | t2 | +| test.swift:323:14:323:14 | t1 | test.swift:323:9:323:9 | SSA def(t2) | +| test.swift:323:14:323:14 | t1 | test.swift:324:21:324:21 | t1 | +| test.swift:324:9:324:17 | SSA def(a) | test.swift:334:15:334:15 | a | +| test.swift:324:9:324:17 | SSA def(b) | test.swift:335:15:335:15 | b | +| test.swift:324:9:324:17 | SSA def(c) | test.swift:336:15:336:15 | c | +| test.swift:324:21:324:21 | t1 | test.swift:324:9:324:17 | SSA def(a) | +| test.swift:324:21:324:21 | t1 | test.swift:324:9:324:17 | SSA def(b) | +| test.swift:324:21:324:21 | t1 | test.swift:324:9:324:17 | SSA def(c) | +| test.swift:324:21:324:21 | t1 | test.swift:326:15:326:15 | t1 | +| test.swift:326:15:326:15 | t1 | test.swift:327:15:327:15 | t1 | +| test.swift:327:15:327:15 | [post] t1 | test.swift:328:15:328:15 | t1 | +| test.swift:327:15:327:15 | t1 | test.swift:328:15:328:15 | t1 | +| test.swift:328:15:328:15 | [post] t1 | test.swift:329:15:329:15 | t1 | +| test.swift:328:15:328:15 | t1 | test.swift:329:15:329:15 | t1 | +| test.swift:330:15:330:15 | t2 | test.swift:331:15:331:15 | t2 | +| test.swift:331:15:331:15 | [post] t2 | test.swift:332:15:332:15 | t2 | +| test.swift:331:15:331:15 | t2 | test.swift:332:15:332:15 | t2 | +| test.swift:332:15:332:15 | [post] t2 | test.swift:333:15:333:15 | t2 | +| test.swift:332:15:332:15 | t2 | test.swift:333:15:333:15 | t2 | diff --git a/swift/ql/test/library-tests/dataflow/dataflow/test.swift b/swift/ql/test/library-tests/dataflow/dataflow/test.swift index 23c8d138a2d..093e8c2db95 100644 --- a/swift/ql/test/library-tests/dataflow/dataflow/test.swift +++ b/swift/ql/test/library-tests/dataflow/dataflow/test.swift @@ -259,14 +259,39 @@ func optionalSource() -> Int? { return source() } -func test_optionals() { +func test_optionals(y: Int?) { let x = optionalSource() + + sink(opt: x) // $ flow=259 + sink(opt: y) sink(arg: x!) // $ flow=259 - sink(arg: source().signum()) // $ flow=265 + sink(arg: y!) + + sink(arg: source().signum()) // $ flow=270 sink(opt: x?.signum()) // $ flow=259 - sink(arg: x ?? 0) // $ MISSING: flow=259 - if let y = x { - sink(arg: y) // $ MISSING: flow=259 + sink(opt: y?.signum()) + + sink(arg: x ?? 0) // $ flow=259 + sink(arg: x ?? source()) // $ flow=259 MISSING: flow=276 + sink(arg: y ?? 0) + sink(arg: y ?? source()) // $ MISSING: flow=278 + + sink(arg: x != nil ? x! : 0) // $ flow=259 + sink(arg: x != nil ? x! : source()) // $ flow=259 flow=280 + sink(arg: y != nil ? y! : 0) + sink(arg: y != nil ? y! : source()) // $ flow=282 + + if let z = x { + sink(arg: z) // $ MISSING: flow=259 + } + if let z = y { + sink(arg: z) + } + if let z = x?.signum() { // $ MISSING: flow=259 + sink(arg: z) + } + if let z = y?.signum() { + sink(arg: z) } } @@ -278,7 +303,7 @@ func testTuples() { sink(arg: t1) sink(arg: t1.0) - sink(arg: t1.1) // $ flow=277 + sink(arg: t1.1) // $ flow=302 t1.1 = 2 @@ -289,7 +314,7 @@ func testTuples() { t1.0 = source() sink(arg: t1) - sink(arg: t1.0) // $ flow=289 + sink(arg: t1.0) // $ flow=314 sink(arg: t1.1) } @@ -299,14 +324,14 @@ func testTuples2() { let (a, b, c) = t1 sink(arg: t1) - sink(arg: t1.x) // $ flow=297 - sink(arg: t1.y) // $ flow=297 + sink(arg: t1.x) // $ flow=322 + sink(arg: t1.y) // $ flow=322 sink(arg: t1.z) sink(arg: t2) - sink(arg: t2.x) // $ flow=297 - sink(arg: t2.y) // $ flow=297 + sink(arg: t2.x) // $ flow=322 + sink(arg: t2.y) // $ flow=322 sink(arg: t2.z) - sink(arg: a) // $ MISSING: flow=297 - sink(arg: b) // $ MISSING: flow=297 + sink(arg: a) // $ MISSING: flow=322 + sink(arg: b) // $ MISSING: flow=322 sink(arg: c) }