Swift: extract CopyExpr

This commit is contained in:
Alex Denisov
2023-11-13 13:46:37 +01:00
parent d931ade182
commit 30e4822fb7
22 changed files with 197 additions and 9 deletions

View File

@@ -201,12 +201,10 @@ MAP(swift::Expr, ExprTag)
MAP(swift::TapExpr, TapExprTag)
MAP(swift::TypeJoinExpr, void) // TODO (introduced in 5.8)
MAP(swift::MacroExpansionExpr, void) // TODO (introduced in 5.8)
#if CODEQL_SWIFT_VERSION_GE(5, 9)
MAP(swift::CopyExpr, void) // TODO (introduced in 5.9)
MAP(swift::CopyExpr, CopyExprTag)
MAP(swift::ConsumeExpr, void) // TODO (introduced in 5.9)
MAP(swift::MaterializePackExpr, void) // TODO (introduced in 5.9)
MAP(swift::SingleValueStmtExpr, SingleValueStmtExprTag)
#endif
MAP(swift::Decl, DeclTag)
MAP(swift::ValueDecl, ValueDeclTag)

View File

@@ -657,4 +657,10 @@ codeql::PackElementExpr ExprTranslator::translatePackElementExpr(
return entry;
}
codeql::CopyExpr ExprTranslator::translateCopyExpr(const swift::CopyExpr& expr) {
auto entry = createExprEntry(expr);
entry.sub_expr = dispatcher.fetchLabel(expr.getSubExpr());
return entry;
}
} // namespace codeql

View File

@@ -122,6 +122,7 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
codeql::SingleValueStmtExpr translateSingleValueStmtExpr(const swift::SingleValueStmtExpr& expr);
codeql::PackExpansionExpr translatePackExpansionExpr(const swift::PackExpansionExpr& expr);
codeql::PackElementExpr translatePackElementExpr(const swift::PackElementExpr& expr);
codeql::CopyExpr translateCopyExpr(const swift::CopyExpr& expr);
private:
void fillClosureExpr(const swift::AbstractClosureExpr& expr, codeql::ClosureExpr& entry);

View File

