13956 Commits

Author SHA1 Message Date
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 ExprNodes for Conversions"
This reverts commit df882a9e72.
2018-12-10 15:06:29 -08:00
Dave Bartolomeo
df882a9e72 C++: Avoid creating ExprNodes for Conversions 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
Dave Bartolomeo
ebbd701188 C++: Fix PR feedback 2018-12-06 12:35:43 -08:00
Dave Bartolomeo
84b39bf999 C++: Simplify models for side effects and alias info. 2018-12-06 12:35:33 -08:00
Ian Lynagh
8d655c74ae C++: Follow range for statement test output changes 2018-12-06 11:12:46 +00:00
Dave Bartolomeo
2b80aee557 C++: Use getConvertedResultExpr in IR-based dataflow
This sort of fixes one FP and causes a new FN, but for the wrong reasons. The IR dataflow is tracking the reference itself, rather than the referred-to object. Once we can better model indirections, we can make this work correctly.

This change is still the right thing to do, because it ensures that the dataflow is looking at actual expression being computed by the instruction.
2018-12-05 12:34:44 -08:00
Dave Bartolomeo
e8efb32156 C++: Remove StoreDestinationAsPostUpdateNode 2018-12-05 11:33:48 -08:00
Dave Bartolomeo
65360b23f9 C++: Change model API based on feedback
I've separated the model interface for memory side effects from the model for escaped addresses. It will be fairly common for a given model to extend both interfaces, but they are used for two different purposes.

I've also put each model interface and the non-member predicates that query it into a named module, which seemed cleaner than having predicates named `functionModelReadsMemory()` and `getFunctionModelParameterAliasBehavior()`.
2018-12-05 10:58:46 -08:00
Ian Lynagh
7d8a8de53d C++: Test output changes following CatchAny fix 2018-12-05 15:35:54 +00:00
Geoffrey White
d85f4b540c CPP: Fix false positive. 2018-12-05 10:01:54 +00:00
Geoffrey White
e7f19e97cb CPP: Add a test of UnusedStaticVariable.ql. 2018-12-05 10:01:54 +00:00
Dave Bartolomeo
e11b4b6c40 C++: Fix IR Dataflow PR feedback 2018-12-04 07:31:13 -08:00
Geoffrey White
a7f45bb59d Merge pull request #608 from jbj/assignment-this-templates
C++: Fix "Overloaded assignment does not return 'this'" for templates
2018-12-04 14:12:56 +00:00
Aditya Sharad
3caf4e52a7 Merge rc/1.19 into next. 2018-12-04 12:39:41 +00:00
Jonas Jensen
6239455a91 C++: Remove extra type check in AV Rule 82
These type checks were overlapping with `assignOperatorWithWrongType` is
are no longer needed now that `assignOperatorWithWrongType` is improved.
They were causing FPs and misleading error messages on uninstantiated
templates.
2018-12-04 12:59:21 +01:00
Jonas Jensen
8ac427c387 C++: Add missing getUnspecifiedType in AV Rule 82
Adding this call to `getUnspecifiedType` makes the error message better
in the presence of typedefs and qualifiers on an assignment operator
return type. It's also needed to avoid losing valid results in the
commit that comes after this.
2018-12-04 11:13:11 +01:00
Jonas Jensen
a78ded7551 C++: Demonstrate FP in AV Rule 82
The added test is a reduced version of a FP observed in the wild.
2018-12-04 11:09:35 +01:00
Nick Rolfe
a637eb651f C++: fix expected test output for improved extraction of agg. inits. 2018-12-03 16:45:53 +00:00
Geoffrey White
436ee553a6 Merge pull request #589 from jbj/1.19-change-notes
C++: add missing 1.19 change notes
2018-12-03 15:56:18 +00:00
Jonas Jensen
b80cf30cee Merge pull request #562 from geoffw0/cpp-308
CPP: Fix FPs for 'Resource not released in destructor' involving virtual method calls
2018-12-03 15:57:11 +01:00
Geoffrey White
d8c7537557 CPP: * -> + 2018-12-03 13:11:52 +00:00
Geoffrey White
dfbccc4bcf CPP: Additional test cases. 2018-12-03 13:11:52 +00:00
Nick Rolfe
fc91ff1a69 C++: we now process operands for vacuous destructor calls thru pointers 2018-12-03 12:16:35 +00:00
Dave Bartolomeo
2822d14588 C++: Add missing changes to test_ir.expected 2018-12-02 22:22:34 -08:00
Jonas Jensen
d14cf34cc6 C++: data flow AlwaysTrueUponEntryLoop perf fix
The predicate `AlwaysTrueUponEntryLoop.getARelevantVariable` was very
sensitive to join ordering, and with the 1.19 QL engine it got an
unfortunate join order that made it explode on certain snapshots. With
this change, it goes from taking minutes to taking less than a second on
a libretro-uae snapshot.
2018-12-01 10:07:08 +01:00
Dave Bartolomeo
7eb47f3f82 C++: A few more IR dataflow tweaks
Made `Node::getType()`, `Node::asParameter()`, and `Node::asUninitialized()` operate directly on the IR. This actually fixed several diffs compared to the AST dataflow, because `getType()` wasn't holding for nodes that weren't `Exprs`.

Made `Uninitialized` a `VariableInstruction`. This makes it consistent with `InitializeParameter`.
2018-11-30 16:53:45 -08:00
Dave Bartolomeo
309b703e47 C++: Models for side-effect-free functions
This commit adds a new model interface that describes the known side effects (or lack thereof) of a library function. Does it read memory, does it write memory, and do any of its parameters escape? Initially, we have models for just two Standard Library functions: `std::move` and `std::forward`, which neither read nor write memory, and do not escape their parameter.

IR construction has been updated to insert the correct side effect instruction (or no side effect instruction) based on the model.
2018-11-30 12:15:23 -08:00
Dave Bartolomeo
af443569d9 C++: Fix handling of accesses to escaped variables in Aliased SSA
This fixes a subtle bug in the construction of aliased SSA. `getResultMemoryAccess` was failing to return a `MemoryAccess` for a store to a variable whose address escaped. This is because no `VirtualIRVariable` was being created for such variables. The code was assuming that any access to such a variable would be via `UnknownMemoryAccess`. The result is that accesses to such variables were not being modeled in SSA at all.

Instead, the way to handle this is to have a `VariableMemoryAccess` even when the variable being accessed has escaped, and to have `VariableMemoryAccess::getVirtualVariable()` return the `UnknownVirtualVariable` for escaped variables. In the future, this will also let us be less conservative about inserting `Chi` nodes, because we'll be able to determine that there's an exact overlap between two accesses to the same escaped variable in some cases.
2018-11-30 12:15:19 -08:00
Dave Bartolomeo
ae8f18c0b5 C++: Treat all Convert instructions as dataflow
The AST dataflow library essentially ignores conversions, which is probably the right behavior. Converting an `int` to a `long` preserves the value, even if the bit pattern might be different. It's arguable whether narrowing conversions should be treated as dataflow, but we'll do so for now. We can revisit that if we see it cause problems.
2018-11-30 12:15:15 -08:00
Dave Bartolomeo
58f7596519 C++: IR-based dataflow 2018-11-30 12:15:11 -08:00
Kevin Backhouse
939db5a7cd Merge pull request #583 from jbj/bbStrictlyDominates-nomagic
C++: pragma[nomagic] on bbStrictlyDominates
2018-11-30 15:12:24 +00:00
Jonas Jensen
60076cb734 Merge pull request #532 from geoffw0/query-tags-3
CPP: Query Tags 3 (JPL_C queries)
2018-11-30 15:45:01 +01:00