From 5353ad7eceebf3ccab711169d6cb55ef6ba4044c 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 5066205db6e0..bd3042be2e8f 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 3274c49675e6..de24e27226ac 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 504f66999cf8..fa3a1ef3c868 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 0cbf708469f6..2395cfd5c2df 100644 --- a/swift/ql/.generated.list +++ b/swift/ql/.generated.list @@ -194,6 +194,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 @@ -361,7 +363,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 @@ -377,12 +379,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 6415d679ce1d6fa227751ce260e4c3322494151c8df7e6e66c3d4b11878c3b9a 2e3ae6706170c1fdaaab947b55b145d50175c4e8ca669c8160bf2a4ee6524c7f +lib/codeql/swift/generated/ParentChild.qll 64d0ebc5244a9488d87fa3e4a93a77ad222a3b3963ec9b6687ca855c7279b141 63ec6bb73408eb526820c866f69751723e3e267580e0cc047b43ffdae0204aa8 lib/codeql/swift/generated/PlatformVersionAvailabilitySpec.qll f82d9ca416fe8bd59b5531b65b1c74c9f317b3297a6101544a11339a1cffce38 7f5c6d3309e66c134107afe55bae76dfc9a72cb7cdd6d4c3706b6b34cee09fa0 lib/codeql/swift/generated/PureSynthConstructors.qll 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 173c0dd59396a1de26fe870e3bc2766c46de689da2a4d8807cb62023bbce1a98 -lib/codeql/swift/generated/Raw.qll 233caf2d5f8d584c20e023151aefe7be454013ed3fd73239d35528b1e74af1c5 e0d8ad912aa936d0766fdd9183d35057876d08e7cbcbbd01ff6e9d3d615f1046 -lib/codeql/swift/generated/Synth.qll 551fdf7e4b53f9ee1314d1bb42c2638cf82f45bfa1f40a635dfa7b6072e4418c 9ab178464700a19951fc5285acacda4913addee81515d8e072b3d7055935a814 -lib/codeql/swift/generated/SynthConstructors.qll 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4 2f801bd8b0db829b0253cd459ed3253c1fdfc55dce68ebc53e7fec138ef0aca4 +lib/codeql/swift/generated/Raw.qll 551cd33d3d1ea95af24b39604181b701332ce57690ff6b07d840c849bfbe113d 7f612cd455b03dc12483c81f43f4bc26c67950ced643afcb0c92085d198c351b +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 ad04c197266069baf505e529e62751ab3056b4bac5db378fe1f79bbdfa29e066 a5058c7e3e0ba7d52710161e349a71f3e963d4abe07ca581ad663395fc50e972 @@ -532,6 +534,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 @@ -829,6 +832,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 a487b874c158..b1946560323d 100644 --- a/swift/ql/.gitattributes +++ b/swift/ql/.gitattributes @@ -196,6 +196,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 @@ -534,6 +536,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 @@ -831,6 +834,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 7c75c11c9762..321b6cfa1fbd 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 000000000000..821ffa8c129b --- /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 000000000000..72ca112012dd --- /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 18a417054ab3..a660c9baae0a 100644 --- a/swift/ql/lib/codeql/swift/generated/ParentChild.qll +++ b/swift/ql/lib/codeql/swift/generated/ParentChild.qll @@ -1737,6 +1737,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 ) { @@ -4965,6 +4983,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 474c0a1b7279..62a35bcb3b36 100644 --- a/swift/ql/lib/codeql/swift/generated/Raw.qll +++ b/swift/ql/lib/codeql/swift/generated/Raw.qll @@ -1564,6 +1564,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 fdbadffcd33b..d10b7b2d1b6e 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 524d39f20a24..58c4d9fc1552 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 000000000000..72b298a17262 --- /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 dd1bfe298d87..57c49989b528 100644 --- a/swift/ql/lib/swift.dbscheme +++ b/swift/ql/lib/swift.dbscheme @@ -757,6 +757,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 @@ -1136,6 +1137,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 000000000000..25daf3d23a21 --- /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 000000000000..eca8be91c8b9 --- /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 493b941d2335..a6e353556560 100644 --- a/swift/schema.py +++ b/swift/schema.py @@ -1225,3 +1225,7 @@ class ParameterizedProtocolType(Type): class AbiSafeConversionExpr(ImplicitConversionExpr): pass + + +class SingleValueStmtExpr(Expr): + stmt: Stmt | child