Commit Graph

6845 Commits

Author SHA1 Message Date
Jonas Jensen
f88dc37218 Merge pull request #99 from aschackmull/java/fieldflow-perf
Java/C: Improve performance when multiple configs use field flow.
2018-08-28 15:27:29 +02:00
Jonas Jensen
4536d75b2f Merge pull request #93 from ian-semmle/underlyingElement
C++: Add a missing underlyingElement call
2018-08-28 15:24:16 +02:00
Jonas Jensen
ea26ac8c22 C++: Remove unneeded CPython toString overrides
These were made redundant when a1e44041e changed their parent class to
extend `Element`.
2018-08-28 14:58:39 +02:00
Jonas Jensen
38fe45ef32 C++: Don't use dbtypes in Declaration.qll 2018-08-28 14:58:39 +02:00
Jonas Jensen
01dc4385cd C++: Don't use dbtypes in TaintTracking.qll 2018-08-28 14:58:39 +02:00
Jonas Jensen
854d0db552 C++: Don't use dbtypes in ClassesWithManyFields.ql
This changes the test output because `VariableDeclarationGroup.toString`
changes to be the one inherited from VariableDeclarationEntry. This
should not affect the output as shown by any front end because
the string to be displayed to the user for a `$@` interpolation comes
from the following column instead.
2018-08-28 14:58:39 +02:00
Jonas Jensen
1d11a13230 C++: Don't use dbtypes in SuppressionScope
This avoids using a raw db type.

It is possible for `SuppressionComment` and `SuppressionScope` to have
different locations because `SuppressionScope` defines `hasLocationInfo`
as a new rootdef whereas `SuppressionComment` only responds to
`getLocation` that it inherited. In interpretation of query results, a
`hasLocationInfo` predicate is preferred over `getLocation` if it
exists.
2018-08-28 14:58:39 +02:00
Jonas Jensen
f005d45c63 C++: Change SuppressionScope.toString
This should have no effect in itself but changes the test output to
correspond with the change coming next.
2018-08-28 14:58:39 +02:00
Jonas Jensen
367776511f C++: Don't use dbtypes in ControlFlowNode etc.
Many classes have been declared with `extends @cfgnode` because they
should be implemented internally as a control-flow node but should not
expose the member predicates of `ControlFlowNode` to their users. After
the transition in a1e44041e it became mandatory to convert explicitly
between the `Element`-derived `ControlFlowNode` and the raw dbtype
`@cfgnode`, and that commit inserted numerous such conversions as a
result of having all those classes that did not derive from `Element` in
the standard library.

It was also confusing and error-prone that the libraries implementing
`ControlFlowNode` referred to `ControlFlowNode`. This seemingly cyclic
reference worked out because the libraries did not call the predicates
on `ControlFlowNode` whose implementation they were part of.

Both these problems are now solved by adding a new class
`ControlFlowNodeBase extends Element` that should be used in preference
to `@cfgnode` everywhere. This class is for exactly those use cases
where `@cfgnode` should be seen as an `Element` without having too many
member predicates on it.

The classes that move from extending `@cfgnode` to extending
`ControlFlowNodeBase` are: `BasicBlock`, `AdditionalControlFlowEdge`,
`DefOrUse`, `SsaDefinition`, `SubBasicBlock` and `RangeSsaDefinition`.
These previously had to define their own `toString` rootdef, which
typically had some dummy string as result (like `"BasicBlock"`), but now
their `toString` is part of the `Element` rootdef and should not be
overridden otherwise `Element.toString` will sometimes have multiple
results. Removing these dummy `toString` predicates had some effects on
the tests that are included in this commit.