@@ -96,6 +96,8 @@ lib/codeql/swift/elements/expr/ConditionalBridgeFromObjCExpr.qll bfe2e7142451c1d
lib/codeql/swift/elements/expr/ConditionalBridgeFromObjCExprConstructor.qll 446d2b437a1b54e0ba3107aad57ea9a12449a70cd9565cc724b395bf88fd9e8b 7f7bd4dd2f6cb717c7868993d183fcf7634c30666a1709b9d1577ed17467f1e7
lib/codeql/swift/elements/expr/ConditionalCheckedCastExpr.qll 61290c72da5609bcefb417a55e9d4338393af057c8634459875500710ffbeebb dadc07129e4b4ed41a8afb19a3e53ac0bf78f5b077be5f09e5609d87659a5869
lib/codeql/swift/elements/expr/ConditionalCheckedCastExprConstructor.qll 14b761095c024474f6e475a66822e9893b4e65e35c4182be9fdc5f801eb2274d 7d62113ae891dff8e371ed89d698e2df225a7580fe371165d69f42bd88ce8ecc
lib/codeql/swift/elements/expr/CopyExpr.qll f820ef6ae749267bfc198b110fb32a14e910800008eeb955a496a7e80cb8c614 4334f4938e164323d7bc58742b73f7285f16d6d641bd41ac92d5dccaa7af32eb
lib/codeql/swift/elements/expr/CopyExprConstructor.qll 2b4944e504ab0a4884a926d5532c686004147548fc1734922d0a83d23828de56 4ef6c99b3bcc0ba58b8c040339762246eb206a4f89d0ed7ca92421b964bded17
lib/codeql/swift/elements/expr/CovariantFunctionConversionExpr.qll 7726850cac33afed7bb0aad3a0e9d1211d7c287b0c17be4e2056ddcd99d35e86 aae0109a74e369d4d1a567473e24c4aac1e68cd4d4a920f11f8fc3b9db99cf6e
lib/codeql/swift/elements/expr/CovariantFunctionConversionExprConstructor.qll 8b186ad94027e2e0a8b8cf0b0a1ec703a121e786fa969aa177dd3638af3c9c04 39c3383cf658bc10c1e02cca4c82362553d24c743651337cfaa54fbe304c9b85
lib/codeql/swift/elements/expr/CovariantReturnConversionExpr.qll eca04e50ec909fd18e10bcccda791c6c09468ff58ad9445b3a93b9c57396c65a 41a8fa2608cf03885ac0df8e9a15ac14356b8ddaa1d7daf029e1912436a6598d
@@ -377,7 +379,7 @@ lib/codeql/swift/elements/type/UnresolvedTypeConstructor.qll 7f75d489b4d7ce65cae
lib/codeql/swift/elements/type/VariadicSequenceTypeConstructor.qll fc74a5a2a2effa28ef24509b20ee4373d97cf6e8c71840121bb031c6adedf584 c9b2effc1d01c13c5e6a74a111122fa79a2f6554dda3cb016d68ba397e566ec4
lib/codeql/swift/elements/type/WeakStorageType.qll edd13dd97b53040684409e187c1f975bcada6807c919e1345d8977144dbebb6f 9434c044d264a7f5f503a6422c106c9b8fedf74aaae314174473a29ea6ed17b9
lib/codeql/swift/elements/type/WeakStorageTypeConstructor.qll 5fdce3716aba6318522174a2c455a63480970222ae81c732fb19c6dd3ae2d271 60ea79d6943e129deba0deccb566cf9d73f78398b0f7f0212674d91287d6b2ae
lib/codeql/swift/elements.qll a9890434db7f1271edd3e61aebb2ddb170c3a71c22892d2d84a6d99dddbdbecf a9890434db7f1271edd3e61aebb2ddb170c3a71c22892d2d84a6d99dddbdbecf
lib/codeql/swift/elements.qll f1c8fdfa57e5bf9bc19c0ca6ded891c8431c8cd98b2a53e5eb7ce36199c6bab2 f1c8fdfa57e5bf9bc19c0ca6ded891c8431c8cd98b2a53e5eb7ce36199c6bab2
lib/codeql/swift/generated/AstNode.qll e00d6a46b16891778531a73722ae0b5842f849328e24aebe88bc30ac9fe438c2 40eaa0072d3ffecbff48d2baf88111daa86ef0f937abf24f032f2495739ef661
lib/codeql/swift/generated/AvailabilityInfo.qll e90fbfc3ec6830390e12a4695698d6efd8da4fa6a8a4189f466489a6dd103586 d9545da9e5d0c160679a4147001b4b1c664d9cb85ae1a169dd639c35046d274d
lib/codeql/swift/generated/AvailabilitySpec.qll 469bbd39d38dc68f1f6fb2e0766cc25b2f813c804fec44962910d5f7777632a2 57a953a8d5cf7031283393af1b3cfbc7f5941c9062e77950b32e5b5c6ae6b191
@@ -393,12 +395,12 @@ lib/codeql/swift/generated/KeyPathComponent.qll 55629a20538d7e8f4f4d4c7484e8bcfd
lib/codeql/swift/generated/Locatable.qll 41f040643ea146c8044be49fddea89bdd79efd2469617c863a4b2da0b1af3364 9a964dcbc7f5ffce2ee006ce0c9a9a99a988976fcd0446af2ba1b202911d7396
lib/codeql/swift/generated/Location.qll 5b37ecde83a871ef2089cf33e4743fc02d9cf8c676aafd9f157c59ffdb776d6b 076d8d3d2313931e8287d196854acf259700124d9c8bc591a6d36017f314260a
lib/codeql/swift/generated/OtherAvailabilitySpec.qll 31f3667ab0dc5f93230ba876b4101898d2a5a4af306925082305eff3ad9c9c0e 31f3667ab0dc5f93230ba876b4101898d2a5a4af306925082305eff3ad9c9c0e
lib/codeql/swift/generated/ParentChild.qll 2c655423a5efa7fe26070bf2272de0067c3288a37e6f8f7c85da46971e82ee1b e5dbf27a8efc0c4b9e2a53fd52ecd8afc3281a0a34386f6c900cd61ab4acaa83
lib/codeql/swift/generated/ParentChild.qll fb015f25cdff4fd65a909b98b3bb213e7948e14e152e14e789f856ec65189c70 dc0b64fc75ac329be4ddd8d69f41cc89d1dfd0f9379b764766b0b9724472907d
lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll 3483726f6db9d978e40db75068d6a9ecad8f7c06516157fce783b26424bea729 864fedf2901de91f662a6d75a2eb7e26ed1a2a1a875a2b3c4e699dc7e7c4605e
lib/codeql/swift/generated/PureSynthConstructors.qll 40f5c0c573ce12f16322d9efb12306750f672254cbc36a200c298cb08e504229 40f5c0c573ce12f16322d9efb12306750f672254cbc36a200c298cb08e504229
lib/codeql/swift/generated/Raw.qll 84fc2268f5a038e58c353d940624bb738d9a195dec5a130c4844f3f9d6a0d43c 1bb8ea3ed529d61c41302b2ea65d35155ed4fd4d3fc7764e361fc108ffd30a4f
lib/codeql/swift/generated/Synth.qll 345d99dfbb3b26173edece42dd9c00b7b49b0890e254915dc8ad393997fec1c5 fe1697b2c9dfe39ecc7e71915803773518c906c969c59ccb34252ee3d4719c5a
lib/codeql/swift/generated/SynthConstructors.qll d63f29c58f85bf4d77a31ce325a54dc972b3ceecb3fb61b8ddbb296318be4827 d63f29c58f85bf4d77a31ce325a54dc972b3ceecb3fb61b8ddbb296318be4827
lib/codeql/swift/generated/Raw.qll d63ca7a4be4795dc6d0693ff91e7057aac20f7bfc92c772b74dd27fce845274e 4c06e31cb9016f2829cf5b67f65dca3ad83b1d7b562e985a4add223f9b5e632c
lib/codeql/swift/generated/Synth.qll 0c32468f13063f3182e57dae315a1140617fec84f20bfe5a1dc18d9ad861747c 9a5853b0ce04b3a03172d38495a8f60702213d1d767e7716ff6e1c5e38ff162d
lib/codeql/swift/generated/SynthConstructors.qll 1384e3f36c64c46294e14eec7998ce219e23271c5f7558a6c9ba40d018e02339 1384e3f36c64c46294e14eec7998ce219e23271c5f7558a6c9ba40d018e02339
lib/codeql/swift/generated/UnknownFile.qll 5922b351b55d5becac0c1ad67b8d601bcc9499dce9ee4093b607101e7e299104 5922b351b55d5becac0c1ad67b8d601bcc9499dce9ee4093b607101e7e299104
lib/codeql/swift/generated/UnknownLocation.qll 67b8605ff5aaa0f3a8588fee2527eba5ec4e322562159c9af3d53486b7954ee9 67b8605ff5aaa0f3a8588fee2527eba5ec4e322562159c9af3d53486b7954ee9
lib/codeql/swift/generated/UnspecifiedElement.qll 01182fee4d5c86b551e89c79d0d645f5e85c0aeeeae9dcafcbd7721c3eb3cc14 cb95ab2b13da080ada10e0a3bd1b00577541c4bfe699cbd19ef45f1e00e7c651
@@ -472,6 +474,7 @@ lib/codeql/swift/generated/expr/CollectionExpr.qll 40f0167cbf67bba45be184e9603f9
lib/codeql/swift/generated/expr/CollectionUpcastConversionExpr.qll 9925461069bd584492925baae30ab098d55ec552e557c6357e8bc82ea204d843 6462bd150d2b6dafbbb05c17e970c47e290cc1d1ae704e5ccb381800451a7188
lib/codeql/swift/generated/expr/ConditionalBridgeFromObjCExpr.qll 65bdf5e9a9e98569af93d2212b114c822e9809ad4a43b50e50e8face07268156 c20f1ff1fd6231e7691d50cc1ee0c36edd8ed3a58ce1cc378ce9e03e9423cb6e
lib/codeql/swift/generated/expr/ConditionalCheckedCastExpr.qll be657b986ae9a8ba929d3e5683d101e1a26e8d7995376ed68610477e87f48184 be657b986ae9a8ba929d3e5683d101e1a26e8d7995376ed68610477e87f48184
lib/codeql/swift/generated/expr/CopyExpr.qll a25970a0238df0ebcf63d437681b1ba3d5f750f0ab69d7c1bb9f3b600392dc90 4c64344d994a0b1fd6fbf39283d3d87423d2dd13893509b296fdbd280703ad04
lib/codeql/swift/generated/expr/CovariantFunctionConversionExpr.qll 4b48c9d01c5f67bd5a6d2ff609ac9bf87954298cd0719b5a951efb89146fcbe6 43626bf6760dfc8f49362d8f065a8f5339f822c8f76ff9be012b4471e20afde2
lib/codeql/swift/generated/expr/CovariantReturnConversionExpr.qll 0c8dffec9ed1f28902a9679ec29ba33b6a9225460180db923733ad3d14fbdd28 fee3ddce4a699c86770b2a9211e524f764ed9140860b7e6c58ca7f62566cd4ec
lib/codeql/swift/generated/expr/DeclRefExpr.qll ab3ada6eaad669a5e2f170c096d27934ddbc28638b37df77d402eb01fba4f2e6 b00075cc65fe364288022937b0e0cfd9805d94436e48cbd88dacdf5bcd4a170d
@@ -794,6 +797,8 @@ test/extractor-tests/generated/expr/CallExpr/MISSING_SOURCE.txt 66846d526b0bc432
test/extractor-tests/generated/expr/CaptureListExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
test/extractor-tests/generated/expr/CoerceExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
test/extractor-tests/generated/expr/ConditionalCheckedCastExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
test/extractor-tests/generated/expr/CopyExpr/CopyExpr.ql 2e80272756531b3d7c65d9efd9474927e5cea719813acb599b61526e1957b220 1982362701e058bd32d3f9dfafbee3770a5016008cc1330237eb102f8459b506
test/extractor-tests/generated/expr/CopyExpr/CopyExpr_getType.ql 33698df9758f9399a0a7492a8432399582d2d52699572ca550c0fcdad839336e 330bd731f686d534769f7fc08d04e60dec83bced96cf39845c4374fa0629eb53
test/extractor-tests/generated/expr/DeclRefExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
test/extractor-tests/generated/expr/DefaultArgumentExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
test/extractor-tests/generated/expr/DictionaryExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7

