Swift: add new implicit conversion

This commit is contained in:
Alex Denisov 2022-11-23 12:33:41 +01:00
Родитель 90d471b486
Коммит f618d53302
15 изменённых файлов: 96 добавлений и 12 удалений

Просмотреть файл

@ -36,6 +36,8 @@ using SILTokenTypeTag = void;
// This is created during type checking and is only used for constraint checking
using TypeVariableTypeTag = void;
using ABISafeConversionExprTag = AbiSafeConversionExprTag;
#define MAP_TYPE_TO_TAG(TYPE, TAG) \
template <> \
struct detail::ToTagFunctor<TYPE> { \

Просмотреть файл

@ -58,6 +58,8 @@ ql/lib/codeql/swift/elements/decl/TopLevelCodeDeclConstructor.qll 6920a4e7aec45a
ql/lib/codeql/swift/elements/decl/TypeAliasDecl.qll ecb457a9a81c6b13a1068f471c0b87e59227838f54c5d4effe7d4c2f6e7f5800 630dc9cbf20603855c599a9f86037ba0d889ad3d2c2b6f9ac17508d398bff9e3
ql/lib/codeql/swift/elements/decl/TypeAliasDeclConstructor.qll ba70bb69b3a14283def254cc1859c29963838f624b3f1062a200a8df38f1edd5 96ac51d1b3156d4139e583f7f803e9eb95fe25cc61c12986e1b2972a781f9c8b
ql/lib/codeql/swift/elements/decl/ValueDecl.qll b344768498e0d1794d92bc5b7c0417e75079aa8a82e27d7b3449f1e52f78d1e9 e3056cf6a883da2737cb220a89499a9e3977eb1c56b9e1d2f41a56b71a0c29f9
ql/lib/codeql/swift/elements/expr/AbiSafeConversionExpr.qll 599bdb52d99a1e2800563209cecc01a5b5eb80cb4aff36b2d037b67c34ebb948 a87738539276438cef63145461adf25309d1938cfac367f53f53d33db9b12844
ql/lib/codeql/swift/elements/expr/AbiSafeConversionExprConstructor.qll 7d70e7c47a9919efcb1ebcbf70e69cab1be30dd006297b75f6d72b25ae75502a e7a741c42401963f0c1da414b3ae779adeba091e9b8f56c9abf2a686e3a04d52
ql/lib/codeql/swift/elements/expr/AbstractClosureExpr.qll 125f8bd8f21c95c439616744539577afcfa9fd63c65683132a2c971abcec3523 400790fe643585ad39f40c433eff8934bbe542d140b81341bca3b6dfc5b22861
ql/lib/codeql/swift/elements/expr/AnyHashableErasureExpr.qll 20dd848a35a47af94d0fb8cf1a33a2bd6582c751440708c365cf338e522f6de5 bf80cab3e9ff5366a6223153409f4852acdb9e4a5d464fb73b2a8cffc664ca29
ql/lib/codeql/swift/elements/expr/AnyHashableErasureExprConstructor.qll 12816f18d079477176519a20b0f1262fc84da98f60bce3d3dd6476098c6542e7 4cc5c8492a97f4639e7d857f2fca9065293dfa953d6af451206ce911cda9f323
@ -366,7 +368,7 @@ ql/lib/codeql/swift/elements/type/VariadicSequenceType.qll 5bca77dd661d3b2653d31
ql/lib/codeql/swift/elements/type/VariadicSequenceTypeConstructor.qll 0d1d2328a3b5e503a883e7e6d7efd0ca5e7f2633abead9e4c94a9f98ed3cb223 69bff81c1b9413949eacb9298d2efb718ea808e68364569a1090c9878c4af856
ql/lib/codeql/swift/elements/type/WeakStorageType.qll 87a28616eea3600fb0156fffcd65eeddc1ea74ce9c0ba5886c6365b9359e00ce 9c968414d7cc8d672f3754bced5d4f83f43a6d7872d0d263d79ff60483e1f996
ql/lib/codeql/swift/elements/type/WeakStorageTypeConstructor.qll d88b031ef44d6de14b3ddcff2eb47b53dbd11550c37250ff2edb42e5d21ec3e9 26d855c33492cf7a118e439f7baeed0e5425cfaf058b1dcc007eca7ed765c897
ql/lib/codeql/swift/elements.qll af0ce7fc361a5cffdbdfbe1c7ff2a5addf6b8a79e3fc062f266776bc97886c33 af0ce7fc361a5cffdbdfbe1c7ff2a5addf6b8a79e3fc062f266776bc97886c33
ql/lib/codeql/swift/elements.qll 954945d6d4939b28e024b85f77c58ab5b4fab2c931aa5650e22d8ded97a7eda9 954945d6d4939b28e024b85f77c58ab5b4fab2c931aa5650e22d8ded97a7eda9
ql/lib/codeql/swift/generated/AstNode.qll 02ca56d82801f942ae6265c6079d92ccafdf6b532f6bcebd98a04029ddf696e4 6216fda240e45bd4302fa0cf0f08f5f945418b144659264cdda84622b0420aa2
ql/lib/codeql/swift/generated/Callable.qll f4050fac68d745fe0fc4d7bd6cff7c326d6c19a5820a780e1d7e589328b1e550 b6540534acc0b583481a18918264b95a129f13ad26256abe667bf4f72c4432d2
ql/lib/codeql/swift/generated/Comment.qll f58b49f6e68c21f87c51e2ff84c8a64b09286d733e86f70d67d3a98fe6260bd6 975bbb599a2a7adc35179f6ae06d9cbc56ea8a03b972ef2ee87604834bc6deb1
@ -378,11 +380,11 @@ ql/lib/codeql/swift/generated/ErrorElement.qll 4b032abe8ffb71376a29c63e470a52943
ql/lib/codeql/swift/generated/File.qll 61454459f5f1ae378bd4970ad1da4f39f3e696bac8a5eebdd162f131995c5316 3e6805f8858cd55dd0e0d0e5aeab923d6a55292dbf98b0029db1ae0208efe684
ql/lib/codeql/swift/generated/Locatable.qll bdc98b9fb7788f44a4bf7e487ee5bd329473409950a8e9f116d61995615ad849 0b36b4fe45e2aa195e4bb70c50ea95f32f141b8e01e5f23466c6427dd9ab88fb
ql/lib/codeql/swift/generated/Location.qll 851766e474cdfdfa67da42e0031fc42dd60196ff5edd39d82f08d3e32deb84c1 b29b2c37672f5acff15f1d3c5727d902f193e51122327b31bd27ec5f877bca3b
ql/lib/codeql/swift/generated/ParentChild.qll d9c1edbbb28e685d31153c3a17419e80fd106cb580ef8440e25a8709e7f4c021 e0e59a05018e4b59ebda3a9fdc3435b1c82207b915630d55edbe6d3f92488356
ql/lib/codeql/swift/generated/ParentChild.qll 0667eb3c260b97beefd4934c80f7ffd2350488807effb3fd79bf187d179cd9bb dc0d237357baa46fae3e453d0446646c6a444155f08a9811aa29167c8cd34c73
ql/lib/codeql/swift/generated/PureSynthConstructors.qll 1cd47d61fec37e019ce2e476603eb2273775bea81062d6bf3d6bbc49796f7b77 1cd47d61fec37e019ce2e476603eb2273775bea81062d6bf3d6bbc49796f7b77
ql/lib/codeql/swift/generated/Raw.qll 74159a7425c2da672d72e71655d27af3479b0acc23d871eafcee7d044d013550 0a6e8a85fbfd7262c983b6a6fedabbe9f11648edbcc52cba5828b97fe18fbd02
ql/lib/codeql/swift/generated/Synth.qll 90df85be365c89c3c2e22041ee7dc9dd2ad9194b66f82e8f9d8fefb8afd900ec 1632984f7a55f6bc55adb9f647baf634b002c299655cbf641dfb110525291689
ql/lib/codeql/swift/generated/SynthConstructors.qll 5c91f09bd82728651ed61f498704e0f62847788fa986dec5e674d81f294076c7 5c91f09bd82728651ed61f498704e0f62847788fa986dec5e674d81f294076c7
ql/lib/codeql/swift/generated/Raw.qll 6b8e3e3d86254d5689b17a08c41d23cda0d913b5d3b22b18b55aa00363ace6df 3736f05fc2c2eb6a9d9dd0d244061abe72161714cd435233106804472213e2b1
ql/lib/codeql/swift/generated/Synth.qll cc7285c43e6c9f47ab67047916d232ad2078443b342ba1bb036c147127c40167 522a3ba4fc7f9fbb0b7d12fc5177fa0a0d2f8239bd6b4c36fc7d7a918fcdcccf
ql/lib/codeql/swift/generated/SynthConstructors.qll 0ff9cfcd64e7701003091f366ec903ec1bf82ec8385ee683b6e7b4e189033b11 0ff9cfcd64e7701003091f366ec903ec1bf82ec8385ee683b6e7b4e189033b11
ql/lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6
ql/lib/codeql/swift/generated/UnknownLocation.qll e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882 e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882
ql/lib/codeql/swift/generated/UnspecifiedElement.qll dbc6ca4018012977b26ca184a88044c55b0661e3998cd14d46295b62a8d69625 184c9a0ce18c2ac881943b0fb400613d1401ed1d5564f90716b6c310ba5afe71
@ -428,6 +430,7 @@ ql/lib/codeql/swift/generated/decl/TypeAliasDecl.qll 15cb5bdbe9d722c403874f744bf
ql/lib/codeql/swift/generated/decl/TypeDecl.qll 3fb055ab433ec40186f822c5711e3d47f9084fb12a1faee550e1e3e2507cfb45 1f46f7ae90c414c5d00bc2e33c86aa80f5ffddfd6be1853d8d6d4222b8e3f584
ql/lib/codeql/swift/generated/decl/ValueDecl.qll 7b4e4c9334be676f242857c77099306d8a0a4357b253f8bc68f71328cedf1f58 f18938c47f670f2e0c27ffd7e31e55f291f88fb50d8e576fcea116d5f9e5c66d
ql/lib/codeql/swift/generated/decl/VarDecl.qll 2fca00ba8b535d7cefc2fa863246a0821437ca29b885c4c30362e8a63f284479 5ba623001e071c16267e94d050bfd973addf2436152c7726945b5d87aa521af8
ql/lib/codeql/swift/generated/expr/AbiSafeConversionExpr.qll f4c913df3f1c139a0533f9a3a2f2e07aee96ab723c957fc7153d68564e4fdd6d f4c913df3f1c139a0533f9a3a2f2e07aee96ab723c957fc7153d68564e4fdd6d
ql/lib/codeql/swift/generated/expr/AbstractClosureExpr.qll f0060c2972d2e1f9818d8deea3ceebbbe0b19d2ce11adc9b670beb672c4564d3 5f2500c5f3728f81599bd4e1fb9c97ac5a44a6dce8c1ab84a850c62aae3741ff
ql/lib/codeql/swift/generated/expr/AnyHashableErasureExpr.qll f450ac8e316def1cd64dcb61411bae191144079df7f313a5973e59dc89fe367f f450ac8e316def1cd64dcb61411bae191144079df7f313a5973e59dc89fe367f
ql/lib/codeql/swift/generated/expr/AnyTryExpr.qll f2929f39407e1717b91fc41f593bd52f1ae14c619d61598bd0668a478a04a91e 62693c2c18678af1ff9ce5393f0dd87c5381e567b340f1a8a9ecf91a92e2e666

Просмотреть файл

@ -55,6 +55,7 @@ import codeql.swift.elements.decl.TypeAliasDecl
import codeql.swift.elements.decl.TypeDecl
import codeql.swift.elements.decl.ValueDecl
import codeql.swift.elements.decl.VarDecl
import codeql.swift.elements.expr.AbiSafeConversionExpr
import codeql.swift.elements.expr.AbstractClosureExpr
import codeql.swift.elements.expr.AnyHashableErasureExpr
import codeql.swift.elements.expr.AnyTryExpr

Просмотреть файл

@ -0,0 +1,4 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
private import codeql.swift.generated.expr.AbiSafeConversionExpr
class AbiSafeConversionExpr extends Generated::AbiSafeConversionExpr { }

Просмотреть файл

@ -0,0 +1,4 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
private import codeql.swift.generated.Raw
predicate constructAbiSafeConversionExpr(Raw::AbiSafeConversionExpr id) { any() }

Просмотреть файл

@ -1872,6 +1872,23 @@ private module Impl {
)
}
private Element getImmediateChildOfAbiSafeConversionExpr(
AbiSafeConversionExpr e, int index, string partialPredicateCall
) {
exists(int b, int bImplicitConversionExpr, int n |
b = 0 and
bImplicitConversionExpr =
b + 1 +
max(int i | i = -1 or exists(getImmediateChildOfImplicitConversionExpr(e, i, _)) | i) and
n = bImplicitConversionExpr and
(
none()
or
result = getImmediateChildOfImplicitConversionExpr(e, index - b, partialPredicateCall)
)
)
}
private Element getImmediateChildOfAnyHashableErasureExpr(
AnyHashableErasureExpr e, int index, string partialPredicateCall
) {
@ -4885,6 +4902,8 @@ private module Impl {
or
result = getImmediateChildOfVarargExpansionExpr(e, index, partialAccessor)
or
result = getImmediateChildOfAbiSafeConversionExpr(e, index, partialAccessor)
or
result = getImmediateChildOfAnyHashableErasureExpr(e, index, partialAccessor)
or
result = getImmediateChildOfArchetypeToSuperExpr(e, index, partialAccessor)

Просмотреть файл

@ -677,6 +677,10 @@ module Raw {
Expr getSubExpr() { vararg_expansion_exprs(this, result) }
}
class AbiSafeConversionExpr extends @abi_safe_conversion_expr, ImplicitConversionExpr {
override string toString() { result = "AbiSafeConversionExpr" }
}
class AnyHashableErasureExpr extends @any_hashable_erasure_expr, ImplicitConversionExpr {
override string toString() { result = "AnyHashableErasureExpr" }
}

Просмотреть файл

@ -41,6 +41,7 @@ module Synth {
TSubscriptDecl(Raw::SubscriptDecl id) { constructSubscriptDecl(id) } or
TTopLevelCodeDecl(Raw::TopLevelCodeDecl id) { constructTopLevelCodeDecl(id) } or
TTypeAliasDecl(Raw::TypeAliasDecl id) { constructTypeAliasDecl(id) } or
TAbiSafeConversionExpr(Raw::AbiSafeConversionExpr id) { constructAbiSafeConversionExpr(id) } or
TAnyHashableErasureExpr(Raw::AnyHashableErasureExpr id) { constructAnyHashableErasureExpr(id) } or
TAppliedPropertyWrapperExpr(Raw::AppliedPropertyWrapperExpr id) {
constructAppliedPropertyWrapperExpr(id)
@ -386,12 +387,12 @@ module Synth {
TAwaitExpr or TDotSelfExpr or TParenExpr or TUnresolvedMemberChainResultExpr;
class TImplicitConversionExpr =
TAnyHashableErasureExpr or TArchetypeToSuperExpr or TArrayToPointerExpr or
TBridgeFromObjCExpr or TBridgeToObjCExpr or TClassMetatypeToObjectExpr or
TCollectionUpcastConversionExpr or TConditionalBridgeFromObjCExpr or
TCovariantFunctionConversionExpr or TCovariantReturnConversionExpr or TDerivedToBaseExpr or
TDestructureTupleExpr or TDifferentiableFunctionExpr or
TDifferentiableFunctionExtractOriginalExpr or TErasureExpr or
TAbiSafeConversionExpr or TAnyHashableErasureExpr or TArchetypeToSuperExpr or
TArrayToPointerExpr or TBridgeFromObjCExpr or TBridgeToObjCExpr or
TClassMetatypeToObjectExpr or TCollectionUpcastConversionExpr or
TConditionalBridgeFromObjCExpr or TCovariantFunctionConversionExpr or
TCovariantReturnConversionExpr or TDerivedToBaseExpr or TDestructureTupleExpr or
TDifferentiableFunctionExpr or TDifferentiableFunctionExtractOriginalExpr or TErasureExpr or
TExistentialMetatypeToObjectExpr or TForeignObjectConversionExpr or
TFunctionConversionExpr or TInOutToPointerExpr or TInjectIntoOptionalExpr or
TLinearFunctionExpr or TLinearFunctionExtractOriginalExpr or
@ -592,6 +593,11 @@ module Synth {
cached
TTypeAliasDecl convertTypeAliasDeclFromRaw(Raw::Element e) { result = TTypeAliasDecl(e) }
cached
TAbiSafeConversionExpr convertAbiSafeConversionExprFromRaw(Raw::Element e) {
result = TAbiSafeConversionExpr(e)
}
cached
TAnyHashableErasureExpr convertAnyHashableErasureExprFromRaw(Raw::Element e) {
result = TAnyHashableErasureExpr(e)
@ -1751,6 +1757,8 @@ module Synth {
cached
TImplicitConversionExpr convertImplicitConversionExprFromRaw(Raw::Element e) {
result = convertAbiSafeConversionExprFromRaw(e)
or
result = convertAnyHashableErasureExprFromRaw(e)
or
result = convertArchetypeToSuperExprFromRaw(e)
@ -2225,6 +2233,11 @@ module Synth {
cached
Raw::Element convertTypeAliasDeclToRaw(TTypeAliasDecl e) { e = TTypeAliasDecl(result) }
cached
Raw::Element convertAbiSafeConversionExprToRaw(TAbiSafeConversionExpr e) {
e = TAbiSafeConversionExpr(result)
}
cached
Raw::Element convertAnyHashableErasureExprToRaw(TAnyHashableErasureExpr e) {
e = TAnyHashableErasureExpr(result)
@ -3382,6 +3395,8 @@ module Synth {
cached
Raw::Element convertImplicitConversionExprToRaw(TImplicitConversionExpr e) {
result = convertAbiSafeConversionExprToRaw(e)
or
result = convertAnyHashableErasureExprToRaw(e)
or
result = convertArchetypeToSuperExprToRaw(e)

Просмотреть файл

@ -33,6 +33,7 @@ import codeql.swift.elements.decl.StructDeclConstructor
import codeql.swift.elements.decl.SubscriptDeclConstructor
import codeql.swift.elements.decl.TopLevelCodeDeclConstructor
import codeql.swift.elements.decl.TypeAliasDeclConstructor
import codeql.swift.elements.expr.AbiSafeConversionExprConstructor
import codeql.swift.elements.expr.AnyHashableErasureExprConstructor
import codeql.swift.elements.expr.AppliedPropertyWrapperExprConstructor
import codeql.swift.elements.expr.ArchetypeToSuperExprConstructor

Просмотреть файл

@ -0,0 +1,10 @@
// generated by codegen/codegen.py
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.expr.ImplicitConversionExpr
module Generated {
class AbiSafeConversionExpr extends Synth::TAbiSafeConversionExpr, ImplicitConversionExpr {
override string getAPrimaryQlClass() { result = "AbiSafeConversionExpr" }
}
}

Просмотреть файл

@ -870,7 +870,8 @@ if_exprs( //dir=expr
);
@implicit_conversion_expr =
@any_hashable_erasure_expr
@abi_safe_conversion_expr
| @any_hashable_erasure_expr
| @archetype_to_super_expr
| @array_to_pointer_expr
| @bridge_from_obj_c_expr
@ -1129,6 +1130,10 @@ vararg_expansion_exprs( //dir=expr
int sub_expr: @expr_or_none ref
);
abi_safe_conversion_exprs( //dir=expr
unique int id: @abi_safe_conversion_expr
);
any_hashable_erasure_exprs( //dir=expr
unique int id: @any_hashable_erasure_expr
);

Просмотреть файл

@ -1,3 +1,5 @@
| implicit_conversions.swift:2:3:2:3 | (UnsafePointer<CChar>) ... | StringToPointerExpr | getSubExpr: | implicit_conversions.swift:2:3:2:3 | Hello |
| implicit_conversions.swift:4:16:4:16 | (Int?) ... | InjectIntoOptionalExpr | getSubExpr: | implicit_conversions.swift:4:16:4:16 | 42 |
| implicit_conversions.swift:5:25:5:25 | (Equatable) ... | ErasureExpr | getSubExpr: | implicit_conversions.swift:5:25:5:25 | 42 |
| implicit_conversions.swift:12:3:12:5 | (@lvalue (() -> Void)?) ... | AbiSafeConversionExpr | getSubExpr: | implicit_conversions.swift:12:3:12:5 | .b |
| implicit_conversions.swift:12:9:12:10 | ((() -> Void)?) ... | InjectIntoOptionalExpr | getSubExpr: | implicit_conversions.swift:12:9:12:10 | { ... } |

Просмотреть файл

@ -1,3 +1,5 @@
| implicit_conversions.swift:2:3:2:3 | (UnsafePointer<CChar>) ... | UnsafePointer<CChar> |
| implicit_conversions.swift:4:16:4:16 | (Int?) ... | Int? |
| implicit_conversions.swift:5:25:5:25 | (Equatable) ... | Equatable |
| implicit_conversions.swift:12:3:12:5 | (@lvalue (() -> Void)?) ... | @lvalue (() -> Void)? |
| implicit_conversions.swift:12:9:12:10 | ((() -> Void)?) ... | (() -> Void)? |

Просмотреть файл

@ -3,3 +3,12 @@ f("Hello") // StringToPointerExpr
let a : Int? = 42 // InjectIntoOptionalExpr
let b : any Equatable = 42 // ErasureExpr
@preconcurrency class A {
@preconcurrency var b: (@Sendable () -> Void)?
}
func g(_ a: A) {
a.b = {}
}

Просмотреть файл

@ -1040,3 +1040,6 @@ class ParameterizedProtocolType(Type):
"""
base: ProtocolType
args: list[Type]
class AbiSafeConversionExpr(ImplicitConversionExpr):
pass