The `getLocation` family of predicates is affected like `toString`, but
the situation is slightly different. Some of these classes had genuinely
useful alternative definitions of locations. Fortunately, they all used
`hasLocationInfo`, which is preferred over `getLocation` by the QL
engine. Because `Element` does not define `getLocationInfo`, each class
can create its own rootdef of this predicate like before.
2018-08-28 14:27:32 +02:00
Nick Rolfe
f44f8d576d C++: test that __declspec(guard(...)) doesn't cause extractor errors 2018-08-28 10:24:53 +01:00
Dave Bartolomeo
6e0fe92434 C++: Fix comments to reference Call instead of Invoke 2018-08-27 11:02:07 -07:00
Dave Bartolomeo
b44c2c72a6 C++: Invoke -> Call
Now that opcodes are in their own module that isn't imported into the global namespace, `Opcode::Call` no longer conflicts with `Call` from the ASTs. I've renamed `Opcode::Invoke` to `Opcode::Call`.
2018-08-27 09:22:01 -07:00
Pavel Avgustinov
d0497a5cff Merge pull request #106 from dave-bartolomeo/dave/LF
Force LF line endings for .ql, .qll, .qlref, and .dbscheme
2018-08-27 10:04:53 +01:00
Jonas Jensen
dc0f3be753 Merge pull request #102 from ian-semmle/type_variants
C++: Tweak type_variants test
2018-08-27 10:34:45 +02:00
Anders Schack-Mulligen
f2760f2547 Java/C: Improve performance when multiple configs use field flow. 2018-08-27 10:00:58 +02:00
Dave Bartolomeo
2af82d9485 LF for .qhelp files too 2018-08-26 21:12:51 -07:00
Jonas Jensen
1ed4a489ec C++: Make ControlFlowNode's predicates concrete
The presence of abstract predicates on this class made it hard to
specialize it, and this is one of the reasons why the raw db-type
`@cfgnode` is often used in preference to `ControlFlowNode`.
2018-08-24 22:03:59 +02:00
Dave Bartolomeo
d920fc7d94 Force LF line endings for .ql, .qll, and .qlref files 2018-08-24 11:58:58 -07:00
Nick Rolfe
7cf550a70f C++: regression test for extractor bug with enum in template class 2018-08-24 18:41:37 +01:00
Nick Rolfe
193e013196 C++: accept more extraction of functions in local classes/lambdas 2018-08-24 18:41:37 +01:00
Nick Rolfe
da7d70662b C++: accept more test changes following extractor frontend upgrade 2018-08-24 18:41:37 +01:00
Nick Rolfe
04385a83ba C++: fix tests: frontend no longer optimises dynamic_cast to base type 2018-08-24 18:41:37 +01:00
Nick Rolfe
dd169d1b21 C++: fix test to enable C++11 support in frontend 2018-08-24 18:41:37 +01:00
Dave Bartolomeo
65ed9afdfb C++: Update test expectations for other PrintAST test 2018-08-24 08:50:35 -07:00
Dave Bartolomeo
c4d6e1b01c C++: Fix wobble in PrintAST test
PrintAST.ql orders the functions by location, then in lexicographical order of the function signature. This is supposed to ensure a stable ordering, but functions without a location were not getting assigned an order at all.
2018-08-24 08:36:30 -07:00
Ian Lynagh
01c7fc1c8b C++: Tweak type_variants test
It's now easier to see what's happening in cases where 2 functions have
the same name, or a function has 2 locations.
2018-08-24 14:46:02 +01:00
Jonas Jensen
1f844e2a7c Merge pull request #95 from ian-semmle/resolveClass
C++: Rename resolve to resolveClass, and remove unused isElement
2018-08-23 22:13:13 +02:00
Jonas Jensen
58e993e877 Merge pull request #82 from dave-bartolomeo/dave/NewDelete2
C++: IR generation for `new` and `new[]`
2018-08-23 21:14:07 +02:00
Dave Bartolomeo
72e72357c2 C++: Use glval<Unknown> as type of call target
Also shared some code between `TranslatedFunctionCall` and `TranslatedAllocatorCall`, and fixed dumps of glval<Unknown> to not print the size.
2018-08-23 09:43:58 -07:00
Ian Lynagh
7ee5efcab0 C++: Rename internal.Type to internal.ResolveClass 2018-08-23 15:40:25 +01:00
Ian Lynagh
e808560c23 C++: Rename resolve to resolveClass, and remove unused isElement 2018-08-23 14:37:38 +01:00
Ian Lynagh
b76e03ca79 C++: Add a missing underlyingElement call 2018-08-23 13:14:04 +01:00
Jonas Jensen
fc0330beb6 C++: Make XMLFile extend File again
Commit a1e44041e made `XMLFile` no longer extend `File`. I'm guessing
this was necessary in the branch where `File` was an IPA-typed `Element`
and `XMLFile` was not, but it broke compilation of some of our internal
queries.
2018-08-23 10:09:42 +02:00
Dave Bartolomeo
bba7f16790 C++: Simplify TranslatedExpr hierarchy a bit
I introduced some unnecessary base classes in the `TranslatedExpr` hierarchy with a previous commit. This commit refactors the hierarchy a bit to align with the following high-level description:
`TranslatedExpr` represents a translated piece of an `Expr`. Each `Expr` has exactly one `TranslatedCoreExpr`, which produces the result of that `Expr` ignoring any lvalue-to-rvalue conversion on its result. If an lvalue-to-rvalue converison is present, there is an additional `TranslatedLoad` for that `Expr` to do the conversion. For higher-level `Expr`s like `NewExpr`, there can also be additional `TranslatedExpr`s to represent the sub-operations within the overall `Expr`, such as the allocator call.
2018-08-22 17:13:03 -07:00
Nick Rolfe
61bd003cf9 Merge pull request #86 from ian-semmle/typo
C++: Fix a copy/paste error in a comment
2018-08-22 10:18:38 +01:00
Dave Bartolomeo
b9a8293610 C++: IR translation for NewExpr and NewArrayExpr
These expressions are a little trickier than most because they include an implicit call to an allocator function. The database tells us which function to call, but we have to synthesize the allocation size and alignment arguments ourselves. The alignment argument, if it exists, is always a constant, but the size argument requires multiplication by the element count for most `NewArrayExpr`s. I introduced the new `TranslatedAllocationSize` class to handle this.
2018-08-21 11:10:29 -07:00
Dave Bartolomeo
07c08f83a6 Create common base class for NewExpr and NewArrayExpr 2018-08-21 11:10:28 -07:00
Nick Rolfe
44ae7b68f0 Merge pull request #63 from ian-semmle/unused_db_types
C++: Remove some unused DB types
2018-08-21 18:27:35 +01:00
Jonas Jensen
3bc9323844 Merge pull request #84 from rdmarsh2/rdmarsh/cpp/macro-get-expr-conversions
C++: exclude conversion in MacroInvocation.getExpr
2018-08-21 19:15:42 +02:00
Jonas Jensen
2481bc7ba2 Merge pull request #72 from dave-bartolomeo/dave/InitMemory
C++: Make `InitializeParameter` and `Uninitialized` return memory results
2018-08-21 19:04:20 +02:00
Ian Lynagh
8a4040e4e0 C++: Update stats 2018-08-21 11:22:19 +01:00
Ian Lynagh
176b7cb8bc C++: Remove some unused DB types 2018-08-21 11:22:19 +01:00
Ian Lynagh
68959cae3a C++: Fix a copy/paste error in a comment 2018-08-21 11:20:06 +01:00
Jonas Jensen
ea9bff00c0 Merge pull request #7 from ian-semmle/alg6un_squashed
C++: resolveElement
2018-08-21 11:35:45 +02:00
Robert Marsh
51bfb8db88 C++: exclude conversion in MacroInvocation.getExpr 2018-08-20 15:10:28 -07:00
Ian Lynagh
0f350780bb C++: Make Folder.getURL() consistent with Folder.getLocation() 2018-08-20 19:01:31 +01:00
Dave Bartolomeo
f2053c488e C++: Make InitializeParameter and Uninitialized return memory results
The IR avoids having non-trivially-copyable and non-trivially-assignable types in register results, because objects of those types need to exist at a particular memory location. The `InitializeParameter` and `Uninitialized` instructions were violating this restriction because they returned register results, which were then stored into the destination location via a `Store`.

This change makes those two instructions take the destination address as an operand, and return a memory result representing the (un-)initialized memory, removing the need for a separate `Store` instruction.
2018-08-20 09:13:45 -07:00
Ian Lynagh
99dbbdf863 C++: Add some comments 2018-08-20 16:12:26 +01:00
Ian Lynagh
9c4d4f8732 C++: No need to cache so many predicates 2018-08-20 16:12:26 +01:00
Ian Lynagh
c241b081cb C++: Don't unresolve 'this'
For example, if you have 3 types called T, where t1 and t2 are defined
but t3 isn't, then you will have

    unspecifiedtype(t1, t1)
    unspecifiedtype(t2, t2)
    unspecifiedtype(t3, t3)

    t1 = resolve(t1)
    t1 = resolve(t3)
    t2 = resolve(t2)
    t2 = resolve(t3)

so given

    Type getUnspecifiedType() {
        unspecifiedtype(unresolve(this), unresolve(result))
    }

you get t1.getUnspecifiedType() = t2.

I think that in general the best thing to do is to not unresolve 'this',
but to just take the underlying value.
2018-08-20 16:12:26 +01:00