Граф коммитов

986 Коммитов

Автор SHA1 Сообщение Дата
Geoffrey White 49cfa43fd8 CPP: Improve accuracy further. 2019-01-16 19:05:51 +00:00
Geoffrey White 105f8dddd0 CPP: Better fileHeaderLimit. 2019-01-16 19:05:50 +00:00
Geoffrey White 91c736229c CPP: Performance is better as a single regexp. 2019-01-16 19:05:50 +00:00
Geoffrey White e3056ca96c CPP: Improve accuracy of AutogeneratedFile.qll. 2019-01-16 19:05:50 +00:00
Jonas Jensen 22b15037fc C++: Split DataFlow::Node.asExpr into two
The existing `Node.asExpr` predicate changes semantics so it becomes the
one that most users should use when they don't want to think about
`Conversion`s. A new `Node.asConvertedExpr` predicate is added and has
the same semantics as the old `Node.asExpr` predicate. It's for advanced
users that know about `Conversion`s and want to account for them.
2019-01-16 14:17:57 +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 b3f46d757a C++: isConstant() -> exists(getValue())
This code was clearly using `isConstant` as an indirect way of checking
whether `getValue` would have a result. That's no longer valid, so I
changed it to check `getValue` directly.
2019-01-15 19:03:49 +01:00
Jonas Jensen d81e6e9bb8 C++: Add TranslatedElement::isIRConstant
Now that there exist constants with no QL-representable value, we need
to make sure they're not treated as constants in the IR.
2019-01-15 17:35:14 +01:00
Jonas Jensen 0f2c7005fc C++: Sync files that should be identical
These files had come out of sync due to 89148a9ec7 and 8c9c316e1b. I
synced the files by replaying the changes that those commits made in
`aliased_ssa/` to the two other copies.
2019-01-15 16:01:54 +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
Jonas Jensen d252a40853 C++: Speed up Expr.getFullyConverted slightly
This change cuts around 15% of the run time off this predicate. It's a
workaround for QL-796.
2019-01-15 11:45:07 +01:00
Nick Rolfe 371c09d4e5
Merge pull request #740 from ian-semmle/inline_ns
C++: Add inline namespace support
2019-01-15 10:00:32 +00:00
Jonas Jensen 9751a91087 C++: Accept changes to alert message in test 2019-01-14 21:43:57 +01:00
Jonas Jensen 08db4cd959
Merge pull request #744 from geoffw0/format
CPP: Autoformat some untidy files
2019-01-14 21:31:17 +01:00
Jonas Jensen b966a872f3
Merge pull request #758 from Semmle/gvn-comment
C++: fix wording in GVN qldoc comment
2019-01-14 21:26:43 +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
Geoffrey White c8cbc8ea5a
Merge pull request #751 from jbj/hides-parameter-crossfile
C++: Improvements to "Declaration hides parameter"
2019-01-11 18:00:50 +00:00
Nick Rolfe e8f4127fe5
C++: fix wording in GVN qldoc comment 2019-01-11 13:56:52 +00:00
Jonas Jensen ca3554dcc6 C++: Incorporate docs review comments 2019-01-11 14:18:15 +01:00
Jonas Jensen b65e2f8b79 C++: Put QLDoc on two helper predicates 2019-01-11 14:07:22 +01:00
Jonas Jensen 6385dd38cf C++: Exclude operator= in ExprHasNoEffect 2019-01-11 13:30:08 +01:00
Jonas Jensen 95e457cb49 C++: Add test with FP in ExprHasNoEffect 2019-01-11 13:18:44 +01:00
Jonas Jensen 1cc36dd969 C++: Exclude copy assignment in LargeParameter.ql
The purpose of the copy assignment operator is to copy the object, so we
should not complain that a copy happens when passing the parameter. See
https://en.wikibooks.org/wiki/More_C++_Idioms/Copy-and-swap for details.
2019-01-11 12:00:02 +01:00
Jonas Jensen 4ea3849595 C++: Add failing test case for LargeParameter.ql 2019-01-11 11:53:04 +01:00
Jonas Jensen b38ca944f4 C++: Work around CPP-331
This change suppresses results from "Declaration hides parameter" where
the ParameterDeclarationEntry does not link up to the right
FunctionDeclarationEntry.
2019-01-11 11:26:43 +01:00
Jonas Jensen 2268f1fee6 C++: Speed up "Declaration hides parameter"
Bad magic ended up in `LocalVariable.getFunction` and effectively
created a Cartesian product. Before this change, the timing looked like
this:

    Variable::LocalVariable::getFunction_dispred#bb ... 50.1s
    #select#cpe#123#fff ............................... 20.6s

