Commit Graph

4303 Commits

Author SHA1 Message Date
Paolo Tranquilli
7fbe4f8547 Merge pull request #9815 from github/redsun82/swift-exclusive-file
Swift: trap output rework
2022-07-14 16:23:44 +02:00
Paolo Tranquilli
22ff8c2c7e Swift: remove redundant braces 2022-07-14 15:40:48 +02:00
Paolo Tranquilli
3e06455ac1 Swift: delete TargetFile's move assignment 2022-07-14 15:39:36 +02:00
Paolo Tranquilli
f1144b9672 Swift: small TypeRepr visit rewording 2022-07-14 06:18:51 +02:00
Paolo Tranquilli
d748cb483d Swift: include cleanup
Fix a problem with `sstream` not being transitively included on macOS.
2022-07-14 06:10:12 +02:00
Paolo Tranquilli
4c53c341f6 Swift: make TargetFile::good() a class invariant
Fallible initialization has been moved to a factory function, and
`commit` has been moved to the destructor.
2022-07-14 06:02:35 +02:00
Paolo Tranquilli
5773a734c3 Swift: slightly simplify a cppgen change 2022-07-13 11:27:50 +02:00
Paolo Tranquilli
f7dca4d70f Swift: trap output rework
Firstly, this change reworks how inter-process races are resolved.
Moreover some responsability reorganization has led to merging
`TrapArena` and `TrapOutput` again into a `TrapDomain` class.

A `TargetFile` class is introduced, that is successfully created
only for the first process that starts processing a given trap output
file. From then on `TargetFile` simply wraps around `<<` stream
operations, dumping them to a temporary file. When `TargetFile::commit`
is called, the temporary file is moved on to the actual target trap
file.

Processes that lose the race can now just ignore the unneeded
extraction and go on, while previously all processes would carry out
all extractions overwriting each other at the end.

Some of the file system logic contained in `SwiftExtractor.cpp` has been
moved to this class, and two TODOs are solved:
* introducing a better inter process file collision avoidance strategy
* better error handling for trap output operations: if unable to write
  to the trap file (or carry out other basic file operations), we just
  abort.

The changes to `ExprVisitor` and `StmtVisitor` are due to wanting to
hide the raw `TrapDomain::createLabel` from them, and bring more
funcionality under the generic caching/dispatching mechanism.
2022-07-13 11:19:57 +02:00
Paolo Tranquilli
48c71c9407 Swift: add comment about TypeRepr in ASTNode fetching 2022-07-12 12:10:22 +02:00
Paolo Tranquilli
033b239b22 Swift: collapse TypeRepr hierarchy
Now `TypeRepr` is a final class in the AST, which is more or less just
a type with a location in code.

As the frontend does not provide a direct way to get a type from a
type representation, this information must be provided when fetching
the label of a type repr.

This meant:
* removing the type repr field from `EnumIsCaseExpr`: this is a virtual
  AST node introduced in place of some kinds of `IsEpxr`. The type
  repr is still available from the `ConditionalCheckedCastExpr` wrapped
  by this virtual node, and we will rebuild the original `IsExpr` with
  the IPA layer.
* some logic to get the type of keypath roots has been added to
  `KeyPathExpr`. This was done to keep the `TypeRepr` to `Type` relation
  total in the DB, but goes against the design of a dumb extractor. The
  logic could be moved to QL in the future
* in the control flow library, `TypeRepr` children are now ignored. As
  far as I can tell, there is no runtime evaluation going on in
  `TypeRepr`s, so it does not make much sense to have control flow
  through them.
2022-07-12 10:49:14 +02:00
Paolo Tranquilli
93d06daf67 Swift: allow skipping fields in cppgen
Some fields of base classes pose some problems with diamond hierarchies,
and we don't use them any way as we are emitting them using directly
trap entries instead of structured C++ classes.

This introduces a `cpp_skip` pragma to skip generation of those fields
in structured generated C++ classes, and applies it to `is_unknown` and
`location`.
2022-07-11 15:59:21 +02:00
Paolo Tranquilli
39406436bf Swift: extract IfConfigDecl
This also adds `UnresolvedDeclRefExpr` tests, as `IfConfigDecl`
consistently introduces those.
2022-07-11 15:11:13 +02:00
Paolo Tranquilli
7d5dd384c3 Swift: extract UnresolvedPatternExpr 2022-07-11 10:59:00 +02:00
Paolo Tranquilli
7c3cadc9b6 Swift: extract OpenedArchetypeType 2022-07-11 10:48:21 +02:00
Mathias Vorreiter Pedersen
e98bdbf73f Merge pull request #9773 from geoffw0/stringlengthconflation4
Swift: More improvements to swift/string-length-conflation
2022-07-01 17:46:04 +01:00
Geoffrey White
e38254c05e Swift: Fix typo. 2022-07-01 17:00:36 +01:00
Geoffrey White
34ffd1aac5 Swift: Support String.Index and flow through * /. 2022-07-01 14:59:50 +01:00
Geoffrey White
d60d2457c2 Swift: Add String.Index.init as a source as as well. 2022-07-01 14:59:50 +01:00
Geoffrey White
bc03f6959c Swift: Detect String -> NSString results. 2022-07-01 14:59:50 +01:00
Geoffrey White
a306f312cd Swift: Add a test of converting Range to NSRange. 2022-07-01 14:59:50 +01:00
Geoffrey White
416977dc50 Swift: Add test cases for removeFirst, removeLast. 2022-07-01 14:59:50 +01:00
Paolo Tranquilli
8addc06799 Swift: add integration test for multiple modules 2022-07-01 15:59:36 +02:00
Paolo Tranquilli
227dad8bf5 Merge main into redsun82/swift-extraction 2022-07-01 15:56:23 +02:00
Paolo Tranquilli
f9143f7855 Swift: fix extraction of empty files 2022-07-01 15:43:16 +02:00
Paolo Tranquilli
3a975174c3 Swift: extract ImportDecl and ModuleDecl
As `ASTMangler` crashes when called on `ModuleDecl`, we simply use
its name.