5
swift/ql/.gitattributes generated vendored
View File

@@ -98,6 +98,8 @@
/lib/codeql/swift/elements/expr/ConditionalBridgeFromObjCExprConstructor.qll linguist-generated
/lib/codeql/swift/elements/expr/ConditionalCheckedCastExpr.qll linguist-generated
/lib/codeql/swift/elements/expr/ConditionalCheckedCastExprConstructor.qll linguist-generated
/lib/codeql/swift/elements/expr/CopyExpr.qll linguist-generated
/lib/codeql/swift/elements/expr/CopyExprConstructor.qll linguist-generated
/lib/codeql/swift/elements/expr/CovariantFunctionConversionExpr.qll linguist-generated
/lib/codeql/swift/elements/expr/CovariantFunctionConversionExprConstructor.qll linguist-generated
/lib/codeql/swift/elements/expr/CovariantReturnConversionExpr.qll linguist-generated
@@ -474,6 +476,7 @@
/lib/codeql/swift/generated/expr/CollectionUpcastConversionExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/ConditionalBridgeFromObjCExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/ConditionalCheckedCastExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/CopyExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/CovariantFunctionConversionExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/CovariantReturnConversionExpr.qll linguist-generated
/lib/codeql/swift/generated/expr/DeclRefExpr.qll linguist-generated
@@ -796,6 +799,8 @@
/test/extractor-tests/generated/expr/CaptureListExpr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/expr/CoerceExpr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/expr/ConditionalCheckedCastExpr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/expr/CopyExpr/CopyExpr.ql linguist-generated
/test/extractor-tests/generated/expr/CopyExpr/CopyExpr_getType.ql linguist-generated
/test/extractor-tests/generated/expr/DeclRefExpr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/expr/DefaultArgumentExpr/MISSING_SOURCE.txt linguist-generated
/test/extractor-tests/generated/expr/DictionaryExpr/MISSING_SOURCE.txt linguist-generated