After this change, those predicates become much faster:

    Variable::LocalVariable::getFunction_dispred#ff ... 121ms
    DeclarationHidesParameter::localVariableNames#fff . 77ms
    #select#cpe#123#fff ............................... 28ms

Introducing the predicate `localVariableNames` ensures that we can do
the main join on two columns simultaneously, so that's a change we
should keep even if we remove the `pragma[nomagic]` later.
2019-01-11 11:06:18 +01:00
Jonas Jensen 8a435ae321 C++: Autoformat "Declaration hides parameter" 2019-01-11 11:02:52 +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
Geoffrey White 87569d14b9 CPP: QLDoc comments. 2019-01-10 17:38:42 +00:00
Geoffrey White ba3bc1596b CPP: Manual fixup. 2019-01-10 15:28:13 +00:00
Geoffrey White c4b01d0816 CPP: Autoformat some other untidy source files. 2019-01-10 15:28:13 +00:00
Geoffrey White 28261d6787
Merge pull request #737 from jbj/cfg-perf
C++: QL CFG performance and tweaks
2019-01-10 14:45:53 +00:00
Geoffrey White f2e68da322 CPP: Use dataflow to find wrapped rounding functions. 2019-01-10 14:44:11 +00:00
Geoffrey White 207c4d365a CPP: Test wrapped rounding functions more thoroughly. 2019-01-10 14:39:23 +00:00
Geoffrey White 4f002291c5 CPP: Add exception for builtins. 2019-01-10 14:16:57 +00:00
Ian Lynagh e5b6e61d45 C++: Update stats to include namespace_inline 2019-01-10 11:35:49 +00:00
Geoffrey White 346bc1ac62 CPP: Autoformat some code from Critical. 2019-01-10 10:40:39 +00:00
Geoffrey White b7febb06af CPP: Autoformat some Power of 10 queries. 2019-01-10 10:40:39 +00:00
Jonas Jensen 92fbea4e41 C++: UsingStrcpyAsBoolean.ql: use getName
We agreed in the review of the original PR that `getName` is more
appropriate here than `getQualifiedName`. Using `getName` ensures that
we also match the `std::`-prefixed versions of these functions as well
as user-defined versions.
2019-01-10 08:35:54 +01:00
Jonas Jensen aa0f2f2da3 C++: Support `?:` in UsingStrcpyAsBoolean.ql
I removed some unnecessary parentheses for symmetry, causing whitespace
changes.
2019-01-10 08:35:54 +01:00
Jonas Jensen 0f88a4b312 C++: Test `?:` support in UsingStrcpyAsBoolean.ql
This test shows that the query only supports the ternary operator in
C++, not C.
2019-01-10 08:35:54 +01:00
Jonas Jensen 4dd36772ef C++: Remove UsingStrcpyAsBoolean.ql duplicates 2019-01-10 08:35:54 +01:00
Jonas Jensen 3a6a515a1d C++: Tabs to spaces and `// Bug` comments in test
This changes the column numbers in the expected test output.
2019-01-10 08:35:53 +01:00
Jonas Jensen aafb4abc3d C++: Use more specific predicates than getChild
This commit doesn't change any behavior but just uses the preferred
high-level predicates. The `getChild` predicate inspects the raw
database more or less directly, and the database layout could change in
the future.
2019-01-10 08:35:53 +01:00
Jonas Jensen 657fe0eda3 C++: Tweak docs of UsingStrcpyAsBoolean.ql
This should make the documentation more in line with the documentation
for our other queries. The @name of the query is changed to "Use of
string copy function in a condition".
2019-01-10 08:35:53 +01:00
Jonas Jensen 563f8158d7 C++: Autoformat UsingStrcpyAsBoolean.ql 2019-01-10 08:35:53 +01:00
Jonas Jensen 9219214d64
Merge pull request #695 from raulgarciamsft/users/raulga/c6324
cpp - Using the return value of a strcpy or related string copy function in an if statement
2019-01-10 08:34:17 +01:00
Geoffrey White 7a877bfe14 CPP: Add exception for wrapped whitelisted functions. 2019-01-09 18:30:19 +00:00
Geoffrey White f983391cbf CPP: Add exception for pow. 2019-01-09 15:06:23 +00:00
Geoffrey White 11013b0ec6 CPP: Add a few more test cases. 2019-01-09 14:58:25 +00:00
Ian Lynagh 7a0ed57916 C++: Add namespace_inline 2019-01-09 14:47:27 +00:00
Geoffrey White 82e54568a5 CPP: Add qhelp. 2019-01-09 14:03:28 +00: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
Jonas Jensen 8ac826a62a C++: Factor out base case of normalGroupMember
This recursive predicate is made faster by working around a known
optimizer problem (QL-796) that causes the optimizer to insert extra
type checks in recursive case even when they are only needed in the
base case.
2019-01-09 15:02:25 +01:00
Geoffrey White cbe69f2daf CPP: Fix false positive. 2019-01-09 13:59:24 +00:00
Geoffrey White e26c709dbf CPP: Add a test for LossyFunctionResultCast.ql. 2019-01-09 13:59:24 +00:00
Geoffrey White 0e092ae88d CPP: Tag LossyFunctionResultCast.ql. Will be run on LGTM. 2019-01-09 13:59:24 +00:00
Jonas Jensen c74b89119e C++: Reorder parameters to subEdge relations
This improves performance slightly by putting the parameters in the
order in which they'll be needed in `qlCFGSuccessor`.
2019-01-09 14:58:43 +01:00
ian-semmle b3bcabf7c6
Merge pull request #724 from jbj/cfg-pr
C++: Construct a CFG with QL
2019-01-09 13:12:39 +00:00
Geoffrey White 6088ca5d5b CPP: Update our uses of MacroInvocationExpr. 2019-01-09 12:17:29 +00:00
Geoffrey White b59c2868cd CPP: Add test cases for the macro logic and other details of ArithmeticUncontrolled.ql. 2019-01-09 12:17:29 +00:00
Geoffrey White a1caa85172 CPP: Deprecate MacroInvocationExpr. 2019-01-09 11:45:08 +00:00
Geoffrey White 75b1fb36ec CPP: Deprecate MacroInvocationStmt. 2019-01-09 11:45:08 +00:00
Robert Marsh c39de75d3d C++: change in-predicate comment formatting 2019-01-08 09:34:29 -08:00
Robert Marsh af8a3f2522 C++: expand a comment 2019-01-08 09:34:28 -08: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 1be91b5df5 C++: Use IPA for Pos and Spec
This is cleaner than extending `int` and working with magic numbers.
Performance appears to be unaffected.
2019-01-08 16:23:11 +01:00
Jonas Jensen dba3351d2c C++: Update comments based on PR feedback 2019-01-08 13:29:03 +01:00
Raul Garcia 18bb6696e0 Fixing conditional only issue.
I changed  to detect any logical operation usage (i.e. !, ==), but I kept usage in a conditional directly as a separate detection condition. I found no false positives on the projects you shared with me previously.
2019-01-07 10:44:11 -08:00
Raul Garcia 880306c621 Removing duplicated results 2019-01-04 10:45:43 -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
Max Schaefer b4f400fb23 Merge remote-tracking branch 'upstream/next' into qlucie/master 2019-01-04 10:35:57 +00:00
Jonas Jensen a47faa2272 C++: Add ConditionDeclExpr convenience predicates
Also expand the QLDoc.
2019-01-04 10:24:08 +01:00
Jonas Jensen ca0517b3d6 C++: LocalVariable docs 2019-01-04 10:24:08 +01:00
Jonas Jensen 8f9849b30b C++: Add BuiltInIntAddr class for __INTADDR__ 2019-01-04 10:24:08 +01:00
Jonas Jensen 79e246f961
Merge pull request #722 from geoffw0/doc-macroinv
CPP: Improve qldoc for MacroAccess and MacroInvocation.
2019-01-04 08:40:37 +01:00
Ian Lynagh 187fdf67b0 C++: Rename `twoOperand` to `isTwoOperand` 2019-01-03 21:09:49 +00:00
Ian Lynagh 98e8858dc6 C++: Accept test changes 2019-01-03 21:09:49 +00:00
Ian Lynagh 283eb51db8 C++: Update stats after adding expr_cond* tables 2019-01-03 21:09:49 +00:00
Ian Lynagh dc3d87f2fc C++: Add tables for ConditionalExprs 2019-01-03 21:09:49 +00:00
Raul Garcia 89c045b550 Merge branch 'users/raulga/c6324' of https://github.com/raulgarciamsft/ql into users/raulga/c6324 2019-01-03 10:06:59 -08:00
Raul Garcia 2c1d7bbc41 Switched to DataFlow::localFlow to avoid false positives. 2019-01-03 10:06:49 -08:00
Geoffrey White 787febae6e CPP: Improve qldoc for MacroAccess and MacroInvocation. 2019-01-03 15:16:47 +00:00
Jonas Jensen b17fb86961 C++: Factor out `reachable` base case 2019-01-03 11:20:18 +01:00
Raul Garcia e7bc3e6c0d
Update UsingStrcpyAsBoolean.cpp 2019-01-02 17:33:28 -08:00
Raul Garcia 28932e85d9 Fixing the code based on PR feedback. 2019-01-02 16:23:19 -08:00
Jonas Jensen d566141273
Merge pull request #694 from dave-bartolomeo/dave/BetterUnreached
C++: Remove infeasible edges to reachable blocks
2018-12-21 07:36:51 +00:00
Dave Bartolomeo a7cb2d6d7c C++: Ignore `Unreached` blocks in IR Guards 2018-12-20 11:57:25 -08:00
Dave Bartolomeo 63a2670fcd C++: Don't have `ReachableBlock` extends `IRBlock` 2018-12-17 13:10:53 -08:00
Dave Bartolomeo fda8605aae C++: One `Unreached` per function 2018-12-17 11:03:15 -08:00
alexet d61022ffcc C++: Improve optimiser performance 2018-12-17 16:11:23 +00:00
Jonas Jensen 5ac5aa0c2a Merge remote-tracking branch 'upstream/master' into mergeback-20181217 2018-12-17 13:42:45 +01:00
Raul Garcia f8ab945b91
Merge branch 'master' into users/raulga/c6324 2018-12-14 15:46:38 -08:00
Raul Garcia 16f2bacf4d cpp - Using the return value of a strcpy or related string copy function in an if statement 2018-12-14 15:42:49 -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
Jonas Jensen 23a2bf1756 C++: Delete dead code with warnings in it 2018-12-14 10:59:41 +00:00
Aditya Sharad f71e5ac338 Merge master into next. 2018-12-13 17:57:31 +00:00
Geoffrey White b21e832ee2
Merge pull request #683 from jbj/prepareQueries-fix-warnings
C++: Fix all prepareQueries errors and warnings
2018-12-13 15:30:44 +00:00
Aditya Sharad ce8ca5979b Merge rc/1.19 into next. 2018-12-13 12:23:59 +00:00
Jonas Jensen bee2ddaf26 C++: Fix all prepareQueries errors and warnings
With these changes we can run `odasa prepareQueries --check-only
--fail-on-warnings` on the C++ query directory. Two changes were needed:

