Commit Graph

12966 Commits

Author SHA1 Message Date
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
Ian Lynagh
a1e44041ec C++: Use mkElement/unresolveElement consistently 2018-08-20 16:12:26 +01:00
Ian Lynagh
34c9892f77 C++: isfromtemplateinstantiation test output change 2018-08-20 16:12:26 +01:00
Dave Bartolomeo
332e944c16 C++: Remove ConvertToVoid, replace with Convert 2018-08-18 10:01:12 -07:00
Dave Bartolomeo
650539dbb6 C++: IR sanity query unnecessaryPhiInstruction
Have `Instruction.getResultSize()` return zero for `void`.
2018-08-17 15:37:19 -07:00
Dave Bartolomeo
f4a060099b C++: Handle casts to void in IR
Casts to `void` did not have a semantic conversion type in the AST, so they also weren't getting generated correctly in the IR. I've added a `VoidConversion` class to the AST, along with tests. I've also added IR translation for such conversions, using a new `ConvertToVoid` opcode. I'm not sure if it's really necessary to generate an instruction to represent this, but it may be useful for detecting values that are explicitly unused (e.g. return value from a call).

I added two new sanity queries for the IR to detect the following:
- IR blocks with no successors, which usually indicates bad IR translation
- Phi instruction without an operand for one of the predecessor blocks.

These sanity queries found another subtle IR translation bug. If an expression that is normally translated as a condition (e.g. `&&`, `||`, or parens in certain contexts) has a constant value, we were not creating a `TranslatedExpr` for the expression at all. I changed it to always treat a constant condition as a non-condition expression.
2018-08-17 01:44:54 -07:00
Dave Bartolomeo
3ebb7938f6 C++: Make IR dump and AST dump tests use the official graph query format 2018-08-16 10:14:56 -07:00
ian-semmle
692f416143 Merge pull request #40 from nickrolfe/dependent_template_alias
C++: dependent template alias
2018-08-15 17:41:24 +01:00
Geoffrey White
fdfbfb365f Merge pull request #62 from ian-semmle/302_1_test
C++: Improve the JSF 3.02 rule 1 message, and add a test
2018-08-15 17:22:33 +01:00
semmle-qlci
63180d484b Merge pull request #60 from pavgust/imp/c-wrapped-functions
Approved by dave-bartolomeo, jbj
2018-08-15 16:44:27 +01:00
Ian Lynagh
d2b4265b73 C++: Improve the JSF 3.02 rule 1 message, and add a test 2018-08-15 15:26:18 +01:00
Jonas Jensen
6225fcf2b8 Merge pull request #12 from pavgust/imp/c-locations
Simplify C locations handling
2018-08-15 16:14:31 +02:00
semmle-qlci
12577f0280 Merge pull request #47 from jbj/ir-perf-blocks-etc
Approved by dave-bartolomeo
2018-08-15 12:53:43 +01:00
Nick Rolfe
df1f51463f C++: extend test to cover template aliases 2018-08-15 10:44:51 +01:00
Nick Rolfe
5bef9f7118 C++: test for resolving specialisations dependent on template aliases 2018-08-15 10:44:51 +01:00
Geoffrey White
f904aed016 Merge pull request #57 from jbj/suites-in-ql-repo
C++: Move C/C++ suites to ql repo
2018-08-15 10:19:08 +01:00
Pavel Avgustinov
d999ada22c FunctionsWithWrappers: Simplify/tidy library. 2018-08-14 17:16:15 -07:00
Pavel Avgustinov
628edc9577 definitions.qll: Tidy up handling of type mentions 2018-08-14 16:38:57 -07:00
Pavel Avgustinov
3bc06627e1 Simplify definitions.qll for C++. 2018-08-14 16:38:56 -07:00
Pavel Avgustinov
382ae85431 Simplify location handling for C++ locations. 2018-08-14 16:38:56 -07:00
Geoffrey White
031964e853 Merge pull request #30 from jbj/incomplete-parity-check-medium
C++: Downgrade cpp/incomplete-parity-check from high to medium precision [CPP-236]
2018-08-14 15:19:02 +01:00
Jonas Jensen
dc22833259 C++: Factor out IRBlock.qll differences
All three `IRBlock.qll` files are now identical again, and they are just
a thin object-oriented layer on top of the three
`IRBlockConstruction.qll` files, two of which are identical.
2018-08-14 14:12:26 +02:00
Jonas Jensen
da02c45102 Merge pull request #36 from rdmarsh2/rdmarsh/cpp/add-security-tags
C++: add security tags to more queries
2018-08-14 12:07:28 +02:00
Jonas Jensen
3e1247257f C++: Move C/C++ suites to ql repo
As the queries live here, it makes sense for the suites to be versioned
together with them. The LGTM suite has already been moved. This commit
moves the actively-maintained non-LGTM suites.
2018-08-14 11:41:31 +02:00
Pavel Avgustinov
64338b0581 Element::getEnclosingElement: Skip macro information.
Previously, we would try to find an element enclosing each macro
access. This is not in general well-defined, especially in the
context of template instantiations -- macros are a lexing-time
concept, and don't map cleanly onto AST elements.
2018-08-13 22:16:49 +01:00
Robert Marsh
9cf599fb59 C++: remove some tags in response to PR comments 2018-08-13 10:25:10 -07:00
Jonas Jensen
d88c9c67f1 C++ IR: Don't repeat a very similar predicate body 2018-08-10 16:05:31 +02:00
Jonas Jensen
a235d7aaff C++ IR: Reuse expensive IRBlock computations
`IRBlock` contains a few expensive predicates, mostly `getInstruction`
and `immediatelyDominates`. These were previously recomputed for each of
the three SSA layers even though they essentially produce the same
result in each layer. The only difference between the three types of
`IRBlock` is the phi nodes.

This commit changes the representation of `IRBlock` for `ssa` and
`aliased_ssa` so they become just wrappers around the `IRBlock` of their
previous layer. Most predicates in later layers are then computed from
the corresponding predicate of the preceding layer.
2018-08-10 16:05:30 +02:00
Jonas Jensen
6ee3def942 C++ IR: Speed up getInstructionOperand
The `SSAConstruction::Cached::getInstructionOperand` predicate took
1m27s on a postgres snapshot before this change and was the slowest
predicate in SSAIR. It now takes 4.5s.

The slowdown was caused by its use of
`getUnmodeledDefinitionInstruction`, which got inlined into a place
where join orderer had little choice but to join the `MkInstruction`
relation with itself, creating a large intermediate relation.

I've added `pragma[noinline]` to `getUnmodeledDefinitionInstruction` and
also to similar predicates that are likely to cause the same problem in
the future.
2018-08-10 16:05:30 +02:00
Jonas Jensen
7b1d1365a9 C++ IR: Fully cache IRBlock and use cached module
Before this PR, the caching and computation of `IRBlock` spanned three
cache stages and was also separate from `SSAConstruction` even though it
shared some computations with it. They are now all cached together, so
the number of stages is reduced by 2 for each layer of IR.

I made the choice of what to cache be similar to what we do for
`PrimitiveBasicBlock` as I've recently benchmarked this and found it to
be a good choice.
2018-08-10 16:05:15 +02:00