From 03646ac46815d174c03d5b0637296c496a624e0d Mon Sep 17 00:00:00 2001 From: Alex Denisov Date: Wed, 20 Sep 2023 11:04:39 +0200 Subject: [PATCH] Swift: extract SingleValueStmtExpr --- swift/extractor/infra/SwiftTagTraits.h | 2 +- .../extractor/translators/ExprTranslator.cpp | 7 +++++ swift/extractor/translators/ExprTranslator.h | 1 + swift/ql/.generated.list | 14 +++++---- swift/ql/.gitattributes | 4 +++ swift/ql/lib/codeql/swift/elements.qll | 1 + .../elements/expr/SingleValueStmtExpr.qll | 4 +++ .../expr/SingleValueStmtExprConstructor.qll | 4 +++ .../codeql/swift/generated/ParentChild.qll | 20 +++++++++++++ swift/ql/lib/codeql/swift/generated/Raw.qll | 12 ++++++++ swift/ql/lib/codeql/swift/generated/Synth.qll | 30 +++++++++++++++++-- .../swift/generated/SynthConstructors.qll | 1 + .../generated/expr/SingleValueStmtExpr.qll | 21 +++++++++++++ swift/ql/lib/swift.dbscheme | 6 ++++ .../SingleValueStmtExpr/MISSING_SOURCE.txt | 4 +++ .../CONSISTENCY/CfgConsistency.expected | 5 ++++ swift/schema.py | 4 +++ 17 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll create mode 100644 swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll create mode 100644 swift/ql/lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll create mode 100644 swift/ql/test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt create mode 100644 swift/ql/test/library-tests/dataflow/flowsources/CONSISTENCY/CfgConsistency.expected diff --git a/swift/extractor/infra/SwiftTagTraits.h b/swift/extractor/infra/SwiftTagTraits.h index 5066205db6e09..bd3042be2e8f3 100644 --- a/swift/extractor/infra/SwiftTagTraits.h +++ b/swift/extractor/infra/SwiftTagTraits.h @@ -205,7 +205,7 @@ MAP(swift::Expr, ExprTag) MAP(swift::CopyExpr, void) // TODO (introduced in 5.9) MAP(swift::ConsumeExpr, void) // TODO (introduced in 5.9) MAP(swift::MaterializePackExpr, void) // TODO (introduced in 5.9) - MAP(swift::SingleValueStmtExpr, void) // TODO (introduced in 5.9) + MAP(swift::SingleValueStmtExpr, SingleValueStmtExprTag) #endif MAP(swift::Decl, DeclTag) diff --git a/swift/extractor/translators/ExprTranslator.cpp b/swift/extractor/translators/ExprTranslator.cpp index 3274c49675e6b..de24e27226aca 100644 --- a/swift/extractor/translators/ExprTranslator.cpp +++ b/swift/extractor/translators/ExprTranslator.cpp @@ -636,4 +636,11 @@ codeql::RegexLiteralExpr ExprTranslator::translateRegexLiteralExpr( return entry; } +codeql::SingleValueStmtExpr ExprTranslator::translateSingleValueStmtExpr( + const swift::SingleValueStmtExpr& expr) { + auto entry = createExprEntry(expr); + entry.stmt = dispatcher.fetchLabel(expr.getStmt()); + return entry; +} + } // namespace codeql diff --git a/swift/extractor/translators/ExprTranslator.h b/swift/extractor/translators/ExprTranslator.h index 504f66999cf8a..fa3a1ef3c868c 100644 --- a/swift/extractor/translators/ExprTranslator.h +++ b/swift/extractor/translators/ExprTranslator.h @@ -119,6 +119,7 @@ class ExprTranslator : public AstTranslatorBase { codeql::AppliedPropertyWrapperExpr translateAppliedPropertyWrapperExpr( const swift::AppliedPropertyWrapperExpr& expr); codeql::RegexLiteralExpr translateRegexLiteralExpr(const swift::RegexLiteralExpr& expr); + codeql::SingleValueStmtExpr translateSingleValueStmtExpr(const swift::SingleValueStmtExpr& expr); private: void fillClosureExpr(const swift::AbstractClosureExpr& expr, codeql::ClosureExpr& entry); diff --git a/swift/ql/.generated.list b/swift/ql/.generated.list index 00d6f0fe319a8..b565b32538736 100644 --- a/swift/ql/.generated.list +++ b/swift/ql/.generated.list @@ -193,6 +193,8 @@ lib/codeql/swift/elements/expr/RegexLiteralExprConstructor.qll 7bf1bdba26d38e839 lib/codeql/swift/elements/expr/SelfApplyExpr.qll 986b3ff9833aac59facecea185517c006264c5011191b4c7f31317a20926467a f0349628f9ead822783e09e56e0721f939bfb7f59c8661e6155b5a7d113c26f3 lib/codeql/swift/elements/expr/SequenceExpr.qll 813360eff6a312e39c7b6c49928477679a3f32314badf3383bf6204690a280e4 3b2d06ac54746033a90319463243f2d0f17265c7f1573cbfedbdca3fb7063fd2 lib/codeql/swift/elements/expr/SequenceExprConstructor.qll 5a15ede013bb017a85092aff35dd2f4f1fb025e0e4e9002ac6e65b8e27c27a0b 05d6c0e2fa80bbd088b67c039520fe74ef4aa7c946f75c86207af125e7e2e6b4 +lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll 9eb08ce070e3a48ed1ff11e884492c27daeae2613377d4e20a08abba917fe068 d0b293c68f5562ff27ff6bb894723e3965348530fe4924b1e492a78a9f2911d7 +lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll 578ff8a344c6e5d1b5d2aae9f7ca0c8205e4aab42cd1f73d00720d7c34a9c407 68c78198f1c280cb1566299b747da2b359fa9d4273e4f167693986af41450b3c lib/codeql/swift/elements/expr/StringLiteralExprConstructor.qll 49de92f9566459609f4a05b7bf9b776e3a420a7316151e1d3d4ec4c5471dcffb 4a7474d3782b74a098afe48599faee2c35c88c1c7a47d4b94f79d39921cd4a1f lib/codeql/swift/elements/expr/StringToPointerExpr.qll c30a9f184de3f395183751a826c59e5e3605560f738315cead3bf89a49cfe23c 6f6710f7ac709102b0f3240dcd779baf5da00d2e7a547d19291600bc405c5a54 lib/codeql/swift/elements/expr/StringToPointerExprConstructor.qll 138dd290fff168d00af79f78d9d39a1940c2a1654afd0ec02e36be86cebef970 66f7385721789915b6d5311665b89feff9469707fab630a6dcbf742980857fd9 @@ -360,7 +362,7 @@ lib/codeql/swift/elements/type/UnresolvedTypeConstructor.qll 76c34ca055a017a0fa7 lib/codeql/swift/elements/type/VariadicSequenceTypeConstructor.qll 0d1d2328a3b5e503a883e7e6d7efd0ca5e7f2633abead9e4c94a9f98ed3cb223 69bff81c1b9413949eacb9298d2efb718ea808e68364569a1090c9878c4af856 lib/codeql/swift/elements/type/WeakStorageType.qll 7c07739cfc1459f068f24fef74838428128054adf611504d22532e4a156073e7 9c968414d7cc8d672f3754bced5d4f83f43a6d7872d0d263d79ff60483e1f996 lib/codeql/swift/elements/type/WeakStorageTypeConstructor.qll d88b031ef44d6de14b3ddcff2eb47b53dbd11550c37250ff2edb42e5d21ec3e9 26d855c33492cf7a118e439f7baeed0e5425cfaf058b1dcc007eca7ed765c897 -lib/codeql/swift/elements.qll 3df0060edd2b2030f4e4d7d5518afe0073d798474d9b1d6185d833bec63ca8bd 3df0060edd2b2030f4e4d7d5518afe0073d798474d9b1d6185d833bec63ca8bd +lib/codeql/swift/elements.qll 08d1b17dc7cd5f438b1fc606098b027051e0f3cc1adde2c22c2e5bb83f7cf66f 08d1b17dc7cd5f438b1fc606098b027051e0f3cc1adde2c22c2e5bb83f7cf66f lib/codeql/swift/generated/AstNode.qll 02ca56d82801f942ae6265c6079d92ccafdf6b532f6bcebd98a04029ddf696e4 6216fda240e45bd4302fa0cf0f08f5f945418b144659264cdda84622b0420aa2 lib/codeql/swift/generated/AvailabilityInfo.qll 1e38e7f52ccbcecd4dd088eae15c482d87911682dabb426332cc0e207fc6bf2f 7c6640530cdbece90d4172e8d6cfd119656860da08bb61ed4ef3a6757723994f lib/codeql/swift/generated/AvailabilitySpec.qll fb1255f91bb5e41ad4e9c675a2efbc50d0fb366ea2de68ab7eebd177b0795309 144e0c2e7d6c62ecee43325f7f26dcf437881edf0b75cc1bc898c6c4b61fdeaf @@ -376,12 +378,12 @@ lib/codeql/swift/generated/KeyPathComponent.qll c79c7bc04fc1426992ab472eedc1a20a lib/codeql/swift/generated/Locatable.qll be20967d48a34cdba126fe298606e0adc11697831f097acba9c52a0b7ce9983e 8aa01bc376614abbc3209e25785c72f86c9b4e94bb5f471a4a0677fedaec4f61 lib/codeql/swift/generated/Location.qll c5793987e77812059a28254dadee29bfe9b38153c0399fbb1bf6a2f5c237fdab 6e6d8802b021e36bbaad81845657769dd48a798ea33080ada05e9818a20b38f7 lib/codeql/swift/generated/OtherAvailabilitySpec.qll 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 0e26a203b26ff0581b7396b0c6d1606feec5cc32477f676585cdec4911af91c5 -lib/codeql/swift/generated/ParentChild.qll 680cbaa7cad7b8c33b7cf3b60aba7013facdbc5601b5076a6f38560fd284f2e8 af472eeaca6bd32848cb2de647ff015053f9fb7c54c1eca18f91fcc6ea8ad7b7 +lib/codeql/swift/generated/ParentChild.qll 235b7536d6c6b027871a1308463352e4486e2e66ed179e737bf1ac35944c2aa9 9e0d24028afd81836e8fee80cf679f39b18526c95a375b4acb2f1db0508200bf lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0 lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 -lib/codeql/swift/generated/Raw.qll 59a847c009d682dfceb72f33bb54d6cf6da589e59a386450bb5fba310a4170e7 ed02d96d3bfc998a105b8f34e6a92d966e6c3db5c581872a53ac5db6904e5fab -lib/codeql/swift/generated/Synth.qll 551fdf7e4b53f9ee1314d1bb42c2638cf82f45bfa1f40a635dfa7b6072e4418c 9ab178464700a19951fc5285acacda4913addee81515d8e072b3d7055935a814 -lib/codeql/swift/generated/SynthConstructors.qll 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4 +lib/codeql/swift/generated/Raw.qll c8a8239c706663f0ba459ead3225ebb056d3195ab12238242d4c36bf3d5a91ef cd129bba1fb9dee274cf0d0d2d618704b4b69b30267891ee22df9db8f0e9e42f +lib/codeql/swift/generated/Synth.qll 0e299d5d910589d82be11fc503640d425ea20478b8a5802347fbc575075dd53c dc87a4f03bb1ead4ef6676e6fd1b53b38b9ec6904b5113f24eb7a778f089490a +lib/codeql/swift/generated/SynthConstructors.qll e6533af43a95a90e6e07add5720c83f436aa2a24c445080ba5e8cbc6417b973f e6533af43a95a90e6e07add5720c83f436aa2a24c445080ba5e8cbc6417b973f lib/codeql/swift/generated/UnknownFile.qll 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 0fcf9beb8de79440bcdfff4bb6ab3dd139bd273e6c32754e05e6a632651e85f6 lib/codeql/swift/generated/UnknownLocation.qll e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882 e50efefa02a0ec1ff635a00951b5924602fc8cab57e5756e4a039382c69d3882 lib/codeql/swift/generated/UnspecifiedElement.qll bfe0dfb0a34fe8f7501710809cdfb82dc423bece9f3bcd23ebfb0e3ecb7aadf7 cdf7553ba0324a7670f6a275ff99bad96498f7363234f829533a27b6e97892f4 @@ -531,6 +533,7 @@ lib/codeql/swift/generated/expr/RebindSelfInInitializerExpr.qll 66d4cbf211cae63a lib/codeql/swift/generated/expr/RegexLiteralExpr.qll a11eb6f6ce7cebb35ab9ff51eae85f272980140814d7e6bded454069457a1312 bdb4bb65c9f4e187cf743ed13c0213bb7e55db9cc3adeae2169df5e32b003940 lib/codeql/swift/generated/expr/SelfApplyExpr.qll c0815a4d6d4f08bd0c7bc170fa817ebcb2328c937c8ef16391fb0da71aff17ae 0979f035e8d4b54e93f17163a4df3c2aa65f23d56c491fa72376887e3e5c10ac lib/codeql/swift/generated/expr/SequenceExpr.qll 62301b2e4c76de4820c6deef0ee95c8b328ed14ba8eac70aa10cc8fb0f3c5ace feb960c796ea517abc9587bd76f7ae9aabfd9a6b0984fe2d8380e803b002eede +lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll 0aa30e7604922c4acbc19f56ecf41248f8f44248e2313fb57c5743ada3a1791b c36bcc93d091c5735c5c62da939a68e32be11a344496815342de57d94b506ee8 lib/codeql/swift/generated/expr/StringLiteralExpr.qll f420c5cd51a223b6f98177147967266e0094a5718ba2d57ae2d3acbb64bbb4b6 30d6dab2a93fd95e652a700902c4d106fecfce13880c2ece565de29f2504bedf lib/codeql/swift/generated/expr/StringToPointerExpr.qll ef69b570aa90697d438f5787a86797955b4b2f985960b5859a7bd13b9ecb9cd3 ef69b570aa90697d438f5787a86797955b4b2f985960b5859a7bd13b9ecb9cd3 lib/codeql/swift/generated/expr/SubscriptExpr.qll 8a2bf1f0ded1888546791e0e59b969267f0352223e2abeb38e91dfa2144a38ae 009566ef61689d14844730235b0e0c31ee01e95e2002cf7272cbabc97539dce9 @@ -832,6 +835,7 @@ test/extractor-tests/generated/expr/PropertyWrapperValuePlaceholderExpr/Property test/extractor-tests/generated/expr/PropertyWrapperValuePlaceholderExpr/PropertyWrapperValuePlaceholderExpr_getWrappedValue.ql 208153f062b04bec13a860b64ea51c1d531597140d81a6d4598294dc9f8649a2 dfaea19e1075c02dfc0366fac8fd2edfae8dde06308730eb462c54be5b571129 test/extractor-tests/generated/expr/RebindSelfInInitializerExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 test/extractor-tests/generated/expr/RegexLiteralExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 +test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 test/extractor-tests/generated/expr/StringLiteralExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 test/extractor-tests/generated/expr/SubscriptExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 test/extractor-tests/generated/expr/SuperRefExpr/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 diff --git a/swift/ql/.gitattributes b/swift/ql/.gitattributes index a1e00251e800b..9539c4d8b2d0c 100644 --- a/swift/ql/.gitattributes +++ b/swift/ql/.gitattributes @@ -195,6 +195,8 @@ /lib/codeql/swift/elements/expr/SelfApplyExpr.qll linguist-generated /lib/codeql/swift/elements/expr/SequenceExpr.qll linguist-generated /lib/codeql/swift/elements/expr/SequenceExprConstructor.qll linguist-generated +/lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll linguist-generated +/lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll linguist-generated /lib/codeql/swift/elements/expr/StringLiteralExprConstructor.qll linguist-generated /lib/codeql/swift/elements/expr/StringToPointerExpr.qll linguist-generated /lib/codeql/swift/elements/expr/StringToPointerExprConstructor.qll linguist-generated @@ -533,6 +535,7 @@ /lib/codeql/swift/generated/expr/RegexLiteralExpr.qll linguist-generated /lib/codeql/swift/generated/expr/SelfApplyExpr.qll linguist-generated /lib/codeql/swift/generated/expr/SequenceExpr.qll linguist-generated +/lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll linguist-generated /lib/codeql/swift/generated/expr/StringLiteralExpr.qll linguist-generated /lib/codeql/swift/generated/expr/StringToPointerExpr.qll linguist-generated /lib/codeql/swift/generated/expr/SubscriptExpr.qll linguist-generated @@ -834,6 +837,7 @@ /test/extractor-tests/generated/expr/PropertyWrapperValuePlaceholderExpr/PropertyWrapperValuePlaceholderExpr_getWrappedValue.ql linguist-generated /test/extractor-tests/generated/expr/RebindSelfInInitializerExpr/MISSING_SOURCE.txt linguist-generated /test/extractor-tests/generated/expr/RegexLiteralExpr/MISSING_SOURCE.txt linguist-generated +/test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt linguist-generated /test/extractor-tests/generated/expr/StringLiteralExpr/MISSING_SOURCE.txt linguist-generated /test/extractor-tests/generated/expr/SubscriptExpr/MISSING_SOURCE.txt linguist-generated /test/extractor-tests/generated/expr/SuperRefExpr/MISSING_SOURCE.txt linguist-generated diff --git a/swift/ql/lib/codeql/swift/elements.qll b/swift/ql/lib/codeql/swift/elements.qll index 7c75c11c9762e..321b6cfa1fbd3 100644 --- a/swift/ql/lib/codeql/swift/elements.qll +++ b/swift/ql/lib/codeql/swift/elements.qll @@ -160,6 +160,7 @@ import codeql.swift.elements.expr.ProtocolMetatypeToObjectExpr import codeql.swift.elements.expr.RebindSelfInInitializerExpr import codeql.swift.elements.expr.RegexLiteralExpr import codeql.swift.elements.expr.SequenceExpr +import codeql.swift.elements.expr.SingleValueStmtExpr import codeql.swift.elements.expr.StringLiteralExpr import codeql.swift.elements.expr.StringToPointerExpr import codeql.swift.elements.expr.SubscriptExpr diff --git a/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll b/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll new file mode 100644 index 0000000000000..821ffa8c129b9 --- /dev/null +++ b/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExpr.qll @@ -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.SingleValueStmtExpr + +class SingleValueStmtExpr extends Generated::SingleValueStmtExpr { } diff --git a/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll b/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll new file mode 100644 index 0000000000000..72ca112012dd1 --- /dev/null +++ b/swift/ql/lib/codeql/swift/elements/expr/SingleValueStmtExprConstructor.qll @@ -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 constructSingleValueStmtExpr(Raw::SingleValueStmtExpr id) { any() } diff --git a/swift/ql/lib/codeql/swift/generated/ParentChild.qll b/swift/ql/lib/codeql/swift/generated/ParentChild.qll index 0467fa10caf0e..0e98a9e889a9d 100644 --- a/swift/ql/lib/codeql/swift/generated/ParentChild.qll +++ b/swift/ql/lib/codeql/swift/generated/ParentChild.qll @@ -1745,6 +1745,24 @@ private module Impl { ) } + private Element getImmediateChildOfSingleValueStmtExpr( + SingleValueStmtExpr e, int index, string partialPredicateCall + ) { + exists(int b, int bExpr, int n, int nStmt | + b = 0 and + bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and + n = bExpr and + nStmt = n + 1 and + ( + none() + or + result = getImmediateChildOfExpr(e, index - b, partialPredicateCall) + or + index = n and result = e.getStmt() and partialPredicateCall = "Stmt()" + ) + ) + } + private Element getImmediateChildOfSuperRefExpr( SuperRefExpr e, int index, string partialPredicateCall ) { @@ -4977,6 +4995,8 @@ private module Impl { or result = getImmediateChildOfSequenceExpr(e, index, partialAccessor) or + result = getImmediateChildOfSingleValueStmtExpr(e, index, partialAccessor) + or result = getImmediateChildOfSuperRefExpr(e, index, partialAccessor) or result = getImmediateChildOfTapExpr(e, index, partialAccessor) diff --git a/swift/ql/lib/codeql/swift/generated/Raw.qll b/swift/ql/lib/codeql/swift/generated/Raw.qll index 00693018cf1d1..410645971d8b0 100644 --- a/swift/ql/lib/codeql/swift/generated/Raw.qll +++ b/swift/ql/lib/codeql/swift/generated/Raw.qll @@ -1571,6 +1571,18 @@ module Raw { Expr getElement(int index) { sequence_expr_elements(this, index, result) } } + /** + * INTERNAL: Do not use. + */ + class SingleValueStmtExpr extends @single_value_stmt_expr, Expr { + override string toString() { result = "SingleValueStmtExpr" } + + /** + * Gets the statement of this single value statement expression. + */ + Stmt getStmt() { single_value_stmt_exprs(this, result) } + } + /** * INTERNAL: Do not use. */ diff --git a/swift/ql/lib/codeql/swift/generated/Synth.qll b/swift/ql/lib/codeql/swift/generated/Synth.qll index fdbadffcd33b4..d10b7b2d1b6e5 100644 --- a/swift/ql/lib/codeql/swift/generated/Synth.qll +++ b/swift/ql/lib/codeql/swift/generated/Synth.qll @@ -579,6 +579,10 @@ module Synth { * INTERNAL: Do not use. */ TSequenceExpr(Raw::SequenceExpr id) { constructSequenceExpr(id) } or + /** + * INTERNAL: Do not use. + */ + TSingleValueStmtExpr(Raw::SingleValueStmtExpr id) { constructSingleValueStmtExpr(id) } or /** * INTERNAL: Do not use. */ @@ -1172,8 +1176,8 @@ module Synth { TOneWayExpr or TOpaqueValueExpr or TOpenExistentialExpr or TOptionalEvaluationExpr or TOtherInitializerRefExpr or TOverloadedDeclRefExpr or TPropertyWrapperValuePlaceholderExpr or TRebindSelfInInitializerExpr or TSequenceExpr or - TSuperRefExpr or TTapExpr or TTupleElementExpr or TTupleExpr or TTypeExpr or - TUnresolvedDeclRefExpr or TUnresolvedDotExpr or TUnresolvedMemberExpr or + TSingleValueStmtExpr or TSuperRefExpr or TTapExpr or TTupleElementExpr or TTupleExpr or + TTypeExpr or TUnresolvedDeclRefExpr or TUnresolvedDotExpr or TUnresolvedMemberExpr or TUnresolvedPatternExpr or TUnresolvedSpecializeExpr or TVarargExpansionExpr; /** @@ -2373,6 +2377,15 @@ module Synth { cached TSequenceExpr convertSequenceExprFromRaw(Raw::Element e) { result = TSequenceExpr(e) } + /** + * INTERNAL: Do not use. + * Converts a raw element to a synthesized `TSingleValueStmtExpr`, if possible. + */ + cached + TSingleValueStmtExpr convertSingleValueStmtExprFromRaw(Raw::Element e) { + result = TSingleValueStmtExpr(e) + } + /** * INTERNAL: Do not use. * Converts a raw element to a synthesized `TStringLiteralExpr`, if possible. @@ -3656,6 +3669,8 @@ module Synth { or result = convertSequenceExprFromRaw(e) or + result = convertSingleValueStmtExprFromRaw(e) + or result = convertSuperRefExprFromRaw(e) or result = convertTapExprFromRaw(e) @@ -5178,6 +5193,15 @@ module Synth { cached Raw::Element convertSequenceExprToRaw(TSequenceExpr e) { e = TSequenceExpr(result) } + /** + * INTERNAL: Do not use. + * Converts a synthesized `TSingleValueStmtExpr` to a raw DB element, if possible. + */ + cached + Raw::Element convertSingleValueStmtExprToRaw(TSingleValueStmtExpr e) { + e = TSingleValueStmtExpr(result) + } + /** * INTERNAL: Do not use. * Converts a synthesized `TStringLiteralExpr` to a raw DB element, if possible. @@ -6461,6 +6485,8 @@ module Synth { or result = convertSequenceExprToRaw(e) or + result = convertSingleValueStmtExprToRaw(e) + or result = convertSuperRefExprToRaw(e) or result = convertTapExprToRaw(e) diff --git a/swift/ql/lib/codeql/swift/generated/SynthConstructors.qll b/swift/ql/lib/codeql/swift/generated/SynthConstructors.qll index 524d39f20a246..58c4d9fc15523 100644 --- a/swift/ql/lib/codeql/swift/generated/SynthConstructors.qll +++ b/swift/ql/lib/codeql/swift/generated/SynthConstructors.qll @@ -127,6 +127,7 @@ import codeql.swift.elements.expr.ProtocolMetatypeToObjectExprConstructor import codeql.swift.elements.expr.RebindSelfInInitializerExprConstructor import codeql.swift.elements.expr.RegexLiteralExprConstructor import codeql.swift.elements.expr.SequenceExprConstructor +import codeql.swift.elements.expr.SingleValueStmtExprConstructor import codeql.swift.elements.expr.StringLiteralExprConstructor import codeql.swift.elements.expr.StringToPointerExprConstructor import codeql.swift.elements.expr.SubscriptExprConstructor diff --git a/swift/ql/lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll b/swift/ql/lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll new file mode 100644 index 0000000000000..72b298a17262d --- /dev/null +++ b/swift/ql/lib/codeql/swift/generated/expr/SingleValueStmtExpr.qll @@ -0,0 +1,21 @@ +// generated by codegen/codegen.py +private import codeql.swift.generated.Synth +private import codeql.swift.generated.Raw +import codeql.swift.elements.expr.Expr +import codeql.swift.elements.stmt.Stmt + +module Generated { + class SingleValueStmtExpr extends Synth::TSingleValueStmtExpr, Expr { + override string getAPrimaryQlClass() { result = "SingleValueStmtExpr" } + + /** + * Gets the statement of this single value statement expression. + */ + Stmt getStmt() { + result = + Synth::convertStmtFromRaw(Synth::convertSingleValueStmtExprToRaw(this) + .(Raw::SingleValueStmtExpr) + .getStmt()) + } + } +} diff --git a/swift/ql/lib/swift.dbscheme b/swift/ql/lib/swift.dbscheme index 7c17e1f4b2d30..fcc7b497930ad 100644 --- a/swift/ql/lib/swift.dbscheme +++ b/swift/ql/lib/swift.dbscheme @@ -764,6 +764,7 @@ arguments( //dir=expr | @property_wrapper_value_placeholder_expr | @rebind_self_in_initializer_expr | @sequence_expr +| @single_value_stmt_expr | @super_ref_expr | @tap_expr | @tuple_element_expr @@ -1143,6 +1144,11 @@ sequence_expr_elements( //dir=expr int element: @expr_or_none ref ); +single_value_stmt_exprs( //dir=expr + unique int id: @single_value_stmt_expr, + int stmt: @stmt_or_none ref +); + super_ref_exprs( //dir=expr unique int id: @super_ref_expr, int self: @var_decl_or_none ref diff --git a/swift/ql/test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt b/swift/ql/test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt new file mode 100644 index 0000000000000..25daf3d23a213 --- /dev/null +++ b/swift/ql/test/extractor-tests/generated/expr/SingleValueStmtExpr/MISSING_SOURCE.txt @@ -0,0 +1,4 @@ +// generated by codegen/codegen.py + +After a source file is added in this directory and codegen/codegen.py is run again, test queries +will appear and this file will be deleted diff --git a/swift/ql/test/library-tests/dataflow/flowsources/CONSISTENCY/CfgConsistency.expected b/swift/ql/test/library-tests/dataflow/flowsources/CONSISTENCY/CfgConsistency.expected new file mode 100644 index 0000000000000..eca8be91c8b94 --- /dev/null +++ b/swift/ql/test/library-tests/dataflow/flowsources/CONSISTENCY/CfgConsistency.expected @@ -0,0 +1,5 @@ +deadEnd +| alamofire.swift:469:9:469:9 | stream | +| alamofire.swift:484:9:484:9 | stream | +| alamofire.swift:499:9:499:9 | stream | +| alamofire.swift:514:9:514:9 | stream | diff --git a/swift/schema.py b/swift/schema.py index c46a2e4552d27..9863f01bc26e1 100644 --- a/swift/schema.py +++ b/swift/schema.py @@ -1239,3 +1239,7 @@ class ParameterizedProtocolType(Type): class AbiSafeConversionExpr(ImplicitConversionExpr): pass + + +class SingleValueStmtExpr(Expr): + stmt: Stmt | child