1. The `Metrics/queries.xml` file had to be deleted. It existed because
   the built distribution has a different file layout, where `Metrics`
   is moved to the top-level query dir `odasa-cpp-metrics`. Since
   internal PR 28230 this file is created as needed as part of the dist
   build process, so it doesn't need to be checked in with the sources.
2. All uses of the `deprecated` and stubbed-out Objective C classes were
   removed.
2018-12-13 11:13:50 +00:00
Jonas Jensen 1a0a8c931f C++: Fix name clash in data flow imports
The AST-based data flow libraries and the IR-based ones both define
modules `DataFlow`, `DataFlow2`, etc. This caused
`ImportAdditionalLibraries.ql` to fail in compilation.
2018-12-13 09:53:20 +00:00
Geoffrey White e443eb8889 CPP: Fix type logic. 2018-12-13 09:49:32 +00:00
Geoffrey White c904a338f7 CPP: Add test cases. 2018-12-12 23:47:48 +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
Geoffrey White 2f3a874c7d CPP: Fix false positives when a member variable is released via the target of a function pointer. 2018-12-12 11:38:44 +00:00
Geoffrey White 370387a9ca CPP: Fix false positives when member variable is released via an ExprCall. 2018-12-12 11:38:44 +00:00
Geoffrey White e408f18766 CPP: Fix false positives when member variable is released via capture inside lambda expression. 2018-12-12 11:38:44 +00:00
Geoffrey White 6efd481118 CPP: Make references to the 'kind' of an alloc/delete consistent (this used to be called the 'release' or 'releaseName'). 2018-12-12 11:38:44 +00:00
Geoffrey White 8e2459a6b7 CPP: Add similar test cases with function pointers. 2018-12-12 11:38:44 +00:00
Geoffrey White 77c1ad47f9 CPP: Add test cases with lambdas. 2018-12-12 11:38:44 +00:00
Dave Bartolomeo be5ac2f2ff
Merge pull request #648 from dave-bartolomeo/dave/UnreachableIR
C++: Remove unreachable IR
2018-12-11 20:58:49 -08:00
Dave Bartolomeo 0140cd23d0 C++: Accept correct test output 2018-12-11 17:11:51 -08:00
Dave Bartolomeo 283c1d43c3 C++: Restore previous test expectations 2018-12-11 17:07:25 -08:00
Robert Marsh 59c0e5d39e C++: update test expectations 2018-12-11 15:07:09 -08:00
Robert Marsh 98005edd9d
Merge pull request #641 from geoffw0/exprnoeffect2
CPP: More tests of isSideEffectFree() / ExprHasNoEffect.ql
2018-12-11 12:17:30 -08:00
Aditya Sharad ce905e7a0a
Merge pull request #597 from dave-bartolomeo/dave/IRDataflow
C++: Initial IR-based dataflow implementation
2018-12-11 15:05:58 +00:00
Aditya Sharad dde42a5723 Merge rc/1.19 into next. 2018-12-11 14:38:58 +00:00
Dave Bartolomeo 8a73bea72f C++: Avoid bad join ordering in `getOperandMemoryAccess` 2018-12-11 00:47:53 -08:00
Dave Bartolomeo 4170d4fadd C++: Handle relational operators in constant analysis 2018-12-10 23:03:02 -08:00
Dave Bartolomeo 5ba51e32f0 C++: Remove aliased_ssa instantiation of IR reachability
We never actually consumed this iteration, since SSA construction only depends on the reachability instantiation of the previous IR layer.
2018-12-10 21:22:55 -08:00
Dave Bartolomeo a81ba84c0e C++: Update test expectations after unreachable IR removal 2018-12-10 21:22:55 -08:00
Dave Bartolomeo b2e596fcc2 C++: Improve join order in IR reachability 2018-12-10 21:22:55 -08:00
Dave Bartolomeo 99d33f9623 C++: Remove unreachable IR
This change removes any IR instructions that can be statically proven unreachable. To detect unreachable IR, we first run a simple constant value analysis on the IR. Then, any `ConditionalBranch` with a constant condition has the appropriate edge marked as "infeasible". We define a class `ReachableBlock` as any `IRBlock` with a path from the entry block of the function. SSA construction has been modified to operate only on `ReachableBlock` and `ReachableInstruction`, which ensures that only reachable IR gets translated into SSA form. For any infeasible edge where its predecessor block is reachable, we replace the original target of the branch with an `Unreached` instruction, which lets us preserve the invariant that all `ConditionalBranch` instructions have both a true and a false edge, and allows guard inference to still work.

The changes to `SSAConstruction.qll` are not as scary as they look. They are almost entirely a mechanical replacement of `OldIR::IRBlock` with `OldBlock`, which is just an alias for `ReachableBlock`.

Note that the `constant_func.ql` test can determine that the two new test functions always return 0.

Removing unreachable code helps get rid of some common FPs in IR-based dataflow analysis, especially for constructs like `while(true)`.
2018-12-10 21:22:55 -08:00
Dave Bartolomeo 59fc77f066 C++: Simple constant analysis
This change moves the simple constant analysis that was used by the const_func test into a pyrameterized module for use on any stage of the IR. This will be used to detect unreachable code.
2018-12-10 21:22:54 -08:00
Dave Bartolomeo 6a11ef5c18 C++: Add a couple test cases for unreachable code in IR 2018-12-10 21:22:54 -08:00
Dave Bartolomeo 78e5b3ad63 C++: Add IR dataflow to ImportAdditionalQueries.ql 2018-12-10 15:09:49 -08:00
Dave Bartolomeo 23993710d1 Revert "C++: Avoid creating `ExprNode`s for `Conversion`s"
This reverts commit df882a9e72.
2018-12-10 15:06:29 -08:00
Dave Bartolomeo df882a9e72 C++: Avoid creating `ExprNode`s for `Conversion`s 2018-12-10 10:09:42 -08:00
Aditya Sharad 02b58a8319
Merge pull request #625 from adityasharad/merge/1.19-next-051218
Merge rc/1.19 into next.
2018-12-10 10:05:16 +00:00
Geoffrey White 9857a85817 CPP: Fix similar queries. 2018-12-07 18:43:28 +00:00
Geoffrey White 0f268cac40 CPP: Fix the issue. 2018-12-07 18:43:27 +00:00
Geoffrey White 02a060fbfa CPP: Add a test. 2018-12-07 18:21:48 +00:00
Ian Lynagh 4f51257e56 C++: Update stats 2018-12-07 16:13:07 +00:00
Geoffrey White e7390f3ea5 CPP: Add simple tests of CommaExpr. 2018-12-07 14:29:09 +00:00
Aditya Sharad fcfab26267 Merge rc/1.19 into next. 2018-12-07 12:31:51 +00:00
Geoffrey White b1e7649d02 CPP: Add functions containing errors to the sideEffects tests. 2018-12-07 09:54:36 +00:00
Jonas Jensen 00e52df371 C++: Rename "Incorrect 'not' operator usage"
This makes the casing consistent with our other queries.
2018-12-07 09:24:35 +01:00