This might probably not work reliably in a scenario where multiple
modules are compiled with the same name (like `main`), but this is left
for future work. At the moment this cannot create DB inconsistencies.
2022-07-01 15:29:30 +02:00
Paolo Tranquilli
7a7440a115 Swift: move createEntry to SwiftDispatcher 2022-07-01 15:22:44 +02:00
Paolo Tranquilli
901e066355 Swift: locally run integration tests
Minimal recreations of internal `integration-tests-runner.py` and
`create_database_utils.py` are provided to be able to run the
integration tests on the codeql repository with a released codeql CLI.

For the moment we skip the database checks by default, as we are still
producing inconsistent results.
2022-07-01 15:00:05 +02:00
Paolo Tranquilli
8336c67edb Merge pull request #9762 from github/alexdenisov/vfs-followup
Swift: cleanup
2022-07-01 09:00:54 +02:00
Geoffrey White
68c76006bd Swift: Allow trivial taint-like flow. 2022-06-30 11:52:57 +01:00
Geoffrey White
0251fb2d35 Swift: Add result annotations to test. 2022-06-30 11:52:44 +01:00
Geoffrey White
2bd25fc589 Swift: Add QLDoc. 2022-06-30 11:52:17 +01:00
Mathias Vorreiter Pedersen
51e3ff9d09 Merge pull request #9736 from github/redsun82/swift-fix-warnings
Swift: fix QL warnings about overriding methods
2022-06-30 11:44:44 +01:00
Alex Denisov
5a04d62969 Swift: cleanup extraction 2022-06-30 12:32:03 +02:00
Alex Denisov
133a6caaa3 Swift: cleanup output rewriting code 2022-06-30 12:03:53 +02:00
AlexDenisov
d42b752c6d Apply suggestions from code review
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:10:43 +02:00
AlexDenisov
b5c1ec8958 Update swift/extractor/SwiftOutputRewrite.cpp
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:08:23 +02:00
AlexDenisov
6b0e734c47 Update swift/extractor/SwiftOutputRewrite.cpp
Co-authored-by: Paolo Tranquilli <redsun82@github.com>
2022-06-30 11:06:03 +02:00
AlexDenisov
b9f4a09f19 Merge branch 'main' into alexdenisov/swift-multiple-modules 2022-06-30 10:13:34 +02:00
Alex Denisov
1dd3141e2d Swift: address more code review comments 2022-06-30 08:57:22 +02:00
Alex Denisov
35da75f685 Swift: rename method 2022-06-30 08:48:36 +02:00
AlexDenisov
522d48aa33 Apply suggestions from code review
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
2022-06-30 08:47:17 +02:00
Alex Denisov
5d5f3f82b1 Swift: fix test case 2022-06-30 07:41:28 +02:00
Alex Denisov
5233a5e17b Swift: also extract imported modules 2022-06-29 17:27:57 +02:00
Paolo Tranquilli
d00fec34c3 Merge pull request #9336 from MathiasVP/swift-decls-in-cfg
Swift: CFG for local declarations
2022-06-29 15:10:45 +02:00
Mathias Vorreiter Pedersen
e03646aba4 Merge pull request #9737 from geoffw0/arithmetic
Swift: Add ArithmeticOperation.qll library
2022-06-29 13:40:20 +01:00
Mathias Vorreiter Pedersen
f35ab7c292 Swift: Accept test changes to the cfg. These happen due to the fixes in 9e0cf62cda. 2022-06-29 12:20:07 +01:00
Mathias Vorreiter Pedersen
15dc08351e Merge pull request #9747 from MathiasVP/fix-joins-in-swift-cwe-135
Swift: Don't join on index in `swift/string-length-conflation`
2022-06-29 11:58:36 +01:00
Geoffrey White
8b7535af81 Swift: Don't use abstract classes. 2022-06-29 11:49:22 +01:00
Geoffrey White
2cf65c7d35 Swift: Autoformat tests. 2022-06-29 11:49:21 +01:00
Geoffrey White
822002d37d Swift: Missing qldoc. 2022-06-29 11:49:20 +01:00