View File

@@ -91,6 +91,7 @@ import codeql.swift.elements.expr.CollectionExpr
import codeql.swift.elements.expr.CollectionUpcastConversionExpr
import codeql.swift.elements.expr.ConditionalBridgeFromObjCExpr
import codeql.swift.elements.expr.ConditionalCheckedCastExpr
import codeql.swift.elements.expr.CopyExpr
import codeql.swift.elements.expr.CovariantFunctionConversionExpr
import codeql.swift.elements.expr.CovariantReturnConversionExpr
import codeql.swift.elements.expr.DeclRefExpr

View File

@@ -0,0 +1,8 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
/**
* This module provides a hand-modifiable wrapper around the generated class `CopyExpr`.
*/
private import codeql.swift.generated.expr.CopyExpr
class CopyExpr extends Generated::CopyExpr { }

View File

@@ -0,0 +1,14 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
/**
* This module defines the hook used internally to tweak the characteristic predicate of
* `CopyExpr` synthesized instances.
* INTERNAL: Do not use.
*/
private import codeql.swift.generated.Raw
/**
* The characteristic predicate of `CopyExpr` synthesized instances.
* INTERNAL: Do not use.
*/
predicate constructCopyExpr(Raw::CopyExpr id) { any() }

View File

@@ -1201,6 +1201,22 @@ private module Impl {
)
}
private Element getImmediateChildOfCopyExpr(CopyExpr e, int index, string partialPredicateCall) {
exists(int b, int bExpr, int n, int nSubExpr |
b = 0 and
bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and
n = bExpr and
nSubExpr = n + 1 and
(
none()
or
result = getImmediateChildOfExpr(e, index - b, partialPredicateCall)
or
index = n and result = e.getImmediateSubExpr() and partialPredicateCall = "SubExpr()"
)
)
}
private Element getImmediateChildOfDeclRefExpr(
DeclRefExpr e, int index, string partialPredicateCall
) {
@@ -5078,6 +5094,8 @@ private module Impl {
or
result = getImmediateChildOfCaptureListExpr(e, index, partialAccessor)
or
result = getImmediateChildOfCopyExpr(e, index, partialAccessor)
or
result = getImmediateChildOfDeclRefExpr(e, index, partialAccessor)
or
result = getImmediateChildOfDefaultArgumentExpr(e, index, partialAccessor)

View File

@@ -1119,6 +1119,24 @@ module Raw {
*/
class CollectionExpr extends @collection_expr, Expr { }
/**
* INTERNAL: Do not use.
* An expression that forces value to be copied. In the example below, `copy` marks the copy expression:
*
* ```
* let y = ...
* let x = copy y
* ```
*/
class CopyExpr extends @copy_expr, Expr {
override string toString() { result = "CopyExpr" }
/**
* Gets the sub expression of this copy expression.
*/
Expr getSubExpr() { copy_exprs(this, result) }
}
/**
* INTERNAL: Do not use.
*/

View File

@@ -279,6 +279,10 @@ module Synth {
TConditionalCheckedCastExpr(Raw::ConditionalCheckedCastExpr id) {
constructConditionalCheckedCastExpr(id)
} or
/**
* INTERNAL: Do not use.
*/
TCopyExpr(Raw::CopyExpr id) { constructCopyExpr(id) } or
/**
* INTERNAL: Do not use.
*/
@@ -1195,7 +1199,7 @@ module Synth {
*/
class TExpr =
TAnyTryExpr or TAppliedPropertyWrapperExpr or TApplyExpr or TAssignExpr or TBindOptionalExpr or
TCaptureListExpr or TClosureExpr or TCollectionExpr or TDeclRefExpr or
TCaptureListExpr or TClosureExpr or TCollectionExpr or TCopyExpr or TDeclRefExpr or
TDefaultArgumentExpr or TDiscardAssignmentExpr or TDotSyntaxBaseIgnoredExpr or
TDynamicTypeExpr or TEnumIsCaseExpr or TErrorExpr or TExplicitCastExpr or TForceValueExpr or
TIdentityExpr or TIfExpr or TImplicitConversionExpr or TInOutExpr or
@@ -1860,6 +1864,13 @@ module Synth {
result = TConditionalCheckedCastExpr(e)
}
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TCopyExpr`, if possible.
*/
cached
TCopyExpr convertCopyExprFromRaw(Raw::Element e) { result = TCopyExpr(e) }
/**
* INTERNAL: Do not use.
* Converts a raw element to a synthesized `TCovariantFunctionConversionExpr`, if possible.
@@ -3702,6 +3713,8 @@ module Synth {
or
result = convertCollectionExprFromRaw(e)
or
result = convertCopyExprFromRaw(e)
or
result = convertDeclRefExprFromRaw(e)
or
result = convertDefaultArgumentExprFromRaw(e)
@@ -4758,6 +4771,13 @@ module Synth {
e = TConditionalCheckedCastExpr(result)
}
/**
* INTERNAL: Do not use.
* Converts a synthesized `TCopyExpr` to a raw DB element, if possible.
*/
cached
Raw::Element convertCopyExprToRaw(TCopyExpr e) { e = TCopyExpr(result) }
/**
* INTERNAL: Do not use.
* Converts a synthesized `TCovariantFunctionConversionExpr` to a raw DB element, if possible.
@@ -6598,6 +6618,8 @@ module Synth {
or
result = convertCollectionExprToRaw(e)
or
result = convertCopyExprToRaw(e)
or
result = convertDeclRefExprToRaw(e)
or
result = convertDefaultArgumentExprToRaw(e)

View File

@@ -64,6 +64,7 @@ import codeql.swift.elements.expr.CoerceExprConstructor
import codeql.swift.elements.expr.CollectionUpcastConversionExprConstructor
import codeql.swift.elements.expr.ConditionalBridgeFromObjCExprConstructor
import codeql.swift.elements.expr.ConditionalCheckedCastExprConstructor
import codeql.swift.elements.expr.CopyExprConstructor
import codeql.swift.elements.expr.CovariantFunctionConversionExprConstructor
import codeql.swift.elements.expr.CovariantReturnConversionExprConstructor
import codeql.swift.elements.expr.DeclRefExprConstructor

View File

@@ -0,0 +1,46 @@
// generated by codegen/codegen.py
/**
* This module provides the generated definition of `CopyExpr`.
* INTERNAL: Do not import directly.
*/
private import codeql.swift.generated.Synth
private import codeql.swift.generated.Raw
import codeql.swift.elements.expr.Expr
module Generated {
/**
* An expression that forces value to be copied. In the example below, `copy` marks the copy expression:
*
* ```
* let y = ...
* let x = copy y
* ```
* INTERNAL: Do not reference the `Generated::CopyExpr` class directly.
* Use the subclass `CopyExpr`, where the following predicates are available.
*/
class CopyExpr extends Synth::TCopyExpr, Expr {
override string getAPrimaryQlClass() { result = "CopyExpr" }
/**
* Gets the sub expression of this copy expression.
*
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
* behavior of both the `Immediate` and non-`Immediate` versions.
*/
Expr getImmediateSubExpr() {
result =
Synth::convertExprFromRaw(Synth::convertCopyExprToRaw(this).(Raw::CopyExpr).getSubExpr())
}
/**
* Gets the sub expression of this copy expression.
*/
final Expr getSubExpr() {
exists(Expr immediate |
immediate = this.getImmediateSubExpr() and
if exists(this.getResolveStep()) then result = immediate else result = immediate.resolve()
)
}
}
}

View File

@@ -734,6 +734,7 @@ arguments( //dir=expr
| @capture_list_expr
| @closure_expr
| @collection_expr
| @copy_expr
| @decl_ref_expr
| @default_argument_expr
| @discard_assignment_expr
@@ -859,6 +860,11 @@ capture_list_expr_binding_decls( //dir=expr
| @dictionary_expr
;
copy_exprs( //dir=expr
unique int id: @copy_expr,
int sub_expr: @expr_or_none ref
);
decl_ref_exprs( //dir=expr
unique int id: @decl_ref_expr,
int decl: @decl_or_none ref

View File

@@ -0,0 +1,2 @@
ERROR: This predicate overrides another predicate but is not marked as 'override' (/opt/GitHub/semmle-code/ql/swift/ql/lib/codeql/swift/generated/expr/BorrowExpr.qll:26,5-35,6)
ERROR: This predicate overrides another predicate but is not marked as 'override' (/opt/GitHub/semmle-code/ql/swift/ql/lib/codeql/swift/generated/Raw.qll:1894,5-1897,53)

View File

@@ -0,0 +1,2 @@
ERROR: This predicate overrides another predicate but is not marked as 'override' (/opt/GitHub/semmle-code/ql/swift/ql/lib/codeql/swift/generated/expr/BorrowExpr.qll:26,5-35,6)
ERROR: This predicate overrides another predicate but is not marked as 'override' (/opt/GitHub/semmle-code/ql/swift/ql/lib/codeql/swift/generated/Raw.qll:1894,5-1897,53)

View File

@@ -0,0 +1 @@
| move_semantics.swift:4:9:4:14 | CopyExpr | hasType: | yes | getSubExpr: | move_semantics.swift:4:14:4:14 | x |

View File

@@ -0,0 +1,11 @@
// generated by codegen/codegen.py
import codeql.swift.elements
import TestUtils
from CopyExpr x, string hasType, Expr getSubExpr
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasType() then hasType = "yes" else hasType = "no") and
getSubExpr = x.getSubExpr()
select x, "hasType:", hasType, "getSubExpr:", getSubExpr

View File

@@ -0,0 +1 @@
| move_semantics.swift:4:9:4:14 | CopyExpr | Int |

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py
import codeql.swift.elements
import TestUtils
from CopyExpr x
where toBeTested(x) and not x.isUnknown()
select x, x.getType()

View File

@@ -0,0 +1,4 @@
//codeql-extractor-options: -enable-experimental-move-only
let x = 42
let _ = copy x

View File

@@ -1327,3 +1327,14 @@ class PackElementExpr(Expr):
https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md
"""
sub_expr: Expr | child
class CopyExpr(Expr):
"""
An expression that forces value to be copied. In the example below, `copy` marks the copy expression:
```
let y = ...
let x = copy y
```
"""
sub_expr: Expr | child