Commit Graph

3147 Commits

Author SHA1 Message Date
Jonas Jensen
566eafc706 Merge pull request #823 from dave-bartolomeo/dave/IdentityString
C++: Declaration.getIdentityString and Type.getTypeIdentityString
2019-02-08 13:16:02 +01:00
Dave Bartolomeo
1e7dcedcdf C++: Fix semantic merge conflict 2019-02-07 14:32:26 -08:00
Dave Bartolomeo
283991d520 C++: Handle ProxyClass in getIdentityString() 2019-02-07 14:26:01 -08:00
Dave Bartolomeo
eb7016620b C++: Fix PR feedback 2019-02-07 14:26:00 -08:00
Dave Bartolomeo
7b54db8ca9 C++: Fix getIdentityString for TemplateParameter 2019-02-07 14:26:00 -08:00
Dave Bartolomeo
5d71d06dbc C++: Fix test expectation 2019-02-07 14:26:00 -08:00
Dave Bartolomeo
bd4ecc3e91 C++: Declaration.getIdentityString and Type.getTypeIdentityString
This PR adds new predicates to `Declaration` and `Type` to get a fully-qualified canonical name for the element, suitable for debugging and dumps. It includes template parameters, cv qualifiers, function parameter and return types, and fully-qualified names for all symbols. These strings are too large to compute in productions queries, so they should be used only for dumps and debugging. Feel free to suggest better names for these predicates.

I've updated PrintAST and PrintIR to use these instead of `Function.getFullSignature()`. The biggest advantage of the new predicates is that they handle lambdas and local classes, which `getQualifiedName` and `getFullSignature` do not. This makes IR and AST dumps much more usable for real-world snapshots.

Along the way, I cleaned up some of our handling of `IntegralType` to use a single table for tracking the signed, unsigned, and canonical versions of each type. The canonical part is new, and was necessary for `getTypeIdentityString` so that `signed int` and `int` both appear as `int`.
2019-02-07 14:26:00 -08:00
Dave Bartolomeo
f460d2c1c3 C++: Fix another test expectation 2019-02-07 09:56:56 -08:00
Dave Bartolomeo
f2a0a86c6d C++: Update captures test for closure fields extractor fix 2019-02-07 09:56:56 -08:00
Robert Marsh
3c638b5966 C++: add edge-based predicates to IRGuards
These predicates currently take a pair of `IRBlock`s - as it stands, at
most one edge can exist from one `IRBlock` to a given other `IRBlock`.
We may need to revisit that assumption and create an `IREdge` IPA type
at some future date
2019-02-07 09:38:54 -08:00
Dave Bartolomeo
4c23ad100e C++: Rename a few IR APIs
There are a few IR APIs that we've found to be confusingly named. This PR renames them to be more consistent within the IR and with the AST API:

`Instruction.getFunction` -> `Instruction.getEnclosingFunction`: This was especially confusing when you'd call `FunctionAddressInstruction.getFunction` to get the function whose address was taken, and wound up with the enclosing function instead.

`Instruction.getXXXOperand` -> `Instruction.getXXX`. Now that `Operand` is an exposed type, we want a way to get a specific `Operand` of an `Instruction`, but more often we want to get the definition instruction of that operand. Now, the pattern is that `getXXXOperand` returns the `Operand`, and `getXXX` is equivalent to `getXXXOperand().getDefinitionInstruction()`.

`Operand.getInstruction` -> `Operand.getUseInstruction`: More consistent with the existing `Operand.getDefinitionInstruction` predicate.
2019-02-06 22:43:49 -08:00
Robert Marsh
5327ca7f77 Merge pull request #812 from jbj/ir-backedge
C++: IR back-edge detection based on TranslatedStmt
2019-01-31 11:28:21 -08:00
Dave Bartolomeo
ab1f96fb2c Merge pull request #770 from jbj/cfg-static-init-pr
C++: Add addresses to `Expr.isConstant`
2019-01-31 10:24:48 -08:00
Jonas Jensen
b55573ebe3 C++: Accept test changes in ir_gvn.expected 2019-01-31 10:08:16 +01:00
Robert Marsh
9decbd9c9f C++: new irreducible CFG test for range analysis 2019-01-25 13:12:40 -08:00
Jonas Jensen
ba8bf94d7b C++: Account for chi nodes in back-edge detection 2019-01-25 15:32:19 +01:00
Jonas Jensen
560dbdf984 C++: Test demonstrating chi node back edge bug
This test shows that the back-edge detection does not properly account
for chi nodes in the translation to aliased SSA.
2019-01-25 15:28:53 +01:00
Jonas Jensen
9963270d63 C++: Annotate back edges in IR debug output 2019-01-25 14:16:45 +01:00
Jonas Jensen
6d09a9b324 C++: Enable range analysis for irreducible CFGs
This adds one new test result (`i >= 0` on line 130).
2019-01-25 09:31:07 +01:00
semmle-qlci
281c944432 Merge pull request #774 from jbj/dataflow-asExpr-conversion
Approved by dave-bartolomeo
2019-01-25 08:00:51 +00:00
Jonas Jensen
b40accee6f C++: sanity checks for back edges 2019-01-23 11:40:12 +01:00
Jonas Jensen
b2e5d235de C++: IR sanity queries for outgoing edges
These queries have no results on our test cases in the repo, but
`ambiguousSuccessors` has results on any large C++ code base, and
`unexplainedLoop` has results on Windows builds of ChakraCore.
2019-01-23 11:07:49 +01:00
Jonas Jensen
dcb24e07c3 C++: Remove getFullyConverted call in sink def
With this change, the `IRDataflowTestCommon.qll` and
`DataflowTestCommon.qll` files use the same definitions of sources and
sinks. Since the IR data flow library is meant to be compatible with the
AST data flow library, this is what we ought to be testing.

Two alerts change but not necessarily for the right reasons.
2019-01-16 13:56:52 +01:00
Jonas Jensen
502b7cfe33 C++: Don't use C-style varargs in test.cpp sink
As we prepare to clarify how conversions are treated, we don't want a
`sink(...)` declaration where it's non-obvious which conversions are
applied to arguments.
2019-01-16 09:47:58 +01:00
Jonas Jensen
3edadc311f C++: Simplify skipInitializer in CFG.qll
The CFG construction code previously contained half of an approximation
of which address expressions are constant. Now this this property is
properly modelled by `Expr.isConstant`, we can remove this code.

This fixes most discrepancies between the QL-based CFG and the
extractor-based CFG on Wireshark.
2019-01-15 13:03:26 +01:00
Jonas Jensen
aaae5becf1 C++: Add addresses to Expr.isConstant
Before this change, `Expr.isConstant` only was only true for those
constant expressions that could be represented as QL values: numbers,
Booleans, and string literals. It was not true for string literals
converted from arrays to pointers, and it was not true for addresses of
variables with static lifetime.

The concept of a "constant expression" varies between C and C++ and
between versions of the standard, but they all include addresses of data
with static lifetime. These are modelled by the new library
`AddressConstantExpression.qll`, which is based on the code in
`EscapesTree.qll` and modified for its new purpose.

I've tested the change for performance on Wireshark and for correctness
with the included tests. I've also checked on Wireshark that all static
initializers in C files are considered constant, which was not the case
before.
2019-01-15 12:31:04 +01:00
Robert Marsh
eabc674bb3 Merge pull request #747 from jbj/cfg-remove-cfg.ql
C++: Delete library-tests/qlcfg/cfg.ql
2019-01-11 11:57:26 -08:00
Jonas Jensen
ef331ee68c Merge pull request #633 from Semmle/rdmarsh/cpp/range-analysis
C++: New range analysis
2019-01-11 19:32:20 +01:00
Jonas Jensen
88a251c05a C++: Delete library-tests/qlcfg/cfg.ql
This test was intended to catch regressions in the CFG, but it looks
like it's just catching insignificant extractor changes. The test has
started failing after some recent extractor changes, but I have no way
to pinpoint the failure and understand whether it's a problem or not, so
I think it's better to delete this test.

The remaining tests check whether the QL-based CFG generates the same
graph as the extractor-based CFG. Furthermore, the `successor-tests`
check that the extractor-based CFG works as intended.
2019-01-11 08:24:07 +01:00
Robert Marsh
c455db9e59 C++: update test expectations 2019-01-10 11:24:13 -08:00
Jonas Jensen
9146b8e32e C++: Add example of conditional destruction
The QL CFG and extractor CFG are the same, so the test passes. Neither
of them model that `ref` may or may not be destructed.
2019-01-09 15:02:25 +01:00
Robert Marsh
0040a2d123 C++: respond to further PR comments 2019-01-08 09:34:28 -08:00
Robert Marsh
8c9c316e1b C++: performance and termination fixes 2019-01-08 09:34:27 -08:00
Robert Marsh
567eee1114 C++: allow phi nodes to self-bound 2019-01-08 09:34:27 -08:00
Robert Marsh
b2cd9a29f2 C++: add test for false comparisons 2019-01-08 09:34:26 -08:00
Robert Marsh
2f8ca8802b C++: switch to using ValueNumbers as bounds
This reduces the number of bounds computed, and will simplify use of the
library. The resulting locations in the tests may be slightly strange,
because the example `Instruction` for a `ValueNumber` is the first
appearing in the IR, regardless of source order, and may not be the most
closely related `Instruction` to the bounded value. I think that's worth
doing for the performance and usability benefits.
2019-01-08 09:34:26 -08:00
Robert Marsh
89148a9ec7 C++: respond to further PR comments 2019-01-08 09:34:26 -08:00
Robert Marsh
ae4ffd9166 C++: respond to PR comments, add some TODOs 2019-01-08 09:34:25 -08:00
Robert Marsh
fe32aea31f C++: fix/add comments 2019-01-08 09:34:25 -08:00
Robert Marsh
ed68f9150a C++: Initial implementation of new range analysis 2019-01-08 09:34:23 -08:00
Robert Marsh
a06a20dbab C++: move SimpleRangeAnalysis tests 2019-01-08 09:34:23 -08:00
Jonas Jensen
26f32f0d6d C++: Initial version of CFG.qll
This implements calculation of the control-flow graph in QL. The new
code is not enabled yet as we'll need more extractor changes first.

The `SyntheticDestructorCalls.qll` file is a temporary solution that can
be removed when the extractor produces this information directly.
2019-01-04 13:34:36 +01:00
Jonas Jensen
8f9849b30b C++: Add BuiltInIntAddr class for __INTADDR__ 2019-01-04 10:24:08 +01:00
Ian Lynagh
98e8858dc6 C++: Accept test changes 2019-01-03 21:09:49 +00:00
Dave Bartolomeo
a7cb2d6d7c C++: Ignore Unreached blocks in IR Guards 2018-12-20 11:57:25 -08:00
Dave Bartolomeo
fda8605aae C++: One Unreached per function 2018-12-17 11:03:15 -08:00
Dave Bartolomeo
56bb9dcde0 C++: Remove infeasible edges to reachable blocks
The existing unreachable IR removal code only retargeted an infeasible edge to an `Unreached` instruction if the successor of the edge was an unreachable block. This is too conservative, because it doesn't remove an infeasible edge that targets a block that is still reachable via other paths. The trivial example of this is `do { } while (false);`, where the back edge is infeasible, but the body block is still reachable from the loop entry.

This change retargets all infeasible edges to `Unreached` instructions, regardless of the reachability of the successor block.
2018-12-14 12:13:22 -08:00
Aditya Sharad
ce8ca5979b Merge rc/1.19 into next. 2018-12-13 12:23:59 +00:00
Aditya Sharad
f92456fcad Merge master into next.
Conflict in `cpp/ql/test/library-tests/sideEffects/functions/sideEffects.expected`,
resolved by accepting test output (combining changes).
2018-12-12 17:26:18 +00:00
Dave Bartolomeo
0140cd23d0 C++: Accept correct test output 2018-12-11 17:11:51 